More bug fixed introduced by code cleanup

This commit is contained in:
Igor Canadi 2014-03-12 11:50:10 -07:00
parent b5d6ad69fc
commit 25c8a1a20f
3 changed files with 35 additions and 23 deletions

View File

@ -277,16 +277,25 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname)
} }
DBImpl::~DBImpl() { DBImpl::~DBImpl() {
// only the default CFD is alive at this point mutex_.Lock();
if (default_cf_handle_ != nullptr) { if (flush_on_destroy_) {
auto default_cfd = default_cf_handle_->cfd(); autovector<ColumnFamilyData*> to_delete;
if (flush_on_destroy_ && for (auto cfd : *versions_->GetColumnFamilySet()) {
default_cfd->mem()->GetFirstSequenceNumber() != 0) { if (cfd->mem()->GetFirstSequenceNumber() != 0) {
FlushMemTable(default_cfd, FlushOptions()); cfd->Ref();
mutex_.Unlock();
FlushMemTable(cfd, FlushOptions());
mutex_.Lock();
if (cfd->Unref()) {
to_delete.push_back(cfd);
}
}
}
for (auto cfd : to_delete) {
delete cfd;
} }
} }
mutex_.Lock();
// Wait for background work to finish // Wait for background work to finish
shutting_down_.Release_Store(this); // Any non-nullptr value is ok shutting_down_.Release_Store(this); // Any non-nullptr value is ok
while (bg_compaction_scheduled_ || while (bg_compaction_scheduled_ ||

View File

@ -1998,34 +1998,35 @@ TEST(DBTest, RollLog) {
TEST(DBTest, WAL) { TEST(DBTest, WAL) {
do { do {
CreateAndReopenWithCF({"pikachu"});
WriteOptions writeOpt = WriteOptions(); WriteOptions writeOpt = WriteOptions();
writeOpt.disableWAL = true; writeOpt.disableWAL = true;
ASSERT_OK(dbfull()->Put(writeOpt, "foo", "v1")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "foo", "v1"));
ASSERT_OK(dbfull()->Put(writeOpt, "bar", "v1")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "bar", "v1"));
Reopen(); ReopenWithColumnFamilies({"default", "pikachu"});
ASSERT_EQ("v1", Get("foo")); ASSERT_EQ("v1", Get(1, "foo"));
ASSERT_EQ("v1", Get("bar")); ASSERT_EQ("v1", Get(1, "bar"));
writeOpt.disableWAL = false; writeOpt.disableWAL = false;
ASSERT_OK(dbfull()->Put(writeOpt, "bar", "v2")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "bar", "v2"));
writeOpt.disableWAL = true; writeOpt.disableWAL = true;
ASSERT_OK(dbfull()->Put(writeOpt, "foo", "v2")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "foo", "v2"));
Reopen(); ReopenWithColumnFamilies({"default", "pikachu"});
// Both value's should be present. // Both value's should be present.
ASSERT_EQ("v2", Get("bar")); ASSERT_EQ("v2", Get(1, "bar"));
ASSERT_EQ("v2", Get("foo")); ASSERT_EQ("v2", Get(1, "foo"));
writeOpt.disableWAL = true; writeOpt.disableWAL = true;
ASSERT_OK(dbfull()->Put(writeOpt, "bar", "v3")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "bar", "v3"));
writeOpt.disableWAL = false; writeOpt.disableWAL = false;
ASSERT_OK(dbfull()->Put(writeOpt, "foo", "v3")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "foo", "v3"));
Reopen(); ReopenWithColumnFamilies({"default", "pikachu"});
// again both values should be present. // again both values should be present.
ASSERT_EQ("v3", Get("foo")); ASSERT_EQ("v3", Get(1, "foo"));
ASSERT_EQ("v3", Get("bar")); ASSERT_EQ("v3", Get(1, "bar"));
} while (ChangeCompactOptions()); } while (ChangeCompactOptions());
} }
@ -2130,7 +2131,7 @@ TEST(DBTest, FLUSH) {
ReopenWithColumnFamilies({"default", "pikachu"}); ReopenWithColumnFamilies({"default", "pikachu"});
ASSERT_EQ("v1", Get(1, "foo")); ASSERT_EQ("v1", Get(1, "foo"));
ASSERT_EQ("NOT_FOUND", Get(1, "bar")); ASSERT_EQ("v1", Get(1, "bar"));
writeOpt.disableWAL = true; writeOpt.disableWAL = true;
ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "bar", "v2")); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "bar", "v2"));

View File

@ -721,6 +721,8 @@ TEST(BackupableDBTest, FailOverwritingBackups) {
OpenBackupableDB(true); OpenBackupableDB(true);
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
FillDB(db_.get(), 100 * i, 100 * (i + 1)); FillDB(db_.get(), 100 * i, 100 * (i + 1));
CloseBackupableDB();
OpenBackupableDB(false);
ASSERT_OK(db_->CreateNewBackup(true)); ASSERT_OK(db_->CreateNewBackup(true));
CloseBackupableDB(); CloseBackupableDB();
OpenBackupableDB(false); OpenBackupableDB(false);