Skip to content

Commit 1f73513

Browse files
committed
Remove DB::VerifyFileChecksums
1 parent d567357 commit 1f73513

File tree

10 files changed

+82
-20
lines changed

10 files changed

+82
-20
lines changed

db/corruption_test.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,15 @@ TEST_F(CorruptionTest, VerifyWholeTableChecksum) {
840840

841841
Build(10, 5);
842842

843-
ASSERT_OK(db_->VerifyFileChecksums(ReadOptions()));
843+
auto* dbi = static_cast_with_check<DBImpl>(db_);
844+
ASSERT_OK(dbi->VerifyFileChecksums(ReadOptions()));
844845
CloseDb();
845846

846847
// Corrupt the first byte of each table file, this must be data block.
847848
Corrupt(kTableFile, 0, 1);
848849

849850
ASSERT_OK(TryReopen(&options));
851+
dbi = static_cast_with_check<DBImpl>(db_);
850852

851853
SyncPoint::GetInstance()->DisableProcessing();
852854
SyncPoint::GetInstance()->ClearAllCallBacks();
@@ -859,8 +861,23 @@ TEST_F(CorruptionTest, VerifyWholeTableChecksum) {
859861
ASSERT_NOK(*s);
860862
});
861863
SyncPoint::GetInstance()->EnableProcessing();
862-
ASSERT_TRUE(db_->VerifyFileChecksums(ReadOptions()).IsCorruption());
864+
ASSERT_TRUE(dbi->VerifyFileChecksums(ReadOptions()).IsCorruption());
863865
ASSERT_EQ(1, count);
866+
867+
CloseDb();
868+
ASSERT_OK(DestroyDB(dbname_, options));
869+
Reopen(&options);
870+
Build(10, 5);
871+
dbi = static_cast_with_check<DBImpl>(db_);
872+
ASSERT_OK(dbi->VerifyFileChecksums(ReadOptions()));
873+
CloseDb();
874+
Corrupt(kTableFile, 0, 1);
875+
876+
// Set best_efforts_recovery to true
877+
options.best_efforts_recovery = true;
878+
#ifdef OS_LINUX
879+
ASSERT_TRUE(TryReopen(&options).IsCorruption());
880+
#endif // OS_LINUX
864881
}
865882

866883
} // namespace ROCKSDB_NAMESPACE

db/db_basic_test.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,8 @@ TEST_F(DBBasicTest, MultiGetIOBufferOverrun) {
22012201

22022202
TEST_F(DBBasicTest, IncrementalRecoveryNoCorrupt) {
22032203
Options options = CurrentOptions();
2204+
options.file_checksum_gen_factory =
2205+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
22042206
DestroyAndReopen(options);
22052207
CreateAndReopenWithCF({"pikachu", "eevee"}, options);
22062208
size_t num_cfs = handles_.size();
@@ -2239,6 +2241,8 @@ TEST_F(DBBasicTest, IncrementalRecoveryNoCorrupt) {
22392241

22402242
TEST_F(DBBasicTest, BestEffortsRecoveryWithVersionBuildingFailure) {
22412243
Options options = CurrentOptions();
2244+
options.file_checksum_gen_factory =
2245+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
22422246
DestroyAndReopen(options);
22432247
ASSERT_OK(Put("foo", "value"));
22442248
ASSERT_OK(Flush());
@@ -2285,6 +2289,8 @@ TEST_F(DBBasicTest, RecoverWithMissingFiles) {
22852289
// Disable auto compaction to simplify SST file name tracking.
22862290
options.disable_auto_compactions = true;
22872291
options.listeners.emplace_back(listener);
2292+
options.file_checksum_gen_factory =
2293+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
22882294
CreateAndReopenWithCF({"pikachu", "eevee"}, options);
22892295
std::vector<std::string> all_cf_names = {kDefaultColumnFamilyName, "pikachu",
22902296
"eevee"};
@@ -2345,6 +2351,8 @@ TEST_F(DBBasicTest, RecoverWithMissingFiles) {
23452351

23462352
TEST_F(DBBasicTest, BestEffortsRecoveryTryMultipleManifests) {
23472353
Options options = CurrentOptions();
2354+
options.file_checksum_gen_factory =
2355+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
23482356
options.env = env_;
23492357
DestroyAndReopen(options);
23502358
ASSERT_OK(Put("foo", "value0"));
@@ -2371,6 +2379,8 @@ TEST_F(DBBasicTest, BestEffortsRecoveryTryMultipleManifests) {
23712379

23722380
TEST_F(DBBasicTest, RecoverWithNoCurrentFile) {
23732381
Options options = CurrentOptions();
2382+
options.file_checksum_gen_factory =
2383+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
23742384
options.env = env_;
23752385
DestroyAndReopen(options);
23762386
CreateAndReopenWithCF({"pikachu"}, options);
@@ -2394,6 +2404,8 @@ TEST_F(DBBasicTest, RecoverWithNoCurrentFile) {
23942404

23952405
TEST_F(DBBasicTest, RecoverWithNoManifest) {
23962406
Options options = CurrentOptions();
2407+
options.file_checksum_gen_factory =
2408+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
23972409
options.env = env_;
23982410
DestroyAndReopen(options);
23992411
ASSERT_OK(Put("foo", "value"));
@@ -2423,6 +2435,8 @@ TEST_F(DBBasicTest, RecoverWithNoManifest) {
24232435

24242436
TEST_F(DBBasicTest, SkipWALIfMissingTableFiles) {
24252437
Options options = CurrentOptions();
2438+
options.file_checksum_gen_factory =
2439+
ROCKSDB_NAMESPACE::GetFileChecksumGenCrc32cFactory();
24262440
DestroyAndReopen(options);
24272441
TableFileListener* listener = new TableFileListener();
24282442
options.listeners.emplace_back(listener);
@@ -3311,17 +3325,17 @@ TEST_F(DBBasicTest, VerifyFileChecksums) {
33113325
DestroyAndReopen(options);
33123326
ASSERT_OK(Put("a", "value"));
33133327
ASSERT_OK(Flush());
3314-
ASSERT_TRUE(db_->VerifyFileChecksums(ReadOptions()).IsInvalidArgument());
3328+
ASSERT_TRUE(dbfull()->VerifyFileChecksums(ReadOptions()).IsInvalidArgument());
33153329

33163330
options.file_checksum_gen_factory = GetFileChecksumGenCrc32cFactory();
33173331
Reopen(options);
3318-
ASSERT_OK(db_->VerifyFileChecksums(ReadOptions()));
3332+
ASSERT_OK(dbfull()->VerifyFileChecksums(ReadOptions()));
33193333

33203334
// Write an L0 with checksum computed.
33213335
ASSERT_OK(Put("b", "value"));
33223336
ASSERT_OK(Flush());
33233337

3324-
ASSERT_OK(db_->VerifyFileChecksums(ReadOptions()));
3338+
ASSERT_OK(dbfull()->VerifyFileChecksums(ReadOptions()));
33253339
}
33263340
#endif // !ROCKSDB_LITE
33273341

db/db_impl/db_impl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4778,11 +4778,11 @@ Status DBImpl::VerifyChecksumInternal(const ReadOptions& read_options,
47784778
j++) {
47794779
const auto& fd_with_krange = vstorage->LevelFilesBrief(i).files[j];
47804780
const auto& fd = fd_with_krange.fd;
4781-
const FileMetaData* fmeta = fd_with_krange.file_metadata;
4782-
assert(fmeta);
47834781
std::string fname = TableFileName(cfd->ioptions()->cf_paths,
47844782
fd.GetNumber(), fd.GetPathId());
47854783
if (use_file_checksum) {
4784+
const FileMetaData* fmeta = fd_with_krange.file_metadata;
4785+
assert(fmeta);
47864786
s = VerifySstFileChecksum(*fmeta, fname, read_options);
47874787
} else {
47884788
s = ROCKSDB_NAMESPACE::VerifySstFileChecksum(opts, file_options_,

db/db_impl/db_impl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ class DBImpl : public DB {
373373
uint64_t start_time, uint64_t end_time,
374374
std::unique_ptr<StatsHistoryIterator>* stats_iterator) override;
375375

376+
// If immutable_db_options_.best_efforts_recovery is true, and
377+
// RocksDbFileChecksumsVerificationEnabledOnRecovery is defined and returns
378+
// true, and immutable_db_options_.file_checksum_gen_factory is not nullptr,
379+
// then call VerifyFileChecksums().
380+
Status MaybeVerifyFileChecksums();
381+
376382
#ifndef ROCKSDB_LITE
377383
using DB::ResetStats;
378384
virtual Status ResetStats() override;
@@ -431,8 +437,7 @@ class DBImpl : public DB {
431437
const ExportImportFilesMetaData& metadata,
432438
ColumnFamilyHandle** handle) override;
433439

434-
using DB::VerifyFileChecksums;
435-
Status VerifyFileChecksums(const ReadOptions& read_options) override;
440+
Status VerifyFileChecksums(const ReadOptions& read_options);
436441

437442
using DB::VerifyChecksum;
438443
virtual Status VerifyChecksum(const ReadOptions& /*read_options*/) override;

db/db_impl/db_impl_open.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
#include "test_util/sync_point.h"
2424
#include "util/rate_limiter.h"
2525

26+
#if !defined(ROCKSDB_LITE) && defined(OS_LINUX)
27+
// VerifyFileChecksums is a weak symbol.
28+
// If it is defined and returns true, and options.best_efforts_recovery = true,
29+
// and file checksum is enabled, then the checksums of table files will be
30+
// computed and verified with MANIFEST.
31+
extern "C" bool RocksDbFileChecksumsVerificationEnabledOnRecovery()
32+
__attribute__((__weak__));
33+
#endif // !ROCKSDB_LITE && OS_LINUX
34+
2635
namespace ROCKSDB_NAMESPACE {
2736
Options SanitizeOptions(const std::string& dbname, const Options& src) {
2837
auto db_options = SanitizeOptions(dbname, DBOptions(src));
@@ -1404,6 +1413,22 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd,
14041413
return s;
14051414
}
14061415

1416+
Status DBImpl::MaybeVerifyFileChecksums() {
1417+
Status s;
1418+
#if !defined(ROCKSDB_LITE) && defined(OS_LINUX)
1419+
// TODO: remove the VerifyFileChecksums() call because it's very expensive.
1420+
if (immutable_db_options_.best_efforts_recovery &&
1421+
RocksDbFileChecksumsVerificationEnabledOnRecovery &&
1422+
RocksDbFileChecksumsVerificationEnabledOnRecovery() &&
1423+
immutable_db_options_.file_checksum_gen_factory) {
1424+
s = VerifyFileChecksums(ReadOptions());
1425+
ROCKS_LOG_INFO(immutable_db_options_.info_log,
1426+
"Verified file checksums: %s\n", s.ToString().c_str());
1427+
}
1428+
#endif // !ROCKSDB_LITE && OS_LINUX
1429+
return s;
1430+
}
1431+
14071432
Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
14081433
DBOptions db_options(options);
14091434
ColumnFamilyOptions cf_options(options);
@@ -1779,6 +1804,9 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname,
17791804
"Persisting Option File error: %s",
17801805
persist_options_status.ToString().c_str());
17811806
}
1807+
if (s.ok()) {
1808+
s = impl->MaybeVerifyFileChecksums();
1809+
}
17821810
if (s.ok()) {
17831811
impl->StartPeriodicWorkScheduler();
17841812
} else {

db/db_impl/db_impl_readonly.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ Status DBImplReadOnly::OpenForReadOnlyWithoutCheck(
233233
}
234234
impl->mutex_.Unlock();
235235
sv_context.Clean();
236+
if (s.ok()) {
237+
s = impl->MaybeVerifyFileChecksums();
238+
}
236239
if (s.ok()) {
237240
*dbptr = impl;
238241
for (auto* h : *handles) {

db/db_test_util.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "rocksdb/utilities/object_registry.h"
1616
#include "util/random.h"
1717

18+
extern "C" bool RocksDbFileChecksumsVerificationEnabledOnRecovery() {
19+
return true;
20+
}
21+
1822
namespace ROCKSDB_NAMESPACE {
1923

2024
namespace {

db/db_test_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include "util/string_util.h"
5050
#include "utilities/merge_operators.h"
5151

52+
extern "C" bool RocksDbFileChecksumsVerificationEnabledOnRecovery();
53+
5254
namespace ROCKSDB_NAMESPACE {
5355

5456
namespace anon {

include/rocksdb/db.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,6 @@ class DB {
14431443
const ExportImportFilesMetaData& metadata,
14441444
ColumnFamilyHandle** handle) = 0;
14451445

1446-
// Verify the checksums of files in db. Currently the whole-file checksum of
1447-
// table files are checked.
1448-
virtual Status VerifyFileChecksums(const ReadOptions& /*read_options*/) {
1449-
return Status::NotSupported("File verification not supported");
1450-
}
1451-
14521446
// Verify the block checksums of files in db. The block checksums of table
14531447
// files are checked.
14541448
virtual Status VerifyChecksum(const ReadOptions& read_options) = 0;

include/rocksdb/utilities/stackable_db.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ class StackableDB : public DB {
141141
import_options, metadata, handle);
142142
}
143143

144-
using DB::VerifyFileChecksums;
145-
Status VerifyFileChecksums(const ReadOptions& read_opts) override {
146-
return db_->VerifyFileChecksums(read_opts);
147-
}
148-
149144
virtual Status VerifyChecksum() override { return db_->VerifyChecksum(); }
150145

151146
virtual Status VerifyChecksum(const ReadOptions& options) override {

0 commit comments

Comments
 (0)