-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mito): Add WriteCache struct and write SSTs to write cache (#2999)
* docs: remove todo * feat: add upload cache * feat: add cache to sst write path * feat: add storage to part * feat: add dir to part * feat: revert storage name * feat: flush use upload part writer * feat: use upload part writer in compaction task * refactor: upload part writer builds parquet writer * chore: suppress warnings * refactor: rename UploadCache to WriteCache * refactor: move source to write_all() * chore: typos * chore: remove output mod * feat: changes upload to async method * docs: update cache * chore: fix compiler errors * docs: remove comment * chore: simplify upload part * refactor: remove option from cache manager param to access layer * feat: remove cache home from file cache * feat: write cache holds file cache * feat: add recover and pub some methods * feat: remove usages of UploadPartWriter * refactor: move sst_file_path to sst mod * refactor: use write cache in access layer * refactor: remove upload * style: fix clippy * refactor: pub write cache method/structs
- Loading branch information
Showing
15 changed files
with
309 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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. | ||
|
||
//! A write-through cache for remote object stores. | ||
use std::sync::Arc; | ||
|
||
use common_base::readable_size::ReadableSize; | ||
use object_store::manager::ObjectStoreManagerRef; | ||
use object_store::ObjectStore; | ||
use store_api::metadata::RegionMetadataRef; | ||
|
||
use crate::cache::file_cache::{FileCache, FileCacheRef}; | ||
use crate::error::Result; | ||
use crate::read::Source; | ||
use crate::sst::file::FileId; | ||
use crate::sst::parquet::writer::ParquetWriter; | ||
use crate::sst::parquet::{SstInfo, WriteOptions}; | ||
|
||
/// A cache for uploading files to remote object stores. | ||
/// | ||
/// It keeps files in local disk and then sends files to object stores. | ||
pub struct WriteCache { | ||
/// Local file cache. | ||
file_cache: FileCacheRef, | ||
/// Object store manager. | ||
object_store_manager: ObjectStoreManagerRef, | ||
} | ||
|
||
pub type WriteCacheRef = Arc<WriteCache>; | ||
|
||
impl WriteCache { | ||
/// Create the cache with a `local_store` to cache files and a | ||
/// `object_store_manager` for all object stores. | ||
pub fn new( | ||
local_store: ObjectStore, | ||
object_store_manager: ObjectStoreManagerRef, | ||
cache_capacity: ReadableSize, | ||
) -> Self { | ||
Self { | ||
file_cache: Arc::new(FileCache::new(local_store, cache_capacity)), | ||
object_store_manager, | ||
} | ||
} | ||
|
||
/// Recovers the write cache from local store. | ||
pub async fn recover(&self) -> Result<()> { | ||
self.file_cache.recover().await | ||
} | ||
|
||
/// Writes SST to the cache and then uploads it to the remote object store. | ||
pub async fn write_and_upload_sst( | ||
&self, | ||
request: SstUploadRequest, | ||
write_opts: &WriteOptions, | ||
) -> Result<Option<SstInfo>> { | ||
// TODO(yingwen): Write to the local store and then upload. | ||
// Now we write to the remote and ignore local cache. | ||
let mut writer = | ||
ParquetWriter::new(request.upload_path, request.metadata, request.remote_store); | ||
writer.write_all(request.source, write_opts).await | ||
} | ||
} | ||
|
||
/// Request to write and upload a SST. | ||
pub struct SstUploadRequest { | ||
pub file_id: FileId, | ||
pub metadata: RegionMetadataRef, | ||
pub source: Source, | ||
pub storage: Option<String>, | ||
/// Path to upload the file. | ||
pub upload_path: String, | ||
/// Remote object store to upload. | ||
pub remote_store: ObjectStore, | ||
} |
Oops, something went wrong.