-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue #934: multi-thread compaction support #976
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,12 @@ class DBImpl : public DB { | |
friend class DBTable; | ||
struct CompactionState; | ||
struct Writer; | ||
struct CompactionTask { | ||
int64_t id; // compaction thread id | ||
double score; // compaction score | ||
uint64_t timeout; // compaction task delay time | ||
DBImpl* db; | ||
}; | ||
|
||
Iterator* NewInternalIterator(const ReadOptions&, | ||
SequenceNumber* latest_snapshot); | ||
|
@@ -110,19 +116,19 @@ class DBImpl : public DB { | |
|
||
// Compact the in-memory write buffer to disk. Switches to a new | ||
// log-file/memtable and writes a new descriptor iff successful. | ||
Status CompactMemTable() | ||
Status CompactMemTable(bool* sched_idle = NULL) | ||
EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
|
||
Status WriteLevel0Table(MemTable* mem, VersionEdit* edit, Version* base) | ||
Status WriteLevel0Table(MemTable* mem, VersionEdit* edit, Version* base, uint64_t* number = NULL) | ||
EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
|
||
Status MakeRoomForWrite(bool force /* compact even if there is room? */) | ||
EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
|
||
void MaybeScheduleCompaction() EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
static void BGWork(void* db); | ||
void BackgroundCall(); | ||
Status BackgroundCompaction() EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
void BackgroundCall(CompactionTask* task); | ||
Status BackgroundCompaction(bool* sched_idle) EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
void CleanupCompaction(CompactionState* compact) | ||
EXCLUSIVE_LOCKS_REQUIRED(mutex_); | ||
Status DoCompactionWork(CompactionState* compact) | ||
|
@@ -196,18 +202,24 @@ class DBImpl : public DB { | |
std::set<uint64_t> pending_outputs_; | ||
|
||
// Has a background compaction been scheduled or is running? | ||
bool bg_compaction_scheduled_; | ||
double bg_compaction_score_; | ||
uint64_t bg_compaction_timeout_; | ||
int64_t bg_schedule_id_; | ||
std::vector<CompactionTask*> bg_compaction_tasks_; | ||
std::vector<double> bg_compaction_score_; | ||
std::vector<int64_t> bg_schedule_id_; | ||
|
||
// Information for a manual compaction | ||
enum ManualCompactState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 跪求注释,这几种状态的定义 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已改 |
||
kManualCompactIdle, // manual compact inited | ||
kManualCompactConflict, // manual compact run simultaneously | ||
kManualCompactWakeup, // restart delay compact task | ||
}; | ||
struct ManualCompaction { | ||
int level; | ||
bool done; | ||
bool being_sched; | ||
const InternalKey* begin; // NULL means beginning of key range | ||
const InternalKey* end; // NULL means end of key range | ||
InternalKey tmp_storage; // Used to keep track of compaction progress | ||
ManualCompactState compaction_conflict; // 0 == idle, 1 == conflict, 2 == wake | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compaction_conflict变量命名有点奇怪? 猜不出什么含义? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 就是手动compact并发冲突 |
||
}; | ||
ManualCompaction* manual_compaction_; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,13 @@ class MemTable { | |
empty_ = false; | ||
} | ||
|
||
bool BeingFlushed() { return being_flushed_;} | ||
void SetBeingFlushed(bool flag) { | ||
assert(flag ? !being_flushed_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么要加assert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 放置后续同学改次块代码改错 |
||
: being_flushed_); | ||
being_flushed_ = flag; | ||
} | ||
|
||
virtual ~MemTable(); | ||
|
||
protected: | ||
|
@@ -97,6 +104,7 @@ class MemTable { | |
|
||
KeyComparator comparator_; | ||
int refs_; | ||
bool being_flushed_; | ||
|
||
Arena arena_; | ||
Table table_; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数的参数求注释啊,下同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
描述改函数是否真正干活,避免空调度
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
防止空调度