Summary: When memtable is full it calls the registered callback. That callback then registers column family as needing the flush. Every write checks if there are some column families that need to be flushed. This completely eliminates the need for MakeRoomForWrite() function and simplifies our Write code-path. There is some complexity with the concurrency when the column family is dropped. I made it a bit less complex by dropping the column family from the write thread in https://reviews.facebook.net/D22965. Let me know if you want to discuss this. Test Plan: make check works. I'll also run db_stress with creating and dropping column families for a while. Reviewers: yhchiang, sdong, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23067main
parent
059e584dd3
commit
3d9e6f7759
@ -0,0 +1,62 @@ |
|||||||
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
#include "db/flush_scheduler.h" |
||||||
|
|
||||||
|
#include <cassert> |
||||||
|
|
||||||
|
#include "db/column_family.h" |
||||||
|
|
||||||
|
namespace rocksdb { |
||||||
|
|
||||||
|
void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) { |
||||||
|
#ifndef NDEBUG |
||||||
|
assert(column_families_set_.find(cfd) == column_families_set_.end()); |
||||||
|
column_families_set_.insert(cfd); |
||||||
|
#endif // NDEBUG
|
||||||
|
cfd->Ref(); |
||||||
|
column_families_.push_back(cfd); |
||||||
|
} |
||||||
|
|
||||||
|
ColumnFamilyData* FlushScheduler::GetNextColumnFamily() { |
||||||
|
ColumnFamilyData* cfd = nullptr; |
||||||
|
while (column_families_.size() > 0) { |
||||||
|
cfd = column_families_.front(); |
||||||
|
column_families_.pop_front(); |
||||||
|
if (cfd->IsDropped()) { |
||||||
|
if (cfd->Unref()) { |
||||||
|
delete cfd; |
||||||
|
} |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
#ifndef NDEBUG |
||||||
|
if (cfd != nullptr) { |
||||||
|
auto itr = column_families_set_.find(cfd); |
||||||
|
assert(itr != column_families_set_.end()); |
||||||
|
column_families_set_.erase(itr); |
||||||
|
} |
||||||
|
#endif // NDEBUG
|
||||||
|
return cfd; |
||||||
|
} |
||||||
|
|
||||||
|
bool FlushScheduler::Empty() { return column_families_.empty(); } |
||||||
|
|
||||||
|
void FlushScheduler::Clear() { |
||||||
|
for (auto cfd : column_families_) { |
||||||
|
#ifndef NDEBUG |
||||||
|
auto itr = column_families_set_.find(cfd); |
||||||
|
assert(itr != column_families_set_.end()); |
||||||
|
column_families_set_.erase(itr); |
||||||
|
#endif // NDEBUG
|
||||||
|
if (cfd->Unref()) { |
||||||
|
delete cfd; |
||||||
|
} |
||||||
|
} |
||||||
|
column_families_.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace rocksdb
|
@ -0,0 +1,39 @@ |
|||||||
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
#include <deque> |
||||||
|
#include <set> |
||||||
|
#include <vector> |
||||||
|
|
||||||
|
namespace rocksdb { |
||||||
|
|
||||||
|
class ColumnFamilyData; |
||||||
|
|
||||||
|
// This class is thread-compatible. It's should only be accessed from single
|
||||||
|
// write thread (between BeginWrite() and EndWrite())
|
||||||
|
class FlushScheduler { |
||||||
|
public: |
||||||
|
FlushScheduler() = default; |
||||||
|
~FlushScheduler() = default; |
||||||
|
|
||||||
|
void ScheduleFlush(ColumnFamilyData* cfd); |
||||||
|
// Returns Ref()-ed column family. Client needs to Unref()
|
||||||
|
ColumnFamilyData* GetNextColumnFamily(); |
||||||
|
|
||||||
|
bool Empty(); |
||||||
|
|
||||||
|
void Clear(); |
||||||
|
|
||||||
|
private: |
||||||
|
std::deque<ColumnFamilyData*> column_families_; |
||||||
|
#ifndef NDEBUG |
||||||
|
std::set<ColumnFamilyData*> column_families_set_; |
||||||
|
#endif // NDEBUG
|
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace rocksdb
|
Loading…
Reference in new issue