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(meta): refactor watch key range from [start,end] to [start,end) #6499

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion common/meta/types/proto/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ message WatchRequest {
// key is the key to register for watching.
string key = 1;

// key_end is the end of the range [key, key_end] to watch.
// key_end is the end of the range [key, key_end) to watch.
// if key_end is None, then watch only key.
optional string key_end = 2;

Expand Down
2 changes: 1 addition & 1 deletion metasrv/src/watcher/watcher_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl WatcherManagerCore {
if &key > key_end {
return Err(false);
}
Ok(key..format!("{}\x00", key_end))
Ok(key..key_end.to_string())
}
None => Ok(key.clone()..key),
}
Expand Down
19 changes: 5 additions & 14 deletions metasrv/tests/it/grpc/metasrv_grpc_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ async fn test_watch() -> anyhow::Result<()> {

let key_a = "a".to_string();
let key_b = "b".to_string();
let key_z = "z".to_string();

let val_a = "a".as_bytes().to_vec();
let val_b = "b".as_bytes().to_vec();
let val_new = "new".as_bytes().to_vec();
let val_z = "z".as_bytes().to_vec();

let events = vec![
let watch_events = vec![
// set a->a
Event {
key: key_a.clone(),
Expand All @@ -122,15 +121,6 @@ async fn test_watch() -> anyhow::Result<()> {
}),
prev: None,
},
// set z->z
Event {
key: key_z.clone(),
current: Some(SeqV {
seq: seq + 1,
data: val_z.clone(),
}),
prev: None,
},
// set b->b
Event {
key: key_b.clone(),
Expand Down Expand Up @@ -167,12 +157,13 @@ async fn test_watch() -> anyhow::Result<()> {
// update kv
let updates = vec![
UpsertKVReq::new("a", MatchSeq::Any, Operation::Update(val_a), None),
// upsert key z, because z in key_end and the range is [key_start, key_end), so key z MUST not be notified in watche events.
UpsertKVReq::new("z", MatchSeq::Any, Operation::Update(val_z), None),
UpsertKVReq::new("b", MatchSeq::Any, Operation::Update(val_b), None),
UpsertKVReq::new("b", MatchSeq::Any, Operation::Update(val_new), None),
UpsertKVReq::new("b", MatchSeq::Any, Operation::Delete, None),
];
test_watch_main(addr.clone(), watch, events, updates).await?;
test_watch_main(addr.clone(), watch, watch_events, updates).await?;
}

// 2. test filter
Expand All @@ -190,7 +181,7 @@ async fn test_watch() -> anyhow::Result<()> {
let val_new = "new".as_bytes().to_vec();

// has only delete events
let events = vec![
let watch_events = vec![
// delete 1 first time
Event {
key: key.clone(),
Expand Down Expand Up @@ -218,7 +209,7 @@ async fn test_watch() -> anyhow::Result<()> {
UpsertKVReq::new(key_str, MatchSeq::Any, Operation::Update(val_new), None),
UpsertKVReq::new(key_str, MatchSeq::Any, Operation::Delete, None),
];
test_watch_main(addr.clone(), watch, events, updates).await?;
test_watch_main(addr.clone(), watch, watch_events, updates).await?;
}

Ok(())
Expand Down