Skip to content
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

feat: improve extract hints #4479

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/servers/src/grpc/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,12 @@ fn extract_hints(metadata: &MetadataMap) -> Vec<(String, String)> {
return None;
};
let key = key.as_str();
if !key.starts_with(GREPTIME_DB_HEADER_HINT_PREFIX) {
return None;
}
let new_key = key.strip_prefix(GREPTIME_DB_HEADER_HINT_PREFIX)?;
let Ok(value) = value.to_str() else {
// Simply return None for non-string values.
return None;
};
// Safety: we already checked the prefix.
let new_key = key
.strip_prefix(GREPTIME_DB_HEADER_HINT_PREFIX)
.unwrap()
.to_string();
Some((new_key, value.trim().to_string()))
Some((new_key.to_string(), value.trim().to_string()))
})
.collect()
}
Expand All @@ -181,6 +174,7 @@ mod tests {
"x-greptime-hint-append_mode",
MetadataValue::from_static("true"),
);
metadata.insert("test-key", MetadataValue::from_static("test-value"));
assert!(prev.is_none());
let hints = extract_hints(&metadata);
assert_eq!(hints, vec![("append_mode".to_string(), "true".to_string())]);
Expand Down