Skip to content
Open
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
16 changes: 12 additions & 4 deletions src/tendisplus/commands/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,11 @@ class ScanCommand : public Command {
auto kvstoreSlots = getKvstoreSlots(kvstoreId, kvstoreCount, slots);
auto cursor = txn->createDataCursor();
cursor->seek(lastScanRecordKey.encode());
auto seekSlotId = lastScanRecordKey.getChunkId();

while (result.size() < count && *scanTimes < scanMaxTimes) {
// get cursor current record and iterate next cursor
auto expRecord = cursor->next();
(*scanTimes)++;

// ERR_EXHAUST means this kv-store has been iterated over
if (expRecord.status().code() == ErrorCodes::ERR_EXHAUST) {
Expand Down Expand Up @@ -828,7 +828,8 @@ class ScanCommand : public Command {
auto recordSlotId = record.getRecordKey().getChunkId();
auto recordDbId = record.getRecordKey().getDbId();
auto recordType = record.getRecordKey().getRecordType();
if (!kvstoreSlots.test(recordSlotId) || recordDbId != dbId ||
auto isRecordValidSlotId = kvstoreSlots.test(recordSlotId);
if (!isRecordValidSlotId || recordDbId != dbId ||
recordType != RecordType::RT_DATA_META) {
// seq: this key in DBID db's position
// means, recordDbId == dbId && recordType == RT_DATA_META
Expand All @@ -841,18 +842,25 @@ class ScanCommand : public Command {
// recordType == RecordType::RT_DATA_META) {
// (*seq)++;
// }
auto nextSlot = getNextSlot(slots, recordSlotId);
int32_t nextSlot = recordSlotId;
if (!isRecordValidSlotId || recordSlotId == seekSlotId ||
rt2Char(recordType) > rt2Char(RecordType::RT_DATA_META) ||
recordDbId > dbId) {
nextSlot = getNextSlot(slots, recordSlotId);
}
// nextSlot == -1 means this kv-store has been iterated over
if (nextSlot == -1) {
break;
}

// construct new record key to seek
auto nextRecordKey = genRecordKey(nextSlot, dbId, "");
seekSlotId = nextSlot;
auto nextRecordKey = genRecordKey(seekSlotId, dbId, "");
cursor->seek(nextRecordKey.encode());
continue;
}

(*scanTimes)++;
/**
* check if this record has expired
* expired key shouldn't increase scanTimes,
Expand Down