-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: PkPatternMatchDel inconsistent between rediscache and db #2839
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,7 @@ Status RedisHashes::ScanKeys(const std::string& pattern, std::vector<std::string | |
return Status::OK(); | ||
} | ||
|
||
Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { | ||
Status RedisHashes::PKPatternMatchDelWithRemoveKeys(const DataType& data_type, const std::string& pattern, int64_t* ret, std::vector<std::string>* remove_keys, const int64_t& max_count) { | ||
AlexStocks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rocksdb::ReadOptions iterator_options; | ||
const rocksdb::Snapshot* snapshot; | ||
ScopeSnapshot ss(db_, &snapshot); | ||
|
@@ -154,27 +154,28 @@ Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret) | |
|
||
std::string key; | ||
std::string meta_value; | ||
int32_t total_delete = 0; | ||
int64_t total_delete = 0; | ||
Status s; | ||
rocksdb::WriteBatch batch; | ||
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]); | ||
DEFER { | ||
delete iter; | ||
}; | ||
iter->SeekToFirst(); | ||
while (iter->Valid()) { | ||
while (iter->Valid() && static_cast<int64_t>(batch.Count()) < max_count) { | ||
key = iter->key().ToString(); | ||
meta_value = iter->value().ToString(); | ||
ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value); | ||
if (!parsed_hashes_meta_value.IsStale() && (parsed_hashes_meta_value.count() != 0) && | ||
(StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { | ||
parsed_hashes_meta_value.InitialMetaValue(); | ||
batch.Put(handles_[0], key, meta_value); | ||
remove_keys->push_back(key.data()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key已经是string类型了吧?直接push_back(key)就可以了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
} | ||
if (static_cast<size_t>(batch.Count()) >= BATCH_DELETE_LIMIT) { | ||
s = db_->Write(default_write_options_, &batch); | ||
if (s.ok()) { | ||
total_delete += static_cast<int32_t>( batch.Count()); | ||
total_delete += static_cast<int64_t>( batch.Count()); | ||
batch.Clear(); | ||
} else { | ||
*ret = total_delete; | ||
|
@@ -186,7 +187,7 @@ Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret) | |
if (batch.Count() != 0U) { | ||
s = db_->Write(default_write_options_, &batch); | ||
if (s.ok()) { | ||
total_delete += static_cast<int32_t>(batch.Count()); | ||
total_delete += static_cast<int64_t>(batch.Count()); | ||
batch.Clear(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,7 @@ Status RedisLists::ScanKeys(const std::string& pattern, std::vector<std::string> | |
return Status::OK(); | ||
} | ||
|
||
Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { | ||
Status RedisLists::PKPatternMatchDelWithRemoveKeys(const DataType& data_type, const std::string& pattern, int64_t* ret, std::vector<std::string>* remove_keys, const int64_t& max_count) { | ||
rocksdb::ReadOptions iterator_options; | ||
const rocksdb::Snapshot* snapshot; | ||
ScopeSnapshot ss(db_, &snapshot); | ||
|
@@ -161,27 +161,28 @@ Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { | |
|
||
std::string key; | ||
std::string meta_value; | ||
int32_t total_delete = 0; | ||
int64_t total_delete = 0; | ||
Status s; | ||
rocksdb::WriteBatch batch; | ||
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]); | ||
DEFER { | ||
delete iter; | ||
}; | ||
iter->SeekToFirst(); | ||
while (iter->Valid()) { | ||
while (iter->Valid() && static_cast<int64_t>(batch.Count()) < max_count) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 182行的逻辑,里边会执行batch.clear,所以用batch.Count()去比不准确。要不你就跟4.0里的一样,把182 if里的删掉,统一在外边调用一次batch.put。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
key = iter->key().ToString(); | ||
meta_value = iter->value().ToString(); | ||
ParsedListsMetaValue parsed_lists_meta_value(&meta_value); | ||
if (!parsed_lists_meta_value.IsStale() && (parsed_lists_meta_value.count() != 0U) && | ||
(StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { | ||
parsed_lists_meta_value.InitialMetaValue(); | ||
batch.Put(handles_[0], key, meta_value); | ||
remove_keys->push_back(key.data()); | ||
} | ||
if (static_cast<size_t>(batch.Count()) >= BATCH_DELETE_LIMIT) { | ||
s = db_->Write(default_write_options_, &batch); | ||
if (s.ok()) { | ||
total_delete += static_cast<int32_t>(batch.Count()); | ||
total_delete += static_cast<int64_t>(batch.Count()); | ||
batch.Clear(); | ||
} else { | ||
*ret = total_delete; | ||
|
@@ -193,7 +194,7 @@ Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { | |
if (batch.Count() != 0U) { | ||
s = db_->Write(default_write_options_, &batch); | ||
if (s.ok()) { | ||
total_delete += static_cast<int32_t>(batch.Count()); | ||
total_delete += static_cast<int64_t>(batch.Count()); | ||
batch.Clear(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argv_[2]是类型,这里应该是argv[3],上边的if条件也得是>3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done