Skip to content

Commit

Permalink
fix scan bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixficsol committed May 20, 2024
1 parent 528c6b8 commit bf332df
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 305 deletions.
6 changes: 1 addition & 5 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@ void DelCmd::DoThroughDB() {

void DelCmd::DoUpdateCache() {
if (s_.ok()) {
std::vector<std::string> v;
for (auto key : keys_) {
v.emplace_back(key);
}
db_->cache()->Del(v);
db_->cache()->Del(keys_);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/pika_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ void BRPopCmd::Do() {
} else if (s_.IsNotFound()) {
continue;
} else if (s_.IsInvalidArgument()) {
// TODO use return or continue; Mixficsol
res_.SetRes(CmdRes::kMultiKey);
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr<DB>& db) {
}
return -1;
}
key_type = storage::DataTypeToTag(type);
key_type_ = storage::DataTypeToTag(type);
if (type == storage::DataType::kNones) {
LOG(WARNING) << "Migrate slot key: " << key_ << " not found";
res_.AppendInteger(0);
Expand Down
5 changes: 5 additions & 0 deletions src/storage/src/base_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class BaseDataFilter : public rocksdb::CompactionFilter {
}
Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value);
if (s.ok()) {
/*
* The elimination policy for keys of the Data type is that if the key
* type obtained from MetaCF is inconsistent with the key type in Data,
* it needs to be eliminated
*/
auto type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
if (type != type_) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/storage/src/lists_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class ListsDataFilter : public rocksdb::CompactionFilter {
}
rocksdb::Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value);
if (s.ok()) {
/*
* The elimination policy for keys of the Data type is that if the key
* type obtained from MetaCF is inconsistent with the key type in Data,
* it needs to be eliminated
*/
auto type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
if (type != type_) {
return true;
Expand Down
9 changes: 7 additions & 2 deletions src/storage/src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string&
Status s = LoadCursorStartKey(dtype, cursor, &key_type, &start_key);
if (!s.ok()) {
// If want to scan all the databases, we start with the strings database
key_type = dtype == DataType::kAll ? DataTypeTag[static_cast<int>(dtype)] : DataTypeTag[static_cast<int>(DataType::kStrings)];
key_type = dtype == DataType::kAll ? DataTypeTag[static_cast<int>(DataType::kStrings)] : DataTypeTag[static_cast<int>(dtype)];
start_key = prefix;
cursor = 0;
}
Expand All @@ -1242,7 +1242,12 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string&
LOG(WARNING) << "Invalid key_type: " << key_type;
return 0;
}
std::copy(pos, iter_end, std::back_inserter(types));
/*
* The reason we need to subtract 2 here is that the last two types of
* DataType are all and none, and we don't need these two types when we
* traverse with the scan iterator, only the first six data types of DataType
*/
std::copy(pos, iter_end - 2, std::back_inserter(types));
} else {
types.push_back(DataTypeTag[static_cast<int>(dtype)]);
}
Expand Down
2 changes: 0 additions & 2 deletions src/storage/src/strings_value_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ParsedStringsValue : public ParsedInternalValue {
public:
// Use this constructor after rocksdb::DB::Get();
explicit ParsedStringsValue(std::string* internal_value_str) : ParsedInternalValue(internal_value_str) {
// TODO Why need this logic; Mixficsol
if (internal_value_str->size() >= kStringsValueMinLength) {
size_t offset = 0;
type_ = static_cast<DataType>(static_cast<uint8_t>((*internal_value_str)[0]));
Expand Down Expand Up @@ -101,7 +100,6 @@ class ParsedStringsValue : public ParsedInternalValue {
}

private:
// TODO Why need kStringsValueSuffixLength; Mixficsol
const static size_t kStringsValueSuffixLength = 2 * kTimestampLength + kSuffixReserveLength;
const static size_t kStringsValueMinLength = kStringsValueSuffixLength + kTypeLength;
};
Expand Down
42 changes: 27 additions & 15 deletions src/storage/src/type_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,35 @@ class AllIterator : public TypeIterator {
bool ShouldSkip() override {
std::string user_value;
auto type = static_cast<DataType>(static_cast<uint8_t>(raw_iter_->value()[0]));
if (type == DataType::kZSets || type == DataType::kSets || type == DataType::kHashes || type == DataType::kStreams) {
ParsedBaseMetaValue parsed_meta_value(raw_iter_->value());
user_value = parsed_meta_value.UserValue().ToString();
if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) {
return true;
switch (type) {
case DataType::kZSets:
case DataType::kSets:
case DataType::kHashes:
case DataType::kStreams: {
ParsedBaseMetaValue parsed_meta_value(raw_iter_->value());
user_value = parsed_meta_value.UserValue().ToString();
if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) {
return true;
}
break;
}
} else if (type == DataType::kLists) {
ParsedListsMetaValue parsed_meta_value(raw_iter_->value());
user_value = parsed_meta_value.UserValue().ToString();
if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) {
return true;

case DataType::kLists: {
ParsedListsMetaValue parsed_meta_list_value(raw_iter_->value());
user_value = parsed_meta_list_value.UserValue().ToString();
if (parsed_meta_list_value.IsStale() || parsed_meta_list_value.Count() == 0) {
return true;
}
break;
}
} else {
ParsedStringsValue parsed_value(raw_iter_->value());
user_value = parsed_value.UserValue().ToString();
if (parsed_value.IsStale()) {
return true;

default: {
ParsedStringsValue parsed_value(raw_iter_->value());
user_value = parsed_value.UserValue().ToString();
if (parsed_value.IsStale()) {
return true;
}
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/storage/src/zsets_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class ZSetsScoreFilter : public rocksdb::CompactionFilter {
}
Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value);
if (s.ok()) {
/*
* The elimination policy for keys of the Data type is that if the key
* type obtained from MetaCF is inconsistent with the key type in Data,
* it needs to be eliminated
*/
auto type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
if (type != type_) {
return true;
Expand Down
Loading

0 comments on commit bf332df

Please sign in to comment.