Skip to main content

mito2/
series_index.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Series index construction, search, and maintenance.
16//!
17//! Under development. Index files are currently stored on the local filesystem.
18
19mod bucket;
20mod builder;
21mod catalog;
22mod maintenance;
23mod purger;
24mod searcher;
25mod task;
26#[cfg(test)]
27mod tests;
28mod version;
29mod writer;
30
31use std::sync::Arc;
32
33use futures::stream::BoxStream;
34use object_store::ObjectStore;
35use store_api::metric_engine_consts::{
36    DATA_SCHEMA_TABLE_ID_COLUMN_NAME as TABLE_ID_COLUMN,
37    DATA_SCHEMA_TSID_COLUMN_NAME as TSID_COLUMN,
38};
39
40use crate::error::Result;
41#[cfg(test)]
42pub(crate) use crate::series_index::catalog::{RangeIndexEntry, SeriesIndexEntry};
43pub(crate) use crate::series_index::catalog::{
44    delete_catalogs, load_version_control, series_index_path,
45};
46pub(crate) use crate::series_index::purger::{IndexFilePurger, series_index_channel};
47pub use crate::series_index::searcher::SeriesIndexSearcher;
48pub(crate) use crate::series_index::task::{SeriesIndexTaskState, spawn_series_index_tasks};
49pub(crate) use crate::series_index::version::{
50    SeriesIndexFileHandle, SeriesIndexVersion, SeriesIndexVersionControl,
51};
52pub use crate::series_index::writer::{
53    SeriesIndexWriter, SeriesIndexWriterMetrics, SeriesIndexWriterOptions, series_index_schema,
54};
55
56/// Index storage and pinned catalog snapshot for a query.
57#[derive(Clone)]
58pub(crate) struct SeriesIndexReadContext {
59    pub(crate) store: ObjectStore,
60    pub(crate) version: Arc<SeriesIndexVersion>,
61}
62
63pub(crate) const MIN_TS_COLUMN: &str = "__series_min_ts";
64pub(crate) const MAX_TS_COLUMN: &str = "__series_max_ts";
65pub(crate) const ROW_COUNT_COLUMN: &str = "__series_row_count";
66pub(crate) const METRIC_SERIES_ID_BATCH_SIZE: usize = 500;
67
68/// Identifies one series in a physical metric region.
69#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
70pub struct MetricSeriesId {
71    /// Logical table ID inside the physical metric region.
72    pub table_id: u32,
73    /// Time-series ID inside the logical table.
74    pub tsid: u64,
75}
76
77/// Stream of bounded batches of matching metric-series IDs.
78pub type MetricSeriesIdStream = BoxStream<'static, Result<Vec<MetricSeriesId>>>;