Skip to content

Commit

Permalink
feat: improve extract hints (#4479)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed Aug 1, 2024
1 parent 291d9d5 commit 62a0def
Showing 1 changed file with 3 additions and 9 deletions.
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

0 comments on commit 62a0def

Please sign in to comment.