Skip to content

Commit

Permalink
add sst module
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Sep 9, 2024
1 parent 8eb0fd0 commit 84156fe
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 79 deletions.
34 changes: 0 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions src/metric_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,29 @@ workspace = true
[package.edition]
workspace = true

[features]
test = ["tempfile"]
wal-table-kv = ["wal/wal-table-kv"]
wal-message-queue = ["wal/wal-message-queue"]
wal-rocksdb = ["wal/wal-rocksdb"]
wal-local-storage = ["wal/wal-local-storage"]

[dependencies]
# In alphabetical order
anyhow = { workspace = true }
arc-swap = "1.4.0"
arena = { workspace = true }
arrow = { workspace = true }
async-stream = { workspace = true }
async-trait = { workspace = true }
atomic_enum = { workspace = true }
base64 = { workspace = true }
bytes_ext = { workspace = true }
codec = { workspace = true }
common_types = { workspace = true }
datafusion = { workspace = true }
future_ext = { workspace = true }
futures = { workspace = true }
generic_error = { workspace = true }
hash_ext = { workspace = true }
hex = { workspace = true }
horaedbproto = { workspace = true }
hyperloglog = { workspace = true }
id_allocator = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
logger = { workspace = true }
lru = { workspace = true }
macros = { workspace = true }
message_queue = { workspace = true }
metric_ext = { workspace = true }
object_store = { workspace = true }
parquet = { workspace = true }
parquet_ext = { workspace = true }
prometheus = { workspace = true }
prost = { workspace = true }
remote_engine_client = { workspace = true }
router = { workspace = true }
runtime = { workspace = true }
sampling_cache = { workspace = true }
serde = { workspace = true }
size_ext = { workspace = true }
skiplist = { path = "../components/skiplist" }
smallvec = { workspace = true }
snafu = { workspace = true }
table_engine = { workspace = true }
table_kv = { workspace = true }
tempfile = { workspace = true, optional = true }
thiserror = { workspace = true }
time_ext = { workspace = true }
tokio = { workspace = true }
trace_metric = { workspace = true }
wal = { workspace = true }
xorfilter-rs = { workspace = true }

[dev-dependencies]
common_types = { workspace = true, features = ["test"] }
env_logger = { workspace = true }
pin-project-lite = { workspace = true }
rand = { workspace = true }
tempfile = { workspace = true }
test_util = { workspace = true }
wal = { workspace = true, features = ["wal-message-queue", "wal-rocksdb", "wal-table-kv"] }
27 changes: 27 additions & 0 deletions src/metric_engine/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use thiserror::Error;

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Internal(#[from] anyhow::Error),
}

pub type Result<T> = std::result::Result<T, Error>;
22 changes: 22 additions & 0 deletions src/metric_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Storage Engine for metrics.

pub mod error;
mod sst;
pub mod table_storage;
pub mod types;

pub use error::{Error, Result};
24 changes: 24 additions & 0 deletions src/metric_engine/src/sst.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use object_store::ObjectStoreRef;

pub struct SSTable {
pub table_id: u64,
pub sst_id: u64,
pub storage: ObjectStoreRef,
}
63 changes: 60 additions & 3 deletions src/metric_engine/src/table_storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;

use common_types::time::TimeRange;
use wal::manager::WalManagerRef;

pub struct SSTable {
id: u64,
use crate::{
sst::SSTable,
types::{Predicate, Row},
Result,
};

pub const METRICS_TABLE: &str = "__metrics__";
pub const SERIES_TABLE: &str = "__series__";
pub const INDEX_TABLE: &str = "__index__";

pub struct TableManager {
shard_id: u32,
// Key: table name, Value: table storage.
// table name is fixed, so we can use &'static str.
all_tables: HashMap<&'static str, TableStorage>,
}

/// Storage to represent different components of the system.
Expand All @@ -14,6 +47,30 @@ pub struct SSTable {
pub struct TableStorage {
name: String,
id: u64,
wal: WalManagerRef,
// TODO: currently not used, all writes go to memory directly.
_wal: Option<WalManagerRef>,
sstables: Vec<SSTable>,
}

impl TableStorage {
pub fn new(name: String, id: u64) -> Self {
Self {
name,
id,
_wal: None,
sstables: Vec::new(),
}
}

pub async fn write(row: Row) -> Result<()> {
unimplemented!()
}

pub async fn scan(range: TimeRange, predicate: Predicate) -> Result<()> {
unimplemented!()
}

pub async fn compact() -> Result<()> {
unimplemented!()
}
}
32 changes: 32 additions & 0 deletions src/metric_engine/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

pub enum Value {
Int64(i64),
Int32(i32),
Float64(f64),
Bytes(Vec<u8>),
}

pub type Row = Vec<Value>;

pub enum Predicate {
Equal(Value),
NotEqual(Value),
RegexMatch(Value),
NotRegexMatch(Value),
}

0 comments on commit 84156fe

Please sign in to comment.