|
23 | 23 | import com.apple.foundationdb.FDBError;
|
24 | 24 | import com.apple.foundationdb.FDBException;
|
25 | 25 | import com.apple.foundationdb.MutationType;
|
26 |
| -import com.apple.foundationdb.Range; |
27 | 26 | import com.apple.foundationdb.annotation.API;
|
28 | 27 | import com.apple.foundationdb.async.AsyncUtil;
|
29 | 28 | import com.apple.foundationdb.async.MoreAsyncUtil;
|
|
91 | 90 | @API(API.Status.INTERNAL)
|
92 | 91 | public abstract class IndexingBase {
|
93 | 92 |
|
94 |
| - private static final Object INDEX_BUILD_LOCK_KEY = 0L; |
95 |
| - private static final Object INDEX_BUILD_SCANNED_RECORDS = 1L; |
96 |
| - private static final Object INDEX_BUILD_TYPE_VERSION = 2L; |
97 |
| - private static final Object INDEX_SCRUBBED_INDEX_RANGES = 3L; |
98 |
| - private static final Object INDEX_SCRUBBED_RECORDS_RANGES = 4L; |
99 |
| - |
100 | 93 | @Nonnull
|
101 | 94 | private static final Logger LOGGER = LoggerFactory.getLogger(IndexingBase.class);
|
102 | 95 | @Nonnull
|
@@ -136,38 +129,6 @@ protected FDBDatabaseRunner getRunner() {
|
136 | 129 | return common.getRunner();
|
137 | 130 | }
|
138 | 131 |
|
139 |
| - @Nonnull |
140 |
| - private static Subspace indexBuildSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index, Object key) { |
141 |
| - return store.getUntypedRecordStore().indexBuildSubspace(index).subspace(Tuple.from(key)); |
142 |
| - } |
143 |
| - |
144 |
| - @Nonnull |
145 |
| - protected static Subspace indexBuildLockSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) { |
146 |
| - return indexBuildSubspace(store, index, INDEX_BUILD_LOCK_KEY); |
147 |
| - } |
148 |
| - |
149 |
| - @Nonnull |
150 |
| - protected static Subspace indexBuildScannedRecordsSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) { |
151 |
| - return indexBuildSubspace(store, index, INDEX_BUILD_SCANNED_RECORDS); |
152 |
| - } |
153 |
| - |
154 |
| - @Nonnull |
155 |
| - protected static Subspace indexBuildTypeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) { |
156 |
| - return indexBuildSubspace(store, index, INDEX_BUILD_TYPE_VERSION); |
157 |
| - } |
158 |
| - |
159 |
| - @Nonnull |
160 |
| - public static Subspace indexScrubIndexRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) { |
161 |
| - // This subspace holds the scrubbed ranges of the index itself (when looking for dangling entries) |
162 |
| - return indexBuildSubspace(store, index, INDEX_SCRUBBED_INDEX_RANGES); |
163 |
| - } |
164 |
| - |
165 |
| - @Nonnull |
166 |
| - public static Subspace indexScrubRecordsRangeSubspace(@Nonnull FDBRecordStoreBase<?> store, @Nonnull Index index) { |
167 |
| - // This subspace hods the scrubbed ranges of the records (when looking for missing index entries) |
168 |
| - return indexBuildSubspace(store, index, INDEX_SCRUBBED_RECORDS_RANGES); |
169 |
| - } |
170 |
| - |
171 | 132 | @SuppressWarnings("squid:S1452")
|
172 | 133 | protected CompletableFuture<FDBRecordStore> openRecordStore(@Nonnull FDBRecordContext context) {
|
173 | 134 | return common.getRecordStoreBuilder().copyBuilder().setContext(context).openAsync();
|
@@ -204,7 +165,7 @@ public CompletableFuture<Void> buildIndexAsync(boolean markReadable, boolean use
|
204 | 165 | }
|
205 | 166 | if (useSyncLock) {
|
206 | 167 | buildIndexAsyncFuture = runner
|
207 |
| - .runAsync(context -> openRecordStore(context).thenApply(store -> indexBuildLockSubspace(store, index)), |
| 168 | + .runAsync(context -> openRecordStore(context).thenApply(store -> IndexingSubspaces.indexBuildLockSubspace(store, index)), |
208 | 169 | common.indexLogMessageKeyValues("IndexingBase::indexBuildLockSubspace"))
|
209 | 170 | .thenCompose(lockSubspace -> runner.startSynchronizedSessionAsync(lockSubspace, common.config.getLeaseLengthMillis()))
|
210 | 171 | .thenCompose(synchronizedRunner -> {
|
@@ -517,7 +478,7 @@ private static IndexBuildProto.IndexBuildIndexingStamp blocklessStampOf(IndexBui
|
517 | 478 |
|
518 | 479 | CompletableFuture<Void> throwIfSyncedLock(String otherIndexName, FDBRecordStore store, IndexBuildProto.IndexBuildIndexingStamp newStamp, IndexBuildProto.IndexBuildIndexingStamp savedStamp) {
|
519 | 480 | final Index otherIndex = store.getRecordMetaData().getIndex(otherIndexName);
|
520 |
| - final Subspace mainLockSubspace = indexBuildLockSubspace(store, otherIndex); |
| 481 | + final Subspace mainLockSubspace = IndexingSubspaces.indexBuildLockSubspace(store, otherIndex); |
521 | 482 | return SynchronizedSession.checkActiveSessionExists(store.ensureContextActive(), mainLockSubspace)
|
522 | 483 | .thenApply(hasActiveSession -> {
|
523 | 484 | if (Boolean.TRUE.equals(hasActiveSession)) {
|
@@ -576,44 +537,10 @@ private CompletableFuture<Void> throwUnlessNoRecordWasScanned(boolean noRecordSc
|
576 | 537 | }
|
577 | 538 |
|
578 | 539 | @Nonnull
|
579 |
| - @SuppressWarnings("PMD.CloseResource") |
580 |
| - private CompletableFuture<Void> setScrubberTypeOrThrow(FDBRecordStore store) { |
581 |
| - // HERE: The index must be readable, checked by the caller |
582 |
| - // if scrubber had already run and still have missing ranges, do nothing |
583 |
| - // else: clear ranges and overwrite type-stamp |
584 |
| - IndexBuildProto.IndexBuildIndexingStamp indexingTypeStamp = getIndexingTypeStamp(store); |
585 |
| - validateOrThrowEx(indexingTypeStamp.getMethod().equals(IndexBuildProto.IndexBuildIndexingStamp.Method.SCRUB_REPAIR), |
586 |
| - "Not a scrubber type-stamp"); |
587 |
| - |
588 |
| - final Index index = common.getIndex(); // Note: the scrubbers do not support multi target (yet) |
589 |
| - IndexingRangeSet indexRangeSet = IndexingRangeSet.forScrubbingIndex(store, index); |
590 |
| - IndexingRangeSet recordsRangeSet = IndexingRangeSet.forScrubbingRecords(store, index); |
591 |
| - final CompletableFuture<Range> indexRangeFuture = indexRangeSet.firstMissingRangeAsync(); |
592 |
| - final CompletableFuture<Range> recordRangeFuture = recordsRangeSet.firstMissingRangeAsync(); |
593 |
| - return indexRangeFuture.thenCompose(indexRange -> { |
594 |
| - if (indexRange == null) { |
595 |
| - // Here: no un-scrubbed index range was left for this call. We will |
596 |
| - // erase the 'ranges' data to allow a fresh index re-scrubbing. |
597 |
| - if (LOGGER.isDebugEnabled()) { |
598 |
| - LOGGER.debug(KeyValueLogMessage.build("Reset scrubber's index range") |
599 |
| - .addKeysAndValues(common.indexLogMessageKeyValues()) |
600 |
| - .toString()); |
601 |
| - } |
602 |
| - indexRangeSet.clear(); |
603 |
| - } |
604 |
| - return recordRangeFuture.thenAccept(recordRange -> { |
605 |
| - if (recordRange == null) { |
606 |
| - // Here: no un-scrubbed records range was left for this call. We will |
607 |
| - // erase the 'ranges' data to allow a fresh records re-scrubbing. |
608 |
| - if (LOGGER.isDebugEnabled()) { |
609 |
| - LOGGER.debug(KeyValueLogMessage.build("Reset scrubber's records range") |
610 |
| - .addKeysAndValues(common.indexLogMessageKeyValues()) |
611 |
| - .toString()); |
612 |
| - } |
613 |
| - recordsRangeSet.clear(); |
614 |
| - } |
615 |
| - }); |
616 |
| - }); |
| 540 | + protected CompletableFuture<Void> setScrubberTypeOrThrow(FDBRecordStore store) { |
| 541 | + // This path should never be reached |
| 542 | + throw new ValidationException("Called setScrubberTypeOrThrow in a non-scrubbing path", |
| 543 | + "isScrubber", isScrubber); |
617 | 544 | }
|
618 | 545 |
|
619 | 546 | @Nonnull
|
@@ -792,7 +719,7 @@ protected <T> CompletableFuture<Void> iterateRangeOnly(@Nonnull FDBRecordStore
|
792 | 719 | }
|
793 | 720 | if (common.isTrackProgress()) {
|
794 | 721 | for (Index index: common.getTargetIndexes()) {
|
795 |
| - final Subspace scannedRecordsSubspace = indexBuildScannedRecordsSubspace(store, index); |
| 722 | + final Subspace scannedRecordsSubspace = IndexingSubspaces.indexBuildScannedRecordsSubspace(store, index); |
796 | 723 | store.context.ensureActive().mutate(MutationType.ADD, scannedRecordsSubspace.getKey(),
|
797 | 724 | FDBRecordStore.encodeRecordCount(recordsScannedInTransaction));
|
798 | 725 | }
|
|
0 commit comments