Unverified Commit fc4106d4 authored by yiwu-arbug's avatar yiwu-arbug Committed by GitHub

Fix new CF missing BlobFileSizeCollector (#78)

Summary:
On `CreateColumnFamilies` we should set `BlobFileSizeCollectorFactory`. Fixing it.

Test Plan:
added test
Signed-off-by: 's avatarYi Wu <yiwu@pingcap.com>
parent 10710bb1
...@@ -183,7 +183,7 @@ void BlobFileMeta::FileStateTransit(const FileEvent& event) { ...@@ -183,7 +183,7 @@ void BlobFileMeta::FileStateTransit(const FileEvent& event) {
// normal state after flush completed. // normal state after flush completed.
assert(state_ == FileState::kPendingLSM || assert(state_ == FileState::kPendingLSM ||
state_ == FileState::kPendingGC || state_ == FileState::kNormal || state_ == FileState::kPendingGC || state_ == FileState::kNormal ||
state_ == FileState::kBeingGC); state_ == FileState::kBeingGC || state_ == FileState::kObsolete);
if (state_ == FileState::kPendingLSM) state_ = FileState::kNormal; if (state_ == FileState::kPendingLSM) state_ = FileState::kNormal;
break; break;
case FileEvent::kGCCompleted: case FileEvent::kGCCompleted:
......
...@@ -21,7 +21,6 @@ ColumnFamilyData* BlobGC::GetColumnFamilyData() { ...@@ -21,7 +21,6 @@ ColumnFamilyData* BlobGC::GetColumnFamilyData() {
} }
void BlobGC::AddOutputFile(BlobFileMeta* blob_file) { void BlobGC::AddOutputFile(BlobFileMeta* blob_file) {
blob_file->FileStateTransit(BlobFileMeta::FileEvent::kGCOutput);
outputs_.push_back(blob_file); outputs_.push_back(blob_file);
} }
......
...@@ -486,11 +486,12 @@ Status BlobGCJob::InstallOutputBlobFiles() { ...@@ -486,11 +486,12 @@ Status BlobGCJob::InstallOutputBlobFiles() {
std::unique_ptr<BlobFileHandle>>> std::unique_ptr<BlobFileHandle>>>
files; files;
std::string tmp; std::string tmp;
for (auto& builder : this->blob_file_builders_) { for (auto& builder : blob_file_builders_) {
auto file = std::make_shared<BlobFileMeta>( auto file = std::make_shared<BlobFileMeta>(
builder.first->GetNumber(), builder.first->GetFile()->GetFileSize(), builder.first->GetNumber(), builder.first->GetFile()->GetFileSize(),
0, 0, builder.second->GetSmallestKey(), 0, 0, builder.second->GetSmallestKey(),
builder.second->GetLargestKey()); builder.second->GetLargestKey());
file->FileStateTransit(BlobFileMeta::FileEvent::kGCOutput);
RecordInHistogram(stats_, TitanStats::GC_OUTPUT_FILE_SIZE, RecordInHistogram(stats_, TitanStats::GC_OUTPUT_FILE_SIZE,
file->file_size()); file->file_size());
if (!tmp.empty()) { if (!tmp.empty()) {
...@@ -502,7 +503,7 @@ Status BlobGCJob::InstallOutputBlobFiles() { ...@@ -502,7 +503,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
ROCKS_LOG_BUFFER(log_buffer_, "[%s] output[%s]", ROCKS_LOG_BUFFER(log_buffer_, "[%s] output[%s]",
blob_gc_->column_family_handle()->GetName().c_str(), blob_gc_->column_family_handle()->GetName().c_str(),
tmp.c_str()); tmp.c_str());
s = this->blob_file_manager_->BatchFinishFiles( s = blob_file_manager_->BatchFinishFiles(
blob_gc_->column_family_handle()->GetID(), files); blob_gc_->column_family_handle()->GetID(), files);
if (s.ok()) { if (s.ok()) {
for (auto& file : files) { for (auto& file : files) {
...@@ -512,7 +513,7 @@ Status BlobGCJob::InstallOutputBlobFiles() { ...@@ -512,7 +513,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
} else { } else {
std::vector<std::unique_ptr<BlobFileHandle>> handles; std::vector<std::unique_ptr<BlobFileHandle>> handles;
std::string to_delete_files; std::string to_delete_files;
for (auto& builder : this->blob_file_builders_) { for (auto& builder : blob_file_builders_) {
if (!to_delete_files.empty()) { if (!to_delete_files.empty()) {
to_delete_files.append(" "); to_delete_files.append(" ");
} }
...@@ -524,7 +525,7 @@ Status BlobGCJob::InstallOutputBlobFiles() { ...@@ -524,7 +525,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
"[%s] InstallOutputBlobFiles failed. Delete GC output files: %s", "[%s] InstallOutputBlobFiles failed. Delete GC output files: %s",
blob_gc_->column_family_handle()->GetName().c_str(), blob_gc_->column_family_handle()->GetName().c_str(),
to_delete_files.c_str()); to_delete_files.c_str());
s = this->blob_file_manager_->BatchDeleteFiles(handles); s = blob_file_manager_->BatchDeleteFiles(handles);
} }
return s; return s;
} }
...@@ -532,12 +533,12 @@ Status BlobGCJob::InstallOutputBlobFiles() { ...@@ -532,12 +533,12 @@ Status BlobGCJob::InstallOutputBlobFiles() {
Status BlobGCJob::RewriteValidKeyToLSM() { Status BlobGCJob::RewriteValidKeyToLSM() {
TitanStopWatch sw(env_, metrics_.gc_update_lsm_micros); TitanStopWatch sw(env_, metrics_.gc_update_lsm_micros);
Status s; Status s;
auto* db_impl = reinterpret_cast<DBImpl*>(this->base_db_); auto* db_impl = reinterpret_cast<DBImpl*>(base_db_);
WriteOptions wo; WriteOptions wo;
wo.low_pri = true; wo.low_pri = true;
wo.ignore_missing_column_families = true; wo.ignore_missing_column_families = true;
for (auto& write_batch : this->rewrite_batches_) { for (auto& write_batch : rewrite_batches_) {
if (blob_gc_->GetColumnFamilyData()->IsDropped()) { if (blob_gc_->GetColumnFamilyData()->IsDropped()) {
s = Status::Aborted("Column family drop"); s = Status::Aborted("Column family drop");
break; break;
......
...@@ -349,6 +349,8 @@ Status TitanDBImpl::CreateColumnFamilies( ...@@ -349,6 +349,8 @@ Status TitanDBImpl::CreateColumnFamilies(
db_options_, desc.options, blob_manager_, &mutex_, blob_file_set_.get(), db_options_, desc.options, blob_manager_, &mutex_, blob_file_set_.get(),
stats_.get())); stats_.get()));
options.table_factory = titan_table_factory.back(); options.table_factory = titan_table_factory.back();
options.table_properties_collector_factories.emplace_back(
std::make_shared<BlobFileSizeCollectorFactory>());
base_descs.emplace_back(desc.name, options); base_descs.emplace_back(desc.name, options);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "blob_file_iterator.h" #include "blob_file_iterator.h"
#include "blob_file_reader.h" #include "blob_file_reader.h"
#include "blob_file_size_collector.h"
#include "db_impl.h" #include "db_impl.h"
#include "db_iter.h" #include "db_iter.h"
#include "titan/db.h" #include "titan/db.h"
...@@ -439,6 +440,17 @@ TEST_F(TitanDBTest, IngestExternalFiles) { ...@@ -439,6 +440,17 @@ TEST_F(TitanDBTest, IngestExternalFiles) {
} }
} }
TEST_F(TitanDBTest, NewColumnFamilyHasBlobFileSizeCollector) {
Open();
AddCF("new_cf");
Options opt = db_->GetOptions(cf_handles_.back());
ASSERT_EQ(1, opt.table_properties_collector_factories.size());
std::unique_ptr<BlobFileSizeCollectorFactory> prop_collector_factory(
new BlobFileSizeCollectorFactory());
ASSERT_EQ(std::string(prop_collector_factory->Name()),
std::string(opt.table_properties_collector_factories[0]->Name()));
}
TEST_F(TitanDBTest, DropColumnFamily) { TEST_F(TitanDBTest, DropColumnFamily) {
Open(); Open();
const uint64_t kNumCF = 3; const uint64_t kNumCF = 3;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment