@@ -132,26 +132,16 @@ void CompactionPicker::GetRange(const std::vector<FileMetaData*>& inputs1,
132
132
GetRange (all, smallest, largest);
133
133
}
134
134
135
- // Add more files to the inputs on "level" to make sure that
136
- // no newer version of a key is compacted to "level+1" while leaving an older
137
- // version in a "level". Otherwise, any Get() will search "level" first,
138
- // and will likely return an old/stale value for the key, since it always
139
- // searches in increasing order of level to find the value. This could
140
- // also scramble the order of merge operands. This function should be
141
- // called any time a new Compaction is created, and its inputs_[0] are
142
- // populated.
143
- //
144
- // Will set c to nullptr if it is impossible to apply this compaction.
145
- void CompactionPicker::ExpandWhileOverlapping (Compaction* c) {
135
+ bool CompactionPicker::ExpandWhileOverlapping (Compaction* c) {
146
136
// If inputs are empty then there is nothing to expand.
147
137
if (!c || c->inputs_ [0 ].empty ()) {
148
- return ;
138
+ return true ;
149
139
}
150
140
151
141
// GetOverlappingInputs will always do the right thing for level-0.
152
142
// So we don't need to do any expansion if level == 0.
153
143
if (c->level () == 0 ) {
154
- return ;
144
+ return true ;
155
145
}
156
146
157
147
const int level = c->level ();
@@ -182,9 +172,9 @@ void CompactionPicker::ExpandWhileOverlapping(Compaction* c) {
182
172
&parent_index))) {
183
173
c->inputs_ [0 ].clear ();
184
174
c->inputs_ [1 ].clear ();
185
- delete c;
186
- c = nullptr ;
175
+ return false ;
187
176
}
177
+ return true ;
188
178
}
189
179
190
180
uint64_t CompactionPicker::ExpandedCompactionByteSizeLimit (int level) {
@@ -341,8 +331,8 @@ Compaction* CompactionPicker::CompactRange(Version* version, int input_level,
341
331
MaxGrandParentOverlapBytes (input_level));
342
332
343
333
c->inputs_ [0 ] = inputs;
344
- ExpandWhileOverlapping (c);
345
- if (c == nullptr ) {
334
+ if ( ExpandWhileOverlapping (c) == false ) {
335
+ delete c;
346
336
Log (options_->info_log , " Could not compact due to expansion failure.\n " );
347
337
return nullptr ;
348
338
}
@@ -383,8 +373,10 @@ Compaction* LevelCompactionPicker::PickCompaction(Version* version) {
383
373
level = version->compaction_level_ [i];
384
374
if ((version->compaction_score_ [i] >= 1 )) {
385
375
c = PickCompactionBySize (version, level, version->compaction_score_ [i]);
386
- ExpandWhileOverlapping (c);
387
- if (c != nullptr ) {
376
+ if (ExpandWhileOverlapping (c) == false ) {
377
+ delete c;
378
+ c = nullptr ;
379
+ } else {
388
380
break ;
389
381
}
390
382
}
@@ -408,7 +400,9 @@ Compaction* LevelCompactionPicker::PickCompaction(Version* version) {
408
400
c->inputs_ [0 ].push_back (f);
409
401
c->parent_index_ = parent_index;
410
402
c->input_version_ ->file_to_compact_ = nullptr ;
411
- ExpandWhileOverlapping (c);
403
+ if (ExpandWhileOverlapping (c) == false ) {
404
+ return nullptr ;
405
+ }
412
406
}
413
407
}
414
408
}
@@ -528,7 +522,7 @@ Compaction* LevelCompactionPicker::PickCompactionBySize(Version* version,
528
522
}
529
523
530
524
// store where to start the iteration in the next call to PickCompaction
531
- c-> input_version_ ->next_file_to_compact_by_size_ [level] = nextIndex;
525
+ version ->next_file_to_compact_by_size_ [level] = nextIndex;
532
526
533
527
return c;
534
528
}
0 commit comments