File temperature information should be preserved when restart the DB (#9242)

Summary:
Fix a bug that causes file temperature not preserved after DB is restarted, or options.max_manifest_file_size is hit.
Also, pass temperature information to NewRandomAccessFile() to allow users to hack a solution where they don't preserve tiering information.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9242

Test Plan: Add a unit test that would fail without the fix.

Reviewed By: jay-zhuang

Differential Revision: D32818150

fbshipit-source-id: 36aa3f148c60107f7b8e9d65b63b039f9e1a1eec
This commit is contained in:
sdong 2021-12-03 14:42:05 -08:00 committed by Facebook GitHub Bot
parent bf2f504188
commit 88875df821
17 changed files with 213 additions and 182 deletions

View File

@ -203,10 +203,11 @@ class CompactionJobTestBase : public testing::Test {
VersionEdit edit; VersionEdit edit;
edit.AddFile(level, file_number, 0, 10, smallest_key, largest_key, edit.AddFile(level, file_number, 0, 10, smallest_key, largest_key,
smallest_seqno, largest_seqno, false, oldest_blob_file_number, smallest_seqno, largest_seqno, false, Temperature::kUnknown,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, oldest_blob_file_number, kUnknownOldestAncesterTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileCreationTime, kUnknownFileChecksum,
kDisableUserTimestamp, kDisableUserTimestamp); kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp);
mutex_.Lock(); mutex_.Lock();
EXPECT_OK( EXPECT_OK(

View File

@ -112,13 +112,12 @@ class CompactionPickerTest : public testing::Test {
file_number, path_id, file_size, file_number, path_id, file_size,
InternalKey(smallest, smallest_seq, kTypeValue), InternalKey(smallest, smallest_seq, kTypeValue),
InternalKey(largest, largest_seq, kTypeValue), smallest_seq, InternalKey(largest, largest_seq, kTypeValue), smallest_seq,
largest_seq, marked_for_compact, kInvalidBlobFileNumber, largest_seq, marked_for_compact, temperature, kInvalidBlobFileNumber,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp, kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
f->compensated_file_size = f->compensated_file_size =
(compensated_file_size != 0) ? compensated_file_size : file_size; (compensated_file_size != 0) ? compensated_file_size : file_size;
f->temperature = temperature;
f->oldest_ancester_time = oldest_ancestor_time; f->oldest_ancester_time = oldest_ancestor_time;
vstorage->AddFile(level, f); vstorage->AddFile(level, f);
files_.emplace_back(f); files_.emplace_back(f);

View File

@ -1611,7 +1611,7 @@ Status DBImpl::ReFitLevel(ColumnFamilyData* cfd, int level, int target_level) {
edit.AddFile( edit.AddFile(
to_level, f->fd.GetNumber(), f->fd.GetPathId(), f->fd.GetFileSize(), to_level, f->fd.GetNumber(), f->fd.GetPathId(), f->fd.GetFileSize(),
f->smallest, f->largest, f->fd.smallest_seqno, f->fd.largest_seqno, f->smallest, f->largest, f->fd.smallest_seqno, f->fd.largest_seqno,
f->marked_for_compaction, f->oldest_blob_file_number, f->marked_for_compaction, f->temperature, f->oldest_blob_file_number,
f->oldest_ancester_time, f->file_creation_time, f->file_checksum, f->oldest_ancester_time, f->file_creation_time, f->file_checksum,
f->file_checksum_func_name, f->min_timestamp, f->max_timestamp); f->file_checksum_func_name, f->min_timestamp, f->max_timestamp);
} }
@ -3196,7 +3196,7 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
c->edit()->AddFile( c->edit()->AddFile(
c->output_level(), f->fd.GetNumber(), f->fd.GetPathId(), c->output_level(), f->fd.GetNumber(), f->fd.GetPathId(),
f->fd.GetFileSize(), f->smallest, f->largest, f->fd.smallest_seqno, f->fd.GetFileSize(), f->smallest, f->largest, f->fd.smallest_seqno,
f->fd.largest_seqno, f->marked_for_compaction, f->fd.largest_seqno, f->marked_for_compaction, f->temperature,
f->oldest_blob_file_number, f->oldest_ancester_time, f->oldest_blob_file_number, f->oldest_ancester_time,
f->file_creation_time, f->file_checksum, f->file_checksum_func_name, f->file_creation_time, f->file_checksum, f->file_checksum_func_name,
f->min_timestamp, f->max_timestamp); f->min_timestamp, f->max_timestamp);

View File

@ -126,13 +126,13 @@ Status DBImpl::PromoteL0(ColumnFamilyHandle* column_family, int target_level) {
edit.SetColumnFamily(cfd->GetID()); edit.SetColumnFamily(cfd->GetID());
for (const auto& f : l0_files) { for (const auto& f : l0_files) {
edit.DeleteFile(0, f->fd.GetNumber()); edit.DeleteFile(0, f->fd.GetNumber());
edit.AddFile(target_level, f->fd.GetNumber(), f->fd.GetPathId(), edit.AddFile(
f->fd.GetFileSize(), f->smallest, f->largest, target_level, f->fd.GetNumber(), f->fd.GetPathId(),
f->fd.smallest_seqno, f->fd.largest_seqno, f->fd.GetFileSize(), f->smallest, f->largest, f->fd.smallest_seqno,
f->marked_for_compaction, f->oldest_blob_file_number, f->fd.largest_seqno, f->marked_for_compaction, f->temperature,
f->oldest_ancester_time, f->file_creation_time, f->oldest_blob_file_number, f->oldest_ancester_time,
f->file_checksum, f->file_checksum_func_name, f->file_creation_time, f->file_checksum, f->file_checksum_func_name,
f->min_timestamp, f->max_timestamp); f->min_timestamp, f->max_timestamp);
} }
status = versions_->LogAndApply(cfd, *cfd->GetLatestMutableCFOptions(), status = versions_->LogAndApply(cfd, *cfd->GetLatestMutableCFOptions(),

View File

@ -1465,13 +1465,13 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd,
constexpr int level = 0; constexpr int level = 0;
if (s.ok() && has_output) { if (s.ok() && has_output) {
edit->AddFile(level, meta.fd.GetNumber(), meta.fd.GetPathId(), edit->AddFile(
meta.fd.GetFileSize(), meta.smallest, meta.largest, level, meta.fd.GetNumber(), meta.fd.GetPathId(), meta.fd.GetFileSize(),
meta.fd.smallest_seqno, meta.fd.largest_seqno, meta.smallest, meta.largest, meta.fd.smallest_seqno,
meta.marked_for_compaction, meta.oldest_blob_file_number, meta.fd.largest_seqno, meta.marked_for_compaction, meta.temperature,
meta.oldest_ancester_time, meta.file_creation_time, meta.oldest_blob_file_number, meta.oldest_ancester_time,
meta.file_checksum, meta.file_checksum_func_name, meta.file_creation_time, meta.file_checksum,
meta.min_timestamp, meta.max_timestamp); meta.file_checksum_func_name, meta.min_timestamp, meta.max_timestamp);
for (const auto& blob : blob_file_additions) { for (const auto& blob : blob_file_additions) {
edit->AddBlobFile(blob); edit->AddBlobFile(blob);

View File

@ -6601,6 +6601,12 @@ TEST_F(DBTest2, BottommostTemperature) {
DB::Properties::kLiveSstFilesSizeAtTemperature + std::to_string(22), DB::Properties::kLiveSstFilesSizeAtTemperature + std::to_string(22),
&prop)); &prop));
ASSERT_EQ(std::atoi(prop.c_str()), 0); ASSERT_EQ(std::atoi(prop.c_str()), 0);
Reopen(options);
db_->GetColumnFamilyMetaData(&metadata);
ASSERT_EQ(2, metadata.file_count);
ASSERT_EQ(Temperature::kUnknown, metadata.levels[0].files[0].temperature);
ASSERT_EQ(Temperature::kWarm, metadata.levels[1].files[0].temperature);
} }
TEST_F(DBTest2, BottommostTemperatureUniversal) { TEST_F(DBTest2, BottommostTemperatureUniversal) {

View File

@ -440,9 +440,10 @@ Status ExternalSstFileIngestionJob::Run() {
FileMetaData f_metadata( FileMetaData f_metadata(
f.fd.GetNumber(), f.fd.GetPathId(), f.fd.GetFileSize(), f.fd.GetNumber(), f.fd.GetPathId(), f.fd.GetFileSize(),
f.smallest_internal_key, f.largest_internal_key, f.assigned_seqno, f.smallest_internal_key, f.largest_internal_key, f.assigned_seqno,
f.assigned_seqno, false, kInvalidBlobFileNumber, oldest_ancester_time, f.assigned_seqno, false, f.file_temperature, kInvalidBlobFileNumber,
current_time, f.file_checksum, f.file_checksum_func_name, oldest_ancester_time, current_time, f.file_checksum,
kDisableUserTimestamp, kDisableUserTimestamp); f.file_checksum_func_name, kDisableUserTimestamp,
kDisableUserTimestamp);
f_metadata.temperature = f.file_temperature; f_metadata.temperature = f.file_temperature;
edit_.AddFile(f.picked_level, f_metadata); edit_.AddFile(f.picked_level, f_metadata);
} }

View File

@ -960,10 +960,11 @@ Status FlushJob::WriteLevel0Table() {
edit_->AddFile(0 /* level */, meta_.fd.GetNumber(), meta_.fd.GetPathId(), edit_->AddFile(0 /* level */, meta_.fd.GetNumber(), meta_.fd.GetPathId(),
meta_.fd.GetFileSize(), meta_.smallest, meta_.largest, meta_.fd.GetFileSize(), meta_.smallest, meta_.largest,
meta_.fd.smallest_seqno, meta_.fd.largest_seqno, meta_.fd.smallest_seqno, meta_.fd.largest_seqno,
meta_.marked_for_compaction, meta_.oldest_blob_file_number, meta_.marked_for_compaction, meta_.temperature,
meta_.oldest_ancester_time, meta_.file_creation_time, meta_.oldest_blob_file_number, meta_.oldest_ancester_time,
meta_.file_checksum, meta_.file_checksum_func_name, meta_.file_creation_time, meta_.file_checksum,
meta_.min_timestamp, meta_.max_timestamp); meta_.file_checksum_func_name, meta_.min_timestamp,
meta_.max_timestamp);
edit_->SetBlobFileAdditions(std::move(blob_file_additions)); edit_->SetBlobFileAdditions(std::move(blob_file_additions));
} }

View File

@ -153,10 +153,10 @@ Status ImportColumnFamilyJob::Run() {
edit_.AddFile(file_metadata.level, f.fd.GetNumber(), f.fd.GetPathId(), edit_.AddFile(file_metadata.level, f.fd.GetNumber(), f.fd.GetPathId(),
f.fd.GetFileSize(), f.smallest_internal_key, f.fd.GetFileSize(), f.smallest_internal_key,
f.largest_internal_key, file_metadata.smallest_seqno, f.largest_internal_key, file_metadata.smallest_seqno,
file_metadata.largest_seqno, false, kInvalidBlobFileNumber, file_metadata.largest_seqno, false, file_metadata.temperature,
oldest_ancester_time, current_time, kUnknownFileChecksum, kInvalidBlobFileNumber, oldest_ancester_time, current_time,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
// If incoming sequence number is higher, update local sequence number. // If incoming sequence number is higher, update local sequence number.
if (file_metadata.largest_seqno > versions_->LastSequence()) { if (file_metadata.largest_seqno > versions_->LastSequence()) {

View File

@ -633,7 +633,7 @@ class Repairer {
table->meta.fd.GetFileSize(), table->meta.smallest, table->meta.fd.GetFileSize(), table->meta.smallest,
table->meta.largest, table->meta.fd.smallest_seqno, table->meta.largest, table->meta.fd.smallest_seqno,
table->meta.fd.largest_seqno, table->meta.marked_for_compaction, table->meta.fd.largest_seqno, table->meta.marked_for_compaction,
table->meta.oldest_blob_file_number, table->meta.temperature, table->meta.oldest_blob_file_number,
table->meta.oldest_ancester_time, table->meta.file_creation_time, table->meta.oldest_ancester_time, table->meta.file_creation_time,
table->meta.file_checksum, table->meta.file_checksum_func_name, table->meta.file_checksum, table->meta.file_checksum_func_name,
table->meta.min_timestamp, table->meta.max_timestamp); table->meta.min_timestamp, table->meta.max_timestamp);

View File

@ -17,6 +17,7 @@
#include "file/filename.h" #include "file/filename.h"
#include "file/random_access_file_reader.h" #include "file/random_access_file_reader.h"
#include "monitoring/perf_context_imp.h" #include "monitoring/perf_context_imp.h"
#include "rocksdb/advanced_options.h"
#include "rocksdb/statistics.h" #include "rocksdb/statistics.h"
#include "table/block_based/block_based_table_reader.h" #include "table/block_based/block_based_table_reader.h"
#include "table/get_context.h" #include "table/get_context.h"
@ -108,6 +109,7 @@ Status TableCache::GetTableReader(
TableFileName(ioptions_.cf_paths, fd.GetNumber(), fd.GetPathId()); TableFileName(ioptions_.cf_paths, fd.GetNumber(), fd.GetPathId());
std::unique_ptr<FSRandomAccessFile> file; std::unique_ptr<FSRandomAccessFile> file;
FileOptions fopts = file_options; FileOptions fopts = file_options;
fopts.temperature = file_temperature;
Status s = PrepareIOFromReadOptions(ro, ioptions_.clock, fopts.io_options); Status s = PrepareIOFromReadOptions(ro, ioptions_.clock, fopts.io_options);
if (s.ok()) { if (s.ok()) {
s = ioptions_.fs->NewRandomAccessFile(fname, fopts, &file, nullptr); s = ioptions_.fs->NewRandomAccessFile(fname, fopts, &file, nullptr);

View File

@ -11,6 +11,7 @@
#include "db/version_edit.h" #include "db/version_edit.h"
#include "db/version_set.h" #include "db/version_set.h"
#include "rocksdb/advanced_options.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
#include "test_util/testutil.h" #include "test_util/testutil.h"
#include "util/string_util.h" #include "util/string_util.h"
@ -67,10 +68,11 @@ class VersionBuilderTest : public testing::Test {
FileMetaData* f = new FileMetaData( FileMetaData* f = new FileMetaData(
file_number, path_id, file_size, GetInternalKey(smallest, smallest_seq), file_number, path_id, file_size, GetInternalKey(smallest, smallest_seq),
GetInternalKey(largest, largest_seq), smallest_seqno, largest_seqno, GetInternalKey(largest, largest_seq), smallest_seqno, largest_seqno,
/* marked_for_compact */ false, oldest_blob_file_number, /* marked_for_compact */ false, Temperature::kUnknown,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, oldest_blob_file_number, kUnknownOldestAncesterTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileCreationTime, kUnknownFileChecksum,
kDisableUserTimestamp, kDisableUserTimestamp); kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp);
f->compensated_file_size = file_size; f->compensated_file_size = file_size;
f->num_entries = num_entries; f->num_entries = num_entries;
f->num_deletions = num_deletions; f->num_deletions = num_deletions;
@ -129,10 +131,10 @@ class VersionBuilderTest : public testing::Test {
edit->AddFile(level, table_file_number, path_id, file_size, edit->AddFile(level, table_file_number, path_id, file_size,
GetInternalKey(smallest), GetInternalKey(largest), GetInternalKey(smallest), GetInternalKey(largest),
smallest_seqno, largest_seqno, marked_for_compaction, smallest_seqno, largest_seqno, marked_for_compaction,
blob_file_number, kUnknownOldestAncesterTime, Temperature::kUnknown, blob_file_number,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
} }
static std::shared_ptr<BlobFileMetaData> GetBlobFileMetaData( static std::shared_ptr<BlobFileMetaData> GetBlobFileMetaData(
@ -190,10 +192,10 @@ TEST_F(VersionBuilderTest, ApplyAndSaveTo) {
VersionEdit version_edit; VersionEdit version_edit;
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"), version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
GetInternalKey("350"), 200, 200, false, GetInternalKey("350"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.DeleteFile(3, 27U); version_edit.DeleteFile(3, 27U);
EnvOptions env_options; EnvOptions env_options;
@ -231,10 +233,10 @@ TEST_F(VersionBuilderTest, ApplyAndSaveToDynamic) {
VersionEdit version_edit; VersionEdit version_edit;
version_edit.AddFile(3, 666, 0, 100U, GetInternalKey("301"), version_edit.AddFile(3, 666, 0, 100U, GetInternalKey("301"),
GetInternalKey("350"), 200, 200, false, GetInternalKey("350"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.DeleteFile(0, 1U); version_edit.DeleteFile(0, 1U);
version_edit.DeleteFile(0, 88U); version_edit.DeleteFile(0, 88U);
@ -275,10 +277,10 @@ TEST_F(VersionBuilderTest, ApplyAndSaveToDynamic2) {
VersionEdit version_edit; VersionEdit version_edit;
version_edit.AddFile(4, 666, 0, 100U, GetInternalKey("301"), version_edit.AddFile(4, 666, 0, 100U, GetInternalKey("301"),
GetInternalKey("350"), 200, 200, false, GetInternalKey("350"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.DeleteFile(0, 1U); version_edit.DeleteFile(0, 1U);
version_edit.DeleteFile(0, 88U); version_edit.DeleteFile(0, 88U);
version_edit.DeleteFile(4, 6U); version_edit.DeleteFile(4, 6U);
@ -310,34 +312,34 @@ TEST_F(VersionBuilderTest, ApplyMultipleAndSaveTo) {
VersionEdit version_edit; VersionEdit version_edit;
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"), version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
GetInternalKey("350"), 200, 200, false, GetInternalKey("350"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"), version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"),
GetInternalKey("450"), 200, 200, false, GetInternalKey("450"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"), version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"),
GetInternalKey("650"), 200, 200, false, GetInternalKey("650"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"), version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"),
GetInternalKey("550"), 200, 200, false, GetInternalKey("550"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"), version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"),
GetInternalKey("750"), 200, 200, false, GetInternalKey("750"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
EnvOptions env_options; EnvOptions env_options;
constexpr TableCache* table_cache = nullptr; constexpr TableCache* table_cache = nullptr;
@ -372,51 +374,51 @@ TEST_F(VersionBuilderTest, ApplyDeleteAndSaveTo) {
VersionEdit version_edit; VersionEdit version_edit;
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"), version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
GetInternalKey("350"), 200, 200, false, GetInternalKey("350"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"), version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"),
GetInternalKey("450"), 200, 200, false, GetInternalKey("450"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"), version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"),
GetInternalKey("650"), 200, 200, false, GetInternalKey("650"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"), version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"),
GetInternalKey("550"), 200, 200, false, GetInternalKey("550"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"), version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"),
GetInternalKey("750"), 200, 200, false, GetInternalKey("750"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
ASSERT_OK(version_builder.Apply(&version_edit)); ASSERT_OK(version_builder.Apply(&version_edit));
VersionEdit version_edit2; VersionEdit version_edit2;
version_edit.AddFile(2, 808, 0, 100U, GetInternalKey("901"), version_edit.AddFile(2, 808, 0, 100U, GetInternalKey("901"),
GetInternalKey("950"), 200, 200, false, GetInternalKey("950"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
version_edit2.DeleteFile(2, 616); version_edit2.DeleteFile(2, 616);
version_edit2.DeleteFile(2, 636); version_edit2.DeleteFile(2, 636);
version_edit.AddFile(2, 806, 0, 100U, GetInternalKey("801"), version_edit.AddFile(2, 806, 0, 100U, GetInternalKey("801"),
GetInternalKey("850"), 200, 200, false, GetInternalKey("850"), 200, 200, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
ASSERT_OK(version_builder.Apply(&version_edit2)); ASSERT_OK(version_builder.Apply(&version_edit2));
ASSERT_OK(version_builder.SaveTo(&new_vstorage)); ASSERT_OK(version_builder.SaveTo(&new_vstorage));
@ -515,10 +517,11 @@ TEST_F(VersionBuilderTest, ApplyFileDeletionAndAddition) {
addition.AddFile(level, file_number, path_id, file_size, addition.AddFile(level, file_number, path_id, file_size,
GetInternalKey(smallest, smallest_seq), GetInternalKey(smallest, smallest_seq),
GetInternalKey(largest, largest_seq), smallest_seqno, GetInternalKey(largest, largest_seq), smallest_seqno,
largest_seqno, marked_for_compaction, kInvalidBlobFileNumber, largest_seqno, marked_for_compaction, Temperature::kUnknown,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kInvalidBlobFileNumber, kUnknownOldestAncesterTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileCreationTime, kUnknownFileChecksum,
kDisableUserTimestamp, kDisableUserTimestamp); kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp);
ASSERT_OK(builder.Apply(&addition)); ASSERT_OK(builder.Apply(&addition));
@ -560,10 +563,10 @@ TEST_F(VersionBuilderTest, ApplyFileAdditionAlreadyInBase) {
edit.AddFile(new_level, file_number, path_id, file_size, edit.AddFile(new_level, file_number, path_id, file_size,
GetInternalKey(smallest), GetInternalKey(largest), GetInternalKey(smallest), GetInternalKey(largest),
smallest_seqno, largest_seqno, marked_for_compaction, smallest_seqno, largest_seqno, marked_for_compaction,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
const Status s = builder.Apply(&edit); const Status s = builder.Apply(&edit);
ASSERT_TRUE(s.IsCorruption()); ASSERT_TRUE(s.IsCorruption());
@ -594,10 +597,11 @@ TEST_F(VersionBuilderTest, ApplyFileAdditionAlreadyApplied) {
edit.AddFile(level, file_number, path_id, file_size, GetInternalKey(smallest), edit.AddFile(level, file_number, path_id, file_size, GetInternalKey(smallest),
GetInternalKey(largest), smallest_seqno, largest_seqno, GetInternalKey(largest), smallest_seqno, largest_seqno,
marked_for_compaction, kInvalidBlobFileNumber, marked_for_compaction, Temperature::kUnknown,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kInvalidBlobFileNumber, kUnknownOldestAncesterTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileCreationTime, kUnknownFileChecksum,
kDisableUserTimestamp, kDisableUserTimestamp); kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp);
ASSERT_OK(builder.Apply(&edit)); ASSERT_OK(builder.Apply(&edit));
@ -608,10 +612,10 @@ TEST_F(VersionBuilderTest, ApplyFileAdditionAlreadyApplied) {
other_edit.AddFile(new_level, file_number, path_id, file_size, other_edit.AddFile(new_level, file_number, path_id, file_size,
GetInternalKey(smallest), GetInternalKey(largest), GetInternalKey(smallest), GetInternalKey(largest),
smallest_seqno, largest_seqno, marked_for_compaction, smallest_seqno, largest_seqno, marked_for_compaction,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
const Status s = builder.Apply(&other_edit); const Status s = builder.Apply(&other_edit);
ASSERT_TRUE(s.IsCorruption()); ASSERT_TRUE(s.IsCorruption());
@ -643,10 +647,10 @@ TEST_F(VersionBuilderTest, ApplyFileAdditionAndDeletion) {
addition.AddFile(level, file_number, path_id, file_size, addition.AddFile(level, file_number, path_id, file_size,
GetInternalKey(smallest), GetInternalKey(largest), GetInternalKey(smallest), GetInternalKey(largest),
smallest_seqno, largest_seqno, marked_for_compaction, smallest_seqno, largest_seqno, marked_for_compaction,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
ASSERT_OK(builder.Apply(&addition)); ASSERT_OK(builder.Apply(&addition));
@ -1172,12 +1176,12 @@ TEST_F(VersionBuilderTest, SaveBlobFilesToConcurrentJobs) {
constexpr uint64_t total_blob_count = 234; constexpr uint64_t total_blob_count = 234;
constexpr uint64_t total_blob_bytes = 1 << 22; constexpr uint64_t total_blob_bytes = 1 << 22;
edit.AddFile(level, table_file_number, path_id, file_size, edit.AddFile(
GetInternalKey(smallest), GetInternalKey(largest), level, table_file_number, path_id, file_size, GetInternalKey(smallest),
smallest_seqno, largest_seqno, marked_for_compaction, GetInternalKey(largest), smallest_seqno, largest_seqno,
blob_file_number, kUnknownOldestAncesterTime, marked_for_compaction, Temperature::kUnknown, blob_file_number,
kUnknownFileCreationTime, checksum_value, checksum_method, kUnknownOldestAncesterTime, kUnknownFileCreationTime, checksum_value,
kDisableUserTimestamp, kDisableUserTimestamp); checksum_method, kDisableUserTimestamp, kDisableUserTimestamp);
edit.AddBlobFile(blob_file_number, total_blob_count, total_blob_bytes, edit.AddBlobFile(blob_file_number, total_blob_count, total_blob_bytes,
checksum_method, checksum_value); checksum_method, checksum_value);
@ -1259,6 +1263,7 @@ TEST_F(VersionBuilderTest, CheckConsistencyForBlobFiles) {
/* file_size */ 100, /* smallest */ GetInternalKey("701"), /* file_size */ 100, /* smallest */ GetInternalKey("701"),
/* largest */ GetInternalKey("750"), /* smallest_seqno */ 200, /* largest */ GetInternalKey("750"), /* smallest_seqno */ 200,
/* largest_seqno */ 200, /* marked_for_compaction */ false, /* largest_seqno */ 200, /* marked_for_compaction */ false,
Temperature::kUnknown,
/* oldest_blob_file_number */ 16, kUnknownOldestAncesterTime, /* oldest_blob_file_number */ 16, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,
@ -1268,6 +1273,7 @@ TEST_F(VersionBuilderTest, CheckConsistencyForBlobFiles) {
/* file_size */ 100, /* smallest */ GetInternalKey("801"), /* file_size */ 100, /* smallest */ GetInternalKey("801"),
/* largest */ GetInternalKey("850"), /* smallest_seqno */ 200, /* largest */ GetInternalKey("850"), /* smallest_seqno */ 200,
/* largest_seqno */ 200, /* marked_for_compaction */ false, /* largest_seqno */ 200, /* marked_for_compaction */ false,
Temperature::kUnknown,
/* oldest_blob_file_number */ 1000, kUnknownOldestAncesterTime, /* oldest_blob_file_number */ 1000, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,
@ -1487,6 +1493,7 @@ TEST_F(VersionBuilderTest, MaintainLinkedSstsForBlobFiles) {
/* file_size */ 100, /* smallest */ GetInternalKey("21", 2100), /* file_size */ 100, /* smallest */ GetInternalKey("21", 2100),
/* largest */ GetInternalKey("21", 2100), /* smallest_seqno */ 2100, /* largest */ GetInternalKey("21", 2100), /* smallest_seqno */ 2100,
/* largest_seqno */ 2100, /* marked_for_compaction */ false, /* largest_seqno */ 2100, /* marked_for_compaction */ false,
Temperature::kUnknown,
/* oldest_blob_file_number */ 1, kUnknownOldestAncesterTime, /* oldest_blob_file_number */ 1, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,
@ -1498,7 +1505,7 @@ TEST_F(VersionBuilderTest, MaintainLinkedSstsForBlobFiles) {
/* file_size */ 100, /* smallest */ GetInternalKey("22", 2200), /* file_size */ 100, /* smallest */ GetInternalKey("22", 2200),
/* largest */ GetInternalKey("22", 2200), /* smallest_seqno */ 2200, /* largest */ GetInternalKey("22", 2200), /* smallest_seqno */ 2200,
/* largest_seqno */ 2200, /* marked_for_compaction */ false, /* largest_seqno */ 2200, /* marked_for_compaction */ false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp); kDisableUserTimestamp);
@ -1521,6 +1528,7 @@ TEST_F(VersionBuilderTest, MaintainLinkedSstsForBlobFiles) {
/* largest */ GetInternalKey("03", 300), /* largest */ GetInternalKey("03", 300),
/* smallest_seqno */ 300, /* smallest_seqno */ 300,
/* largest_seqno */ 300, /* marked_for_compaction */ false, /* largest_seqno */ 300, /* marked_for_compaction */ false,
Temperature::kUnknown,
/* oldest_blob_file_number */ 3, kUnknownOldestAncesterTime, /* oldest_blob_file_number */ 3, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,
@ -1533,10 +1541,10 @@ TEST_F(VersionBuilderTest, MaintainLinkedSstsForBlobFiles) {
/* largest */ GetInternalKey("13", 1300), /* largest */ GetInternalKey("13", 1300),
/* smallest_seqno */ 1300, /* smallest_seqno */ 1300,
/* largest_seqno */ 1300, /* marked_for_compaction */ false, /* largest_seqno */ 1300, /* marked_for_compaction */ false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
// Add one more SST file that references a blob file, then promptly // Add one more SST file that references a blob file, then promptly
// delete it in a second version edit before the new version gets saved. // delete it in a second version edit before the new version gets saved.
@ -1546,6 +1554,7 @@ TEST_F(VersionBuilderTest, MaintainLinkedSstsForBlobFiles) {
/* largest */ GetInternalKey("23", 2300), /* largest */ GetInternalKey("23", 2300),
/* smallest_seqno */ 2300, /* smallest_seqno */ 2300,
/* largest_seqno */ 2300, /* marked_for_compaction */ false, /* largest_seqno */ 2300, /* marked_for_compaction */ false,
Temperature::kUnknown,
/* oldest_blob_file_number */ 5, kUnknownOldestAncesterTime, /* oldest_blob_file_number */ 5, kUnknownOldestAncesterTime,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownFileCreationTime, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksumFuncName, kDisableUserTimestamp,

View File

@ -19,6 +19,7 @@
#include "db/dbformat.h" #include "db/dbformat.h"
#include "db/wal_edit.h" #include "db/wal_edit.h"
#include "memory/arena.h" #include "memory/arena.h"
#include "rocksdb/advanced_options.h"
#include "rocksdb/cache.h" #include "rocksdb/cache.h"
#include "table/table_reader.h" #include "table/table_reader.h"
#include "util/autovector.h" #include "util/autovector.h"
@ -222,14 +223,16 @@ struct FileMetaData {
const InternalKey& smallest_key, const InternalKey& largest_key, const InternalKey& smallest_key, const InternalKey& largest_key,
const SequenceNumber& smallest_seq, const SequenceNumber& smallest_seq,
const SequenceNumber& largest_seq, bool marked_for_compact, const SequenceNumber& largest_seq, bool marked_for_compact,
uint64_t oldest_blob_file, uint64_t _oldest_ancester_time, Temperature _temperature, uint64_t oldest_blob_file,
uint64_t _file_creation_time, const std::string& _file_checksum, uint64_t _oldest_ancester_time, uint64_t _file_creation_time,
const std::string& _file_checksum,
const std::string& _file_checksum_func_name, const std::string& _file_checksum_func_name,
std::string _min_timestamp, std::string _max_timestamp) std::string _min_timestamp, std::string _max_timestamp)
: fd(file, file_path_id, file_size, smallest_seq, largest_seq), : fd(file, file_path_id, file_size, smallest_seq, largest_seq),
smallest(smallest_key), smallest(smallest_key),
largest(largest_key), largest(largest_key),
marked_for_compaction(marked_for_compact), marked_for_compaction(marked_for_compact),
temperature(_temperature),
oldest_blob_file_number(oldest_blob_file), oldest_blob_file_number(oldest_blob_file),
oldest_ancester_time(_oldest_ancester_time), oldest_ancester_time(_oldest_ancester_time),
file_creation_time(_file_creation_time), file_creation_time(_file_creation_time),
@ -401,8 +404,9 @@ class VersionEdit {
uint64_t file_size, const InternalKey& smallest, uint64_t file_size, const InternalKey& smallest,
const InternalKey& largest, const SequenceNumber& smallest_seqno, const InternalKey& largest, const SequenceNumber& smallest_seqno,
const SequenceNumber& largest_seqno, bool marked_for_compaction, const SequenceNumber& largest_seqno, bool marked_for_compaction,
uint64_t oldest_blob_file_number, uint64_t oldest_ancester_time, Temperature temperature, uint64_t oldest_blob_file_number,
uint64_t file_creation_time, const std::string& file_checksum, uint64_t oldest_ancester_time, uint64_t file_creation_time,
const std::string& file_checksum,
const std::string& file_checksum_func_name, const std::string& file_checksum_func_name,
const std::string& min_timestamp, const std::string& min_timestamp,
const std::string& max_timestamp) { const std::string& max_timestamp) {
@ -411,7 +415,7 @@ class VersionEdit {
level, level,
FileMetaData(file, file_path_id, file_size, smallest, largest, FileMetaData(file, file_path_id, file_size, smallest, largest,
smallest_seqno, largest_seqno, marked_for_compaction, smallest_seqno, largest_seqno, marked_for_compaction,
oldest_blob_file_number, oldest_ancester_time, temperature, oldest_blob_file_number, oldest_ancester_time,
file_creation_time, file_checksum, file_checksum_func_name, file_creation_time, file_checksum, file_checksum_func_name,
min_timestamp, max_timestamp)); min_timestamp, max_timestamp));
} }

View File

@ -9,6 +9,7 @@
#include "db/version_edit.h" #include "db/version_edit.h"
#include "rocksdb/advanced_options.h"
#include "test_util/sync_point.h" #include "test_util/sync_point.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
#include "test_util/testutil.h" #include "test_util/testutil.h"
@ -39,8 +40,9 @@ TEST_F(VersionEditTest, EncodeDecode) {
edit.AddFile(3, kBig + 300 + i, kBig32Bit + 400 + i, 0, edit.AddFile(3, kBig + 300 + i, kBig32Bit + 400 + i, 0,
InternalKey("foo", kBig + 500 + i, kTypeValue), InternalKey("foo", kBig + 500 + i, kTypeValue),
InternalKey("zoo", kBig + 600 + i, kTypeDeletion), InternalKey("zoo", kBig + 600 + i, kTypeDeletion),
kBig + 500 + i, kBig + 600 + i, false, kInvalidBlobFileNumber, kBig + 500 + i, kBig + 600 + i, false, Temperature::kUnknown,
888, 678, "234", "crc32c", "123", "345"); kInvalidBlobFileNumber, 888, 678, "234", "crc32c", "123",
"345");
edit.DeleteFile(4, kBig + 700 + i); edit.DeleteFile(4, kBig + 700 + i);
} }
@ -57,26 +59,27 @@ TEST_F(VersionEditTest, EncodeDecodeNewFile4) {
VersionEdit edit; VersionEdit edit;
edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue), edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue),
InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500, InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500,
kBig + 600, true, kInvalidBlobFileNumber, kBig + 600, true, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, "123", kUnknownFileChecksum, kUnknownFileChecksumFuncName, "123",
"234"); "234");
edit.AddFile(4, 301, 3, 100, InternalKey("foo", kBig + 501, kTypeValue), edit.AddFile(4, 301, 3, 100, InternalKey("foo", kBig + 501, kTypeValue),
InternalKey("zoo", kBig + 601, kTypeDeletion), kBig + 501, InternalKey("zoo", kBig + 601, kTypeDeletion), kBig + 501,
kBig + 601, false, kInvalidBlobFileNumber, kBig + 601, false, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, "345", kUnknownFileChecksum, kUnknownFileChecksumFuncName, "345",
"543"); "543");
edit.AddFile(5, 302, 0, 100, InternalKey("foo", kBig + 502, kTypeValue), edit.AddFile(5, 302, 0, 100, InternalKey("foo", kBig + 502, kTypeValue),
InternalKey("zoo", kBig + 602, kTypeDeletion), kBig + 502, InternalKey("zoo", kBig + 602, kTypeDeletion), kBig + 502,
kBig + 602, true, kInvalidBlobFileNumber, 666, 888, kBig + 602, true, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, "456", 666, 888, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
"567"); "456", "567");
edit.AddFile(5, 303, 0, 100, InternalKey("foo", kBig + 503, kTypeBlobIndex), edit.AddFile(5, 303, 0, 100, InternalKey("foo", kBig + 503, kTypeBlobIndex),
InternalKey("zoo", kBig + 603, kTypeBlobIndex), kBig + 503, InternalKey("zoo", kBig + 603, kTypeBlobIndex), kBig + 503,
kBig + 603, true, 1001, kUnknownOldestAncesterTime, kBig + 603, true, Temperature::kUnknown, 1001,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, "678", "789"); kUnknownFileChecksum, kUnknownFileChecksumFuncName, "678",
"789");
; ;
edit.DeleteFile(4, 700); edit.DeleteFile(4, 700);
@ -123,14 +126,15 @@ TEST_F(VersionEditTest, ForwardCompatibleNewFile4) {
VersionEdit edit; VersionEdit edit;
edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue), edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue),
InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500, InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500,
kBig + 600, true, kInvalidBlobFileNumber, kBig + 600, true, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, "123", kUnknownFileChecksum, kUnknownFileChecksumFuncName, "123",
"234"); "234");
edit.AddFile(4, 301, 3, 100, InternalKey("foo", kBig + 501, kTypeValue), edit.AddFile(4, 301, 3, 100, InternalKey("foo", kBig + 501, kTypeValue),
InternalKey("zoo", kBig + 601, kTypeDeletion), kBig + 501, InternalKey("zoo", kBig + 601, kTypeDeletion), kBig + 501,
kBig + 601, false, kInvalidBlobFileNumber, 686, 868, "234", kBig + 601, false, Temperature::kUnknown, kInvalidBlobFileNumber,
"crc32c", kDisableUserTimestamp, kDisableUserTimestamp); 686, 868, "234", "crc32c", kDisableUserTimestamp,
kDisableUserTimestamp);
edit.DeleteFile(4, 700); edit.DeleteFile(4, 700);
edit.SetComparatorName("foo"); edit.SetComparatorName("foo");
@ -180,7 +184,7 @@ TEST_F(VersionEditTest, NewFile4NotSupportedField) {
VersionEdit edit; VersionEdit edit;
edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue), edit.AddFile(3, 300, 3, 100, InternalKey("foo", kBig + 500, kTypeValue),
InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500, InternalKey("zoo", kBig + 600, kTypeDeletion), kBig + 500,
kBig + 600, true, kInvalidBlobFileNumber, kBig + 600, true, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp, kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
@ -211,10 +215,10 @@ TEST_F(VersionEditTest, NewFile4NotSupportedField) {
TEST_F(VersionEditTest, EncodeEmptyFile) { TEST_F(VersionEditTest, EncodeEmptyFile) {
VersionEdit edit; VersionEdit edit;
edit.AddFile(0, 0, 0, 0, InternalKey(), InternalKey(), 0, 0, false, edit.AddFile(0, 0, 0, 0, InternalKey(), InternalKey(), 0, 0, false,
kInvalidBlobFileNumber, kUnknownOldestAncesterTime, Temperature::kUnknown, kInvalidBlobFileNumber,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
std::string buffer; std::string buffer;
ASSERT_TRUE(!edit.EncodeTo(&buffer)); ASSERT_TRUE(!edit.EncodeTo(&buffer));
} }

View File

@ -5385,13 +5385,13 @@ Status VersionSet::WriteCurrentStateToManifest(
for (int level = 0; level < cfd->NumberLevels(); level++) { for (int level = 0; level < cfd->NumberLevels(); level++) {
for (const auto& f : for (const auto& f :
cfd->current()->storage_info()->LevelFiles(level)) { cfd->current()->storage_info()->LevelFiles(level)) {
edit.AddFile(level, f->fd.GetNumber(), f->fd.GetPathId(), edit.AddFile(
f->fd.GetFileSize(), f->smallest, f->largest, level, f->fd.GetNumber(), f->fd.GetPathId(), f->fd.GetFileSize(),
f->fd.smallest_seqno, f->fd.largest_seqno, f->smallest, f->largest, f->fd.smallest_seqno,
f->marked_for_compaction, f->oldest_blob_file_number, f->fd.largest_seqno, f->marked_for_compaction, f->temperature,
f->oldest_ancester_time, f->file_creation_time, f->oldest_blob_file_number, f->oldest_ancester_time,
f->file_checksum, f->file_checksum_func_name, f->file_creation_time, f->file_checksum,
f->min_timestamp, f->max_timestamp); f->file_checksum_func_name, f->min_timestamp, f->max_timestamp);
} }
} }

View File

@ -13,6 +13,7 @@
#include "db/db_impl/db_impl.h" #include "db/db_impl/db_impl.h"
#include "db/log_writer.h" #include "db/log_writer.h"
#include "rocksdb/advanced_options.h"
#include "rocksdb/convenience.h" #include "rocksdb/convenience.h"
#include "rocksdb/file_system.h" #include "rocksdb/file_system.h"
#include "table/block_based/block_based_table_factory.h" #include "table/block_based/block_based_table_factory.h"
@ -44,10 +45,11 @@ class GenerateLevelFilesBriefTest : public testing::Test {
files_.size() + 1, 0, 0, files_.size() + 1, 0, 0,
InternalKey(smallest, smallest_seq, kTypeValue), InternalKey(smallest, smallest_seq, kTypeValue),
InternalKey(largest, largest_seq, kTypeValue), smallest_seq, InternalKey(largest, largest_seq, kTypeValue), smallest_seq,
largest_seq, /* marked_for_compact */ false, kInvalidBlobFileNumber, largest_seq, /* marked_for_compact */ false, Temperature::kUnknown,
kUnknownOldestAncesterTime, kUnknownFileCreationTime, kInvalidBlobFileNumber, kUnknownOldestAncesterTime,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileCreationTime, kUnknownFileChecksum,
kDisableUserTimestamp, kDisableUserTimestamp); kUnknownFileChecksumFuncName, kDisableUserTimestamp,
kDisableUserTimestamp);
files_.push_back(f); files_.push_back(f);
} }
@ -153,10 +155,10 @@ class VersionStorageInfoTestBase : public testing::Test {
FileMetaData* f = new FileMetaData( FileMetaData* f = new FileMetaData(
file_number, 0, file_size, smallest, largest, /* smallest_seq */ 0, file_number, 0, file_size, smallest, largest, /* smallest_seq */ 0,
/* largest_seq */ 0, /* marked_for_compact */ false, /* largest_seq */ 0, /* marked_for_compact */ false,
oldest_blob_file_number, kUnknownOldestAncesterTime, Temperature::kUnknown, oldest_blob_file_number,
kUnknownFileCreationTime, kUnknownFileChecksum, kUnknownOldestAncesterTime, kUnknownFileCreationTime,
kUnknownFileChecksumFuncName, kDisableUserTimestamp, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
f->compensated_file_size = file_size; f->compensated_file_size = file_size;
vstorage_.AddFile(level, f); vstorage_.AddFile(level, f);
} }
@ -2997,7 +2999,8 @@ class VersionSetTestMissingFiles : public VersionSetTestBase,
ASSERT_OK(s); ASSERT_OK(s);
ASSERT_NE(0, file_size); ASSERT_NE(0, file_size);
file_metas->emplace_back(file_num, /*file_path_id=*/0, file_size, ikey, file_metas->emplace_back(file_num, /*file_path_id=*/0, file_size, ikey,
ikey, 0, 0, false, 0, 0, 0, kUnknownFileChecksum, ikey, 0, 0, false, Temperature::kUnknown, 0, 0,
0, kUnknownFileChecksum,
kUnknownFileChecksumFuncName, kUnknownFileChecksumFuncName,
kDisableUserTimestamp, kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
} }
@ -3051,11 +3054,11 @@ TEST_F(VersionSetTestMissingFiles, ManifestFarBehindSst) {
std::string largest_ukey = "b"; std::string largest_ukey = "b";
InternalKey smallest_ikey(smallest_ukey, 1, ValueType::kTypeValue); InternalKey smallest_ikey(smallest_ukey, 1, ValueType::kTypeValue);
InternalKey largest_ikey(largest_ukey, 1, ValueType::kTypeValue); InternalKey largest_ikey(largest_ukey, 1, ValueType::kTypeValue);
FileMetaData meta = FileMetaData meta = FileMetaData(
FileMetaData(file_num, /*file_path_id=*/0, /*file_size=*/12, file_num, /*file_path_id=*/0, /*file_size=*/12, smallest_ikey,
smallest_ikey, largest_ikey, 0, 0, false, 0, 0, 0, largest_ikey, 0, 0, false, Temperature::kUnknown, 0, 0, 0,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp, kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
added_files.emplace_back(0, meta); added_files.emplace_back(0, meta);
} }
WriteFileAdditionAndDeletionToManifest( WriteFileAdditionAndDeletionToManifest(
@ -3107,11 +3110,11 @@ TEST_F(VersionSetTestMissingFiles, ManifestAheadofSst) {
std::string largest_ukey = "b"; std::string largest_ukey = "b";
InternalKey smallest_ikey(smallest_ukey, 1, ValueType::kTypeValue); InternalKey smallest_ikey(smallest_ukey, 1, ValueType::kTypeValue);
InternalKey largest_ikey(largest_ukey, 1, ValueType::kTypeValue); InternalKey largest_ikey(largest_ukey, 1, ValueType::kTypeValue);
FileMetaData meta = FileMetaData meta = FileMetaData(
FileMetaData(file_num, /*file_path_id=*/0, /*file_size=*/12, file_num, /*file_path_id=*/0, /*file_size=*/12, smallest_ikey,
smallest_ikey, largest_ikey, 0, 0, false, 0, 0, 0, largest_ikey, 0, 0, false, Temperature::kUnknown, 0, 0, 0,
kUnknownFileChecksum, kUnknownFileChecksumFuncName, kUnknownFileChecksum, kUnknownFileChecksumFuncName,
kDisableUserTimestamp, kDisableUserTimestamp); kDisableUserTimestamp, kDisableUserTimestamp);
added_files.emplace_back(0, meta); added_files.emplace_back(0, meta);
} }
WriteFileAdditionAndDeletionToManifest( WriteFileAdditionAndDeletionToManifest(

View File

@ -79,6 +79,7 @@ IOStatus SimulatedHybridFileSystem::NewRandomAccessFile(
temperature = Temperature::kWarm; temperature = Temperature::kWarm;
} }
} }
assert(temperature == file_opts.temperature);
IOStatus s = target()->NewRandomAccessFile(fname, file_opts, result, dbg); IOStatus s = target()->NewRandomAccessFile(fname, file_opts, result, dbg);
result->reset( result->reset(
new SimulatedHybridRaf(std::move(*result), rate_limiter_, temperature)); new SimulatedHybridRaf(std::move(*result), rate_limiter_, temperature));