PragmaTwice commented on code in PR #1279:
URL:
https://github.com/apache/incubator-kvrocks/pull/1279#discussion_r1128121589
##########
src/server/server.cc:
##########
@@ -1637,6 +1639,95 @@ Status ServerLogData::Decode(const rocksdb::Slice &blob)
{
content_ = std::string(blob.data() + 2, blob.size() - 2);
return Status::OK();
}
-
return {Status::NotOK};
}
+
+void Server::updateWatchedKeysFromRange(const std::vector<std::string> &args,
const Redis::CommandKeyRange &range) {
+ std::shared_lock lock(watched_key_mutex_);
+
+ for (size_t i = range.first_key; range.last_key > 0 ? i <=
size_t(range.last_key) : i <= args.size() + range.last_key;
+ i += range.key_step) {
+ if (auto iter = watched_key_map_.find(args[i]); iter !=
watched_key_map_.end()) {
+ for (auto *conn : iter->second) {
+ conn->watched_keys_modified_ = true;
+ }
+ }
+ }
+}
+
+void Server::updateAllWatchedKeys() {
+ std::shared_lock lock(watched_key_mutex_);
+
+ for (auto &[_, conn_map] : watched_key_map_) {
+ for (auto *conn : conn_map) {
+ conn->watched_keys_modified_ = true;
+ }
+ }
+}
+
+void Server::UpdateWatchedKeysFromArgs(const std::vector<std::string> &args,
const Redis::CommandAttributes &attr) {
+ if (attr.is_write() && watched_key_size_ > 0) {
+ if (attr.key_range.first_key > 0) {
+ updateWatchedKeysFromRange(args, attr.key_range);
+ } else if (attr.key_range.first_key < 0) {
+ Redis::CommandKeyRange range = attr.key_range_gen(args);
+
+ if (range.first_key > 0) {
+ updateWatchedKeysFromRange(args, range);
+ }
Review Comment:
That is a good question.
I have some concern here: if a command has the write attribute and a static
all-zero range, we give the upper-bound approximation as the changed key set.
But if a writable command has a dynamic range, I think we cannot make such
strict assumption, i.e. it can be that, no key is changed. Hence now I do
not update all keys in such case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]