Skip to content

Commit d30e49e

Browse files
committed
fix: rdb load bugs
1 parent bfa5c4d commit d30e49e

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

server/db.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ int MiniKVDB::setExpire(std::string key, uint64_t expires) {
5959
}
6060

6161
void MiniKVDB::rdbSave() {
62+
// TODO: save the expire time
6263
std::unique_lock<std::shared_mutex> lk(smutex_);
6364
kvlogi("rdb save triggered!");
6465
io_->clearFile();
@@ -187,11 +188,11 @@ void MiniKVDB::rdbLoadEntry() {
187188
}
188189

189190
void MiniKVDB::rdbFileReadInitDB() {
190-
if (io_->emptyFile()) {
191+
if (io_->empty()) {
191192
kvlogi("No rdb file to load.");
192193
return;
193194
}
194-
while (!io_->reachEOF()) {
195+
while (!io_->empty()) {
195196
rdbLoadEntry();
196197
}
197198
kvlogi("Rdb file loaded.");

server/db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef class MiniKVDB {
4848
void rdbFileReadInitDB();
4949
void rdbLoadEntry();
5050
void rdbSave();
51+
// void fixedTimeDeleteExpiredKey();
5152
public:
5253
void insert(std::string key, std::string val, uint32_t encoding);
5354
void get(std::string key, std::vector<std::string>& res);

server/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class KVio {
3333
bool reachEOF() {
3434
return feof(fp_);
3535
}
36-
bool emptyFile() {
36+
bool empty() {
3737
if (!fp_) return true;
3838
getc(fp_);
3939
if (feof(fp_)) {

0 commit comments

Comments
 (0)