@@ -97,6 +97,11 @@ class DBImpl : public DB {
9797 friend class DBTable ;
9898 struct CompactionState ;
9999 struct Writer ;
100+ struct CompactionTask {
101+ int64_t id;
102+ double score;
103+ DBImpl* db;
104+ };
100105
101106 Iterator* NewInternalIterator (const ReadOptions&,
102107 SequenceNumber* latest_snapshot);
@@ -111,10 +116,10 @@ class DBImpl : public DB {
111116
112117 // Compact the in-memory write buffer to disk. Switches to a new
113118 // log-file/memtable and writes a new descriptor iff successful.
114- Status CompactMemTable ()
119+ Status CompactMemTable (bool * sched_idle = NULL )
115120 EXCLUSIVE_LOCKS_REQUIRED(mutex_);
116121
117- Status WriteLevel0Table (MemTable* mem, VersionEdit* edit, Version* base)
122+ Status WriteLevel0Table (MemTable* mem, VersionEdit* edit, Version* base, uint64_t * number = NULL )
118123 EXCLUSIVE_LOCKS_REQUIRED(mutex_);
119124
120125 Status MakeRoomForWrite (bool force /* compact even if there is room? */ )
@@ -123,8 +128,8 @@ class DBImpl : public DB {
123128
124129 void MaybeScheduleCompaction () EXCLUSIVE_LOCKS_REQUIRED(mutex_);
125130 static void BGWork (void * db);
126- void BackgroundCall ();
127- Status BackgroundCompaction () EXCLUSIVE_LOCKS_REQUIRED(mutex_);
131+ void BackgroundCall (CompactionTask* task );
132+ Status BackgroundCompaction (bool * sched_idle ) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
128133 void CleanupCompaction (CompactionState* compact)
129134 EXCLUSIVE_LOCKS_REQUIRED(mutex_);
130135 Status DoCompactionWork (CompactionState* compact)
@@ -193,17 +198,25 @@ class DBImpl : public DB {
193198 std::set<uint64_t > pending_outputs_;
194199
195200 // Has a background compaction been scheduled or is running?
196- bool bg_compaction_scheduled_;
197- double bg_compaction_score_;
198- int64_t bg_schedule_id_;
201+ std::set<CompactionTask*> bg_compaction_tasks_;
202+ int bg_compaction_scheduled_;
203+ std::vector<double > bg_compaction_score_;
204+ std::vector<int64_t > bg_schedule_id_;
199205
200206 // Information for a manual compaction
207+ enum ManualCompactState {
208+ kManualCompactIdle ,
209+ kManualCompactConflict ,
210+ kManualCompactWakeup ,
211+ };
201212 struct ManualCompaction {
202213 int level;
203214 bool done;
215+ bool being_sched;
204216 const InternalKey* begin; // NULL means beginning of key range
205217 const InternalKey* end; // NULL means end of key range
206218 InternalKey tmp_storage; // Used to keep track of compaction progress
219+ int compaction_conflict; // 0 == idle, 1 == conflict, 2 == wake
207220 };
208221 ManualCompaction* manual_compaction_;
209222
0 commit comments