horaedb
horaedb copied to clipboard
feat: add metrics manager cache
Rationale
#1623
Detailed Changes
- Create a metric cache for both read and write scenarios.
type MetricsData = RwLock<HashMap<MetricName, (FieldName, FieldType)>>;
struct MetricsCache {
pub inner: Arc<RwLock<MetricsInner>>,
}
struct MetricsInner {
// global cache data older than X days
pub global: Arc<SectionedHashMap<Arc<MetricsData>>>,
// section of cache data for latest X days
pub local: Arc<SectionedHashMap<Arc<MetricsData>>>,
// TODO: compute next day cache in advance
pub next_day: Arc<MetricsData>,
}
a. The local cache contains the latest 30 days metrics data. b. The global cache contains data older than 30 days.
- If missing the write cache, the metric data will be asynchronously written to storage.
TODO:
- Implement graceful shutdown on async write tasks.