// vast majority of all files), we'll pass the size to SstFileManager.
// For all other files SstFileManager will query the size from filesystem.
- std::vector<LiveFileMetaData> metadata;
-
- // TODO: Once GetLiveFilesMetaData supports blob files, update the logic
- // below to get known_file_sizes for blob files.
- impl->mutex_.Lock();
- impl->versions_->GetLiveFilesMetaData(&metadata);
- impl->mutex_.Unlock();
+ std::vector<ColumnFamilyMetaData> metadata;
+ impl->GetAllColumnFamilyMetaData(&metadata);
std::unordered_map<std::string, uint64_t> known_file_sizes;
for (const auto& md : metadata) {
- std::string name = md.name;
- if (!name.empty() && name[0] == '/') {
- name = name.substr(1);
+ for (const auto& lmd : md.levels) {
+ for (const auto& fmd : lmd.files) {
+ known_file_sizes[fmd.relative_filename] = fmd.size;
+ }
+ }
+ for (const auto& bmd : md.blob_files) {
+ std::string name = bmd.blob_file_name;
+ // The BlobMetaData.blob_file_name may start with "/".
+ if (!name.empty() && name[0] == '/') {
+ name = name.substr(1);
+ }
+ known_file_sizes[name] = bmd.blob_file_size;
}
- known_file_sizes[name] = md.size;
}
std::vector<std::string> paths;
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "db/db_test_util.h"
+#include "env/mock_env.h"
#include "file/sst_file_manager_impl.h"
#include "port/port.h"
#include "port/stack_trace.h"
ASSERT_NOK(env_->FileExists(dbname_ + "/" + "003.sst.trash"));
}
-
// Create a DB with 2 db_paths, and generate multiple files in the 2
// db_paths using CompactRangeOptions, make sure that files that were
// deleted from first db_path were deleted using DeleteScheduler and
ASSERT_GT(completed_compactions, 0);
ASSERT_EQ(sfm->GetCompactionsReservedSize(), 0);
// Make sure the stat is bumped
- ASSERT_GT(dbfull()->immutable_db_options().statistics.get()->getTickerCount(COMPACTION_CANCELLED), 0);
+ ASSERT_GT(dbfull()->immutable_db_options().statistics.get()->getTickerCount(
+ COMPACTION_CANCELLED),
+ 0);
ASSERT_EQ(0,
dbfull()->immutable_db_options().statistics.get()->getTickerCount(
FILES_MARKED_TRASH));
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
}
+TEST_F(DBSSTTest, OpenDBWithoutGetFileSizeInvocations) {
+ Options options = CurrentOptions();
+ std::unique_ptr<MockEnv> env{MockEnv::Create(Env::Default())};
+ options.env = env.get();
+ options.disable_auto_compactions = true;
+ options.compression = kNoCompression;
+ options.enable_blob_files = true;
+ options.blob_file_size = 32; // create one blob per file
+ options.skip_checking_sst_file_sizes_on_db_open = true;
+
+ DestroyAndReopen(options);
+ // Generate 5 files in L0
+ for (int i = 0; i < 5; i++) {
+ for (int j = 0; j < 10; j++) {
+ std::string val = "val_file_" + std::to_string(i);
+ ASSERT_OK(Put(Key(j), val));
+ }
+ ASSERT_OK(Flush());
+ }
+ Close();
+
+ bool is_get_file_size_called = false;
+ SyncPoint::GetInstance()->SetCallBack(
+ "MockFileSystem::GetFileSize:CheckFileType", [&](void* arg) {
+ std::string* filename = reinterpret_cast<std::string*>(arg);
+ if (filename->find(".blob") != std::string::npos) {
+ is_get_file_size_called = true;
+ }
+ });
+
+ SyncPoint::GetInstance()->EnableProcessing();
+ Reopen(options);
+ ASSERT_FALSE(is_get_file_size_called);
+ SyncPoint::GetInstance()->DisableProcessing();
+ SyncPoint::GetInstance()->ClearAllCallBacks();
+
+ Destroy(options);
+}
+
TEST_F(DBSSTTest, GetTotalSstFilesSizeVersionsFilesShared) {
Options options = CurrentOptions();
options.disable_auto_compactions = true;