horaedb icon indicating copy to clipboard operation
horaedb copied to clipboard

feat: add metrics manager cache

Open zealchen opened this issue 1 year ago • 0 comments

Rationale

#1623

Detailed Changes

  1. 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.

  1. If missing the write cache, the metric data will be asynchronously written to storage.

TODO:

  1. Implement graceful shutdown on async write tasks.

Test Plan

zealchen avatar Feb 09 '25 05:02 zealchen