-
Notifications
You must be signed in to change notification settings - Fork 490
feat(mito): Add WriteCache struct and write SSTs to write cache #2999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9e4371d
docs: remove todo
evenyag 6c0ab68
feat: add upload cache
evenyag 195ce56
feat: add cache to sst write path
evenyag 48d1c1b
feat: add storage to part
evenyag d6eee6d
feat: add dir to part
evenyag 0c2efdf
feat: revert storage name
evenyag 47c9fef
feat: flush use upload part writer
evenyag 1280b1e
feat: use upload part writer in compaction task
evenyag 1247d3d
refactor: upload part writer builds parquet writer
evenyag ed8d700
chore: suppress warnings
evenyag 8b27e8d
refactor: rename UploadCache to WriteCache
evenyag de00923
refactor: move source to write_all()
evenyag 61ec72d
chore: typos
evenyag 168f05a
chore: remove output mod
evenyag 5294510
feat: changes upload to async method
evenyag 21a8acd
docs: update cache
evenyag 1ede9b3
chore: Merge branch 'develop' into feat/write-cache
evenyag c5044a3
chore: fix compiler errors
evenyag 0d90ed6
docs: remove comment
evenyag 0b5544c
chore: simplify upload part
evenyag d517d41
refactor: remove option from cache manager param to access layer
evenyag 44098d7
chore: Merge branch 'main' into feat/write-cache
evenyag 2044f38
feat: remove cache home from file cache
evenyag 6b814e7
feat: write cache holds file cache
evenyag e7192b8
feat: add recover and pub some methods
evenyag 0278513
feat: remove usages of UploadPartWriter
evenyag 0e8b58f
refactor: move sst_file_path to sst mod
evenyag 9f03e67
refactor: use write cache in access layer
evenyag 7cb11d8
refactor: remove upload
evenyag 6a66893
style: fix clippy
evenyag 75c0759
chore: Merge branch 'main' into feat/write-cache
evenyag 962a9d1
refactor: pub write cache method/structs
evenyag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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(crate) 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(crate) struct SstUploadRequest { | ||
| pub(crate) file_id: FileId, | ||
| pub(crate) metadata: RegionMetadataRef, | ||
| pub(crate) source: Source, | ||
| pub(crate) storage: Option<String>, | ||
| /// Path to upload the file. | ||
| pub(crate) upload_path: String, | ||
| /// Remote object store to upload. | ||
| pub(crate) remote_store: ObjectStore, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.