| 554 | } |
| 555 | |
| 556 | bool Storage::IsEmptyDB() { |
| 557 | std::unique_ptr<rocksdb::Iterator> iter( |
| 558 | db_->NewIterator(DefaultScanOptions(), GetCFHandle(ColumnFamilyID::Metadata))); |
| 559 | for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { |
| 560 | Metadata metadata(kRedisNone, false); |
| 561 | // If cannot decode the metadata we think the key is alive, so the db is not empty |
| 562 | if (!metadata.Decode(iter->value()).ok() || !metadata.Expired()) { |
| 563 | return false; |
| 564 | } |
| 565 | } |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | void Storage::EmptyDB() { |
| 570 | // Clean old backups and checkpoints |