Skip to content

Commit 2db756d

Browse files
authored
Extra cleanup for the index scrubbing code (#3317)
Resolve #3315 There where leftover requested changes in PR #3298 that are addressed here
1 parent 5fe882c commit 2db756d

File tree

3 files changed

+223
-102
lines changed

3 files changed

+223
-102
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingSubspaces.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,36 @@ public static Subspace indexBuildTypeSubspace(@Nonnull FDBRecordStoreBase<?> sto
9191
* @return subspace
9292
*/
9393
@Nonnull
94-
public static Subspace indexScrubRecordsRangeSubspaceZero(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
94+
private static Subspace indexScrubRecordsRangeSubspaceZero(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
9595
// Backward compatible subspace for range-id zero
9696
return indexBuildSubspace(store, index, INDEX_SCRUBBED_RECORDS_RANGES_ZERO);
9797
}
9898

9999
/**
100-
* Subspace that stores scrubbed records ranges. This subspace is expected to be followed by a range-id.
100+
* Subspace that stores scrubbed records ranges.
101101
* @param store store
102102
* @param index index
103103
* @return subspace
104104
*/
105105
@Nonnull
106-
public static Subspace indexScrubRecordsRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
106+
private static Subspace indexScrubRecordsRangeSubspaceRoot(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
107107
return indexBuildSubspace(store, index, INDEX_SCRUBBED_RECORDS_RANGES);
108108
}
109109

110+
/**
111+
* Subspace that stores scrubbed records ranges.
112+
* @param store store
113+
* @param index index
114+
* @return subspace
115+
*/
116+
@Nonnull
117+
public static Subspace indexScrubRecordsRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index, int rangeId) {
118+
return rangeId == 0 ?
119+
// Backward compatible
120+
IndexingSubspaces.indexScrubRecordsRangeSubspaceZero(store, index) :
121+
IndexingSubspaces.indexScrubRecordsRangeSubspaceRoot(store, index).subspace(Tuple.from(rangeId));
122+
}
123+
110124
/**
111125
* Subspace that stores scrubbed index entries ranges of the zero range-id. This subspace is backward compatible
112126
* to index entries ranges scrubbed before range-id was introduced.
@@ -115,7 +129,7 @@ public static Subspace indexScrubRecordsRangeSubspace(@Nonnull FDBRecordStoreBas
115129
* @return subspace
116130
*/
117131
@Nonnull
118-
public static Subspace indexScrubIndexRangeSubspaceLegacy(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
132+
private static Subspace indexScrubIndexRangeSubspaceZero(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
119133
// Backward compatible subspace for range-id zero
120134
return indexBuildSubspace(store, index, INDEX_SCRUBBED_INDEX_RANGES_ZERO);
121135
}
@@ -127,21 +141,36 @@ public static Subspace indexScrubIndexRangeSubspaceLegacy(@Nonnull FDBRecordStor
127141
* @return subspace
128142
*/
129143
@Nonnull
130-
public static Subspace indexScrubIndexRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
144+
private static Subspace indexScrubIndexRangeSubspaceRoot(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) {
131145
return indexBuildSubspace(store, index, INDEX_SCRUBBED_INDEX_RANGES);
132146
}
133147

148+
/**
149+
* Subspace that stores scrubbed index entries ranges.
150+
* @param store store
151+
* @param index index
152+
* @param rangeId used by the caller to distinct different scrubbing sessions.
153+
* @return subspace
154+
*/
155+
@Nonnull
156+
public static Subspace indexScrubIndexRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index, int rangeId) {
157+
return rangeId == 0 ?
158+
// Backward compatible
159+
IndexingSubspaces.indexScrubIndexRangeSubspaceZero(store, index) :
160+
IndexingSubspaces.indexScrubIndexRangeSubspaceRoot(store, index).subspace(Tuple.from(rangeId));
161+
}
162+
134163
/**
135164
* Erasing all the scrubbing ranges data. After calling this function, there would be no memory of scrubbed ranges.
136165
* @param context user context - the operation will run within this context
137166
* @param store store
138167
* @param index index
139168
*/
140169
public static void eraseAllIndexingScrubbingData(@Nonnull FDBRecordContext context, @Nonnull FDBRecordStore store, @Nonnull Index index) {
141-
context.clear(Range.startsWith(indexScrubIndexRangeSubspaceLegacy(store, index).pack()));
142-
context.clear(Range.startsWith(indexScrubIndexRangeSubspace(store, index).pack()));
170+
context.clear(Range.startsWith(indexScrubIndexRangeSubspaceZero(store, index).pack()));
171+
context.clear(Range.startsWith(indexScrubIndexRangeSubspaceRoot(store, index).pack()));
143172
context.clear(Range.startsWith(indexScrubRecordsRangeSubspaceZero(store, index).pack()));
144-
context.clear(Range.startsWith(indexScrubRecordsRangeSubspace(store, index).pack()));
173+
context.clear(Range.startsWith(indexScrubRecordsRangeSubspaceRoot(store, index).pack()));
145174
}
146175

147176
/**

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/indexing/IndexingRangeSet.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer;
3333
import com.apple.foundationdb.record.provider.foundationdb.IndexingSubspaces;
3434
import com.apple.foundationdb.subspace.Subspace;
35-
import com.apple.foundationdb.tuple.Tuple;
3635

3736
import javax.annotation.Nonnull;
3837
import javax.annotation.Nullable;
@@ -228,13 +227,7 @@ public static IndexingRangeSet forIndexBuild(@Nonnull FDBRecordStore store, @Non
228227
*/
229228
@Nonnull
230229
public static IndexingRangeSet forScrubbingIndex(@Nonnull FDBRecordStore store, @Nonnull Index index, int rangeId) {
231-
final Subspace subspace;
232-
if (rangeId == 0) {
233-
// Backward compatible
234-
subspace = IndexingSubspaces.indexScrubIndexRangeSubspaceLegacy(store, index);
235-
} else {
236-
subspace = IndexingSubspaces.indexScrubIndexRangeSubspace(store, index).subspace(Tuple.from(rangeId));
237-
}
230+
final Subspace subspace = IndexingSubspaces.indexScrubIndexRangeSubspace(store, index, rangeId);
238231
final RangeSet rangeSet = new RangeSet(subspace);
239232
return new IndexingRangeSet(store.getRecordContext(), rangeSet);
240233
}
@@ -251,13 +244,7 @@ public static IndexingRangeSet forScrubbingIndex(@Nonnull FDBRecordStore store,
251244
*/
252245
@Nonnull
253246
public static IndexingRangeSet forScrubbingRecords(@Nonnull FDBRecordStore store, @Nonnull Index index, int rangeId) {
254-
final Subspace subspace;
255-
if (rangeId == 0) {
256-
// Backward compatible
257-
subspace = IndexingSubspaces.indexScrubRecordsRangeSubspaceZero(store, index);
258-
} else {
259-
subspace = IndexingSubspaces.indexScrubRecordsRangeSubspace(store, index).subspace(Tuple.from(rangeId));
260-
}
247+
final Subspace subspace = IndexingSubspaces.indexScrubRecordsRangeSubspace(store, index, rangeId);
261248
final RangeSet rangeSet = new RangeSet(subspace);
262249
return new IndexingRangeSet(store.getRecordContext(), rangeSet);
263250
}

0 commit comments

Comments
 (0)