-
Notifications
You must be signed in to change notification settings - Fork 419
feat(mito2): expose puffin index metadata #7042
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
+1,206
−30
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
859a5bd
Add encode/decode helpers for IndexTarget
zhongzc dfd7e65
Use IndexTarget encode for puffin index blob keys
zhongzc badc088
Normalize puffin index blobs to use IndexTarget keys
zhongzc 0393a47
feat(mito2): expose puffin index metadata
zhongzc 01fb3e4
target json polish
zhongzc 0187c15
fix header
zhongzc 2c57625
Merge branch 'main' into zhongzc/index-meta-api
zhongzc bc7b1f8
add index path
zhongzc fa20dbb
Merge remote-tracking branch 'origin/main' into zhongzc/index-meta-api
zhongzc 33a554b
address copilot comments
zhongzc 48b6bb5
address comments
zhongzc 8f0df1d
reuse cached index metadata
zhongzc 141b2fd
parallelism for reading index meta
zhongzc eadeeac
Merge branch 'main' into zhongzc/index-meta-api
zhongzc 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,109 @@ | ||
// 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. | ||
|
||
use std::any::Any; | ||
|
||
use common_error::ext::ErrorExt; | ||
use common_error::status_code::StatusCode; | ||
use common_macro::stack_trace_debug; | ||
use serde::{Deserialize, Serialize}; | ||
use snafu::{Snafu, ensure}; | ||
use store_api::storage::ColumnId; | ||
|
||
/// Describes an index target. Column ids are the only supported variant for now. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub enum IndexTarget { | ||
ColumnId(ColumnId), | ||
} | ||
|
||
impl IndexTarget { | ||
/// Derive a stable target key string for the provided index target. | ||
pub fn encode(&self) -> String { | ||
match self { | ||
IndexTarget::ColumnId(id) => id.to_string(), | ||
} | ||
} | ||
|
||
/// Parse a target key string back into an index target description. | ||
pub fn decode(key: &str) -> Result<Self, TargetKeyError> { | ||
validate_column_key(key)?; | ||
let id = key | ||
.parse::<ColumnId>() | ||
.map_err(|_| TargetKeyError::InvalidColumnId { | ||
value: key.to_string(), | ||
})?; | ||
Ok(IndexTarget::ColumnId(id)) | ||
} | ||
} | ||
|
||
/// Errors that can occur when working with index target keys. | ||
#[derive(Snafu, Clone, PartialEq, Eq)] | ||
#[stack_trace_debug] | ||
pub enum TargetKeyError { | ||
#[snafu(display("target key cannot be empty"))] | ||
Empty, | ||
|
||
#[snafu(display("target key must contain digits only: {key}"))] | ||
InvalidCharacters { key: String }, | ||
|
||
#[snafu(display("failed to parse column id from '{value}'"))] | ||
InvalidColumnId { value: String }, | ||
} | ||
|
||
impl ErrorExt for TargetKeyError { | ||
fn status_code(&self) -> StatusCode { | ||
StatusCode::InvalidArguments | ||
} | ||
|
||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
} | ||
|
||
fn validate_column_key(key: &str) -> Result<(), TargetKeyError> { | ||
ensure!(!key.is_empty(), EmptySnafu); | ||
ensure!( | ||
key.chars().all(|ch| ch.is_ascii_digit()), | ||
InvalidCharactersSnafu { | ||
key: key.to_string() | ||
zhongzc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn encode_decode_column() { | ||
let target = IndexTarget::ColumnId(42); | ||
let key = target.encode(); | ||
assert_eq!(key, "42"); | ||
let decoded = IndexTarget::decode(&key).unwrap(); | ||
assert_eq!(decoded, target); | ||
} | ||
|
||
#[test] | ||
fn decode_rejects_empty() { | ||
let err = IndexTarget::decode("").unwrap_err(); | ||
assert!(matches!(err, TargetKeyError::Empty)); | ||
} | ||
|
||
#[test] | ||
fn decode_rejects_invalid_digits() { | ||
let err = IndexTarget::decode("1a2").unwrap_err(); | ||
assert!(matches!(err, TargetKeyError::InvalidCharacters { .. })); | ||
} | ||
} |
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
Oops, something went wrong.
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.