From 87723effc7e4849927bd5aa543cccfbea533eba7 Mon Sep 17 00:00:00 2001 From: evenyag Date: Sun, 9 Mar 2025 15:33:00 +0800 Subject: [PATCH] feat: declare converter --- src/sst-convert/src/converter.rs | 69 ++++++++++++++++++++++++++++++++ src/sst-convert/src/lib.rs | 1 + src/sst-convert/src/table.rs | 1 + 3 files changed, 71 insertions(+) create mode 100644 src/sst-convert/src/converter.rs diff --git a/src/sst-convert/src/converter.rs b/src/sst-convert/src/converter.rs new file mode 100644 index 0000000000..3b6168e164 --- /dev/null +++ b/src/sst-convert/src/converter.rs @@ -0,0 +1,69 @@ +// Copyright 2023 Greptime Team +// +// Licensed 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. + +//! SST converter. + +use datanode::config::{FileConfig, StorageConfig}; +use datanode::datanode::DatanodeBuilder; +use datanode::store::fs::new_fs_object_store; +use meta_client::MetaClientOptions; +use object_store::manager::ObjectStoreManagerRef; +use object_store::ObjectStore; +use snafu::ResultExt; + +use crate::error::{DatanodeSnafu, Result}; + +/// SST converter takes a list of source files and converts them to SST files. +pub struct SstConverter { + /// Object store for input files + input_store: ObjectStore, + /// Object store manager for output files. + output_store_manager: ObjectStoreManagerRef, +} + +impl SstConverter { + // +} + +/// Builder to build a SST converter. +pub struct SstConverterBuilder { + input_path: String, + meta_options: MetaClientOptions, + storage_config: StorageConfig, +} + +impl SstConverterBuilder { + /// Creates a new builder. + pub fn new(input_path: String) -> Self { + Self { + input_path, + meta_options: MetaClientOptions::default(), + storage_config: StorageConfig::default(), + } + } +} + +/// A hepler function to create the object store manager. +pub async fn new_object_store_manager(config: &StorageConfig) -> Result { + DatanodeBuilder::build_object_store_manager(config) + .await + .context(DatanodeSnafu) +} + +/// Creates a input store from a path. +pub async fn new_input_store(path: &str) -> Result { + new_fs_object_store(path, &FileConfig::default()) + .await + .context(DatanodeSnafu) +} diff --git a/src/sst-convert/src/lib.rs b/src/sst-convert/src/lib.rs index b4b588ecc6..c85a16731f 100644 --- a/src/sst-convert/src/lib.rs +++ b/src/sst-convert/src/lib.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub mod converter; pub mod error; mod reader; mod table; diff --git a/src/sst-convert/src/table.rs b/src/sst-convert/src/table.rs index 51f0003d0b..fc9681cd7b 100644 --- a/src/sst-convert/src/table.rs +++ b/src/sst-convert/src/table.rs @@ -22,6 +22,7 @@ use common_meta::key::table_name::TableNameKey; use common_meta::key::{TableMetadataManager, TableMetadataManagerRef}; use meta_client::{MetaClientOptions, MetaClientType}; +// TODO(yingwen): Error handling. #[derive(Clone)] pub struct TableMetadataHelper { table_metadata_manager: TableMetadataManagerRef,