-
Notifications
You must be signed in to change notification settings - Fork 119
Allow leaving corrupted indexes as readable after header repair #3801
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
Open
ScottDugas
wants to merge
8
commits into
FoundationDB:main
Choose a base branch
from
ScottDugas:repair-store-without-disable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+305
−119
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ff6e03
Allow leaving corrupted indexes as readable after header repair
ScottDugas 1197739
Prevent committing if you didn't disable the index
ScottDugas 24f229f
Some code/comment cleanup
ScottDugas 7589f4b
Merge branch 'main' into repair-store-without-disable
ScottDugas 708a8ca
Convert anonymous class into PreventCommitCheck
ScottDugas 85fb139
Extract helper method, hopefully making test easier to understand
ScottDugas 6148a8b
Use a lambda to get even better reuse
ScottDugas c91fc80
Remove unnamed boolean test parameters
ScottDugas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,6 +255,11 @@ public class FDBRecordStore extends FDBStoreBase implements FDBRecordStoreBase<M | |
| protected static final Object RECORD_VERSION_KEY = FDBRecordStoreKeyspace.RECORD_VERSION_SPACE.key(); | ||
| protected static final Object INDEX_BUILD_SPACE_KEY = FDBRecordStoreKeyspace.INDEX_BUILD_SPACE.key(); | ||
|
|
||
| /** | ||
| * Name for the commit check that prevents commits when potentially corrupted indexes are left readable. | ||
| */ | ||
| public static final String POTENTIALLY_CORRUPTED_INDEXES_COMMIT_CHECK = "PotentiallyCorruptedIndexes"; | ||
|
|
||
| @SuppressWarnings("squid:S2386") | ||
| @SpotBugsSuppressWarnings("MS_MUTABLE_ARRAY") | ||
| public static final byte[] LITTLE_ENDIAN_INT64_ONE = { 1, 0, 0, 0, 0, 0, 0, 0 }; | ||
|
|
@@ -5682,6 +5687,25 @@ private CompletableFuture<Void> preloadMetaData() { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * In the event that a store has been corrupted, and the header has been lost, this method can be used to open | ||
| * the store, and fill in the missing header; replaced by {@link #repairMissingHeader(int, FormatVersion, boolean)}. | ||
| * | ||
| * @param userVersion the user version to set in the store header | ||
| * @param minimumPossibleFormatVersion the minimum {@link FormatVersion} that this store could have possibly | ||
| * had. Notably, upgrading to {@link FormatVersion#SAVE_VERSION_WITH_RECORD} requires moving data, and upgrading | ||
| * to {@link FormatVersion#SAVE_UNSPLIT_WITH_SUFFIX} requires storing whether the store should have the unsplit | ||
| * suffix or not. It is probably possible for {@code repairMissingHeader} to determine what to do based on the | ||
| * rest of the data in the store, but to keep this simple, upgrading across those versions is not supported. | ||
| * | ||
| * @return a boolean indicating whether a repair needed to be done ({@code true}) or not ({@code false}) and | ||
| * the opened store. | ||
| */ | ||
| @API(API.Status.DEPRECATED) | ||
| public CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHeader(final int userVersion, FormatVersion minimumPossibleFormatVersion) { | ||
| return repairMissingHeader(userVersion, minimumPossibleFormatVersion, false); | ||
| } | ||
|
|
||
| /** | ||
| * In the event that a store has been corrupted, and the header has been lost, this method can be used to open | ||
| * the store, and fill in the missing header. | ||
|
|
@@ -5697,6 +5721,9 @@ private CompletableFuture<Void> preloadMetaData() { | |
| * Disable all indexes, since we cannot universally determine whether they have been added or | ||
| * changed since the store was last opened. In theory there are some situations where we could | ||
| * determine that the index can be marked readable for free, but this is not supported. | ||
| * If {@code leavePotentiallyCorruptIndexesReadable} is {@code true} they will not be disabled. | ||
| * This can be useful if you want to use the potentially corrupt indexes to discern information | ||
| * about the corrupted records. | ||
| * </li> | ||
| * <li> | ||
| * Disable the {@link RecordMetaData#getRecordCountKey()} if there is one on the metadata, because | ||
|
|
@@ -5727,12 +5754,16 @@ private CompletableFuture<Void> preloadMetaData() { | |
| * to {@link FormatVersion#SAVE_UNSPLIT_WITH_SUFFIX} requires storing whether the store should have the unsplit | ||
| * suffix or not. It is probably possible for {@code repairMissingHeader} to determine what to do based on the | ||
| * rest of the data in the store, but to keep this simple, upgrading across those versions is not supported. | ||
| * @param leavePotentiallyCorruptIndexesReadable if {@code true}, indexes will not be marked as disabled during | ||
| * repair, even though they could be corrupt. | ||
| * | ||
| * @return a boolean indicating whether a repair needed to be done ({@code true}) or not ({@code false}) and | ||
| * the opened store. | ||
| */ | ||
| @API(API.Status.INTERNAL) | ||
|
Contributor
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. Maybe we should consider changing that to |
||
| public CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHeader(final int userVersion, FormatVersion minimumPossibleFormatVersion) { | ||
| public CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHeader( | ||
| final int userVersion, @Nonnull final FormatVersion minimumPossibleFormatVersion, | ||
| final boolean leavePotentiallyCorruptIndexesReadable) { | ||
| if (!formatVersion.isAtLeast(minimumPossibleFormatVersion)) { | ||
| throw new RecordCoreArgumentException("minimumPossibleFormatVersion is greater than the target formatVerson") | ||
| .addLogInfo(LogMessageKeys.FORMAT_VERSION, minimumPossibleFormatVersion) | ||
|
|
@@ -5748,12 +5779,13 @@ public CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHead | |
| store.getStoreStateCache().get(store, StoreExistenceCheck.NONE) | ||
| .thenCompose(storeStateCacheEntry -> | ||
| repairMissingHeader(userVersion, store, | ||
| storeStateCacheEntry.getRecordStoreState().getStoreHeader()))); | ||
| storeStateCacheEntry.getRecordStoreState().getStoreHeader(), leavePotentiallyCorruptIndexesReadable))); | ||
| } | ||
|
|
||
| private CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHeader(final int userVersion, | ||
| @Nonnull final FDBRecordStore store, | ||
| @Nonnull final RecordMetaDataProto.DataStoreInfo existing) { | ||
| @Nonnull final FDBRecordStore store, | ||
| @Nonnull final RecordMetaDataProto.DataStoreInfo existing, | ||
| boolean leavePotentiallyCorruptIndexesReadable) { | ||
| if (!existing.equals(RecordMetaDataProto.DataStoreInfo.getDefaultInstance())) { | ||
| return store.checkVersion(userVersionChecker, StoreExistenceCheck.ERROR_IF_NOT_EXISTS) | ||
| .thenApply(checkVersionDidSomething -> NonnullPair.of(false, store)); | ||
|
|
@@ -5827,12 +5859,24 @@ private CompletableFuture<NonnullPair<Boolean, FDBRecordStore>> repairMissingHea | |
| // or that the store was on a metadata version that didn't have the index, or | ||
| // had an older version of the index. If it wasn't readable on the current version, then | ||
| // leaving the index would leave it in a corrupted state. | ||
| return bumpMetaDataVersionStamp.thenCompose(vignore -> AsyncUtil.whenAll( | ||
| return bumpMetaDataVersionStamp.thenCompose(vignore -> { | ||
| if (leavePotentiallyCorruptIndexesReadable) { | ||
| // Add a commit check that will fail if the user tries to commit with potentially corrupted indexes | ||
| store.getRecordContext().addCommitCheck(POTENTIALLY_CORRUPTED_INDEXES_COMMIT_CHECK, | ||
| new PreventCommitCheck(() -> new RecordCoreException( | ||
| "Commit failed because potentially corrupted indexes were left readable after header repair. " + | ||
| "The indexes should be rebuilt or verified before allowing commits."))); | ||
| // Leave indexes as-is per user request | ||
| return AsyncUtil.DONE; | ||
| } else { | ||
| return AsyncUtil.whenAll( | ||
| recordMetaData.getAllIndexes().stream() | ||
| .map(store::markIndexDisabled) | ||
| .collect(Collectors.toList())) | ||
| .thenApply(ignored -> NonnullPair.of(true, store))); | ||
| .collect(Collectors.toList())); | ||
| } | ||
| }).thenApply(ignored -> NonnullPair.of(true, store)); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
52 changes: 52 additions & 0 deletions
52
...src/main/java/com/apple/foundationdb/record/provider/foundationdb/PreventCommitCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * PreventCommitCheck.java | ||
| * | ||
| * This source file is part of the FoundationDB open source project | ||
| * | ||
| * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.apple.foundationdb.record.provider.foundationdb; | ||
|
|
||
| import com.apple.foundationdb.annotation.API; | ||
| import com.apple.foundationdb.record.RecordCoreException; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Commit check that always fails, effectively preventing this transaction from committing at all. | ||
| */ | ||
| @API(API.Status.INTERNAL) | ||
| class PreventCommitCheck implements FDBRecordContext.CommitCheckAsync { | ||
|
|
||
| final Supplier<RecordCoreException> exceptionSupplier; | ||
|
|
||
| PreventCommitCheck(Supplier<RecordCoreException> exceptionSupplier) { | ||
| this.exceptionSupplier = exceptionSupplier; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isReady() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| @Nonnull | ||
| public CompletableFuture<Void> checkAsync() { | ||
| return CompletableFuture.failedFuture(exceptionSupplier.get()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add some verbiage about the inability to commit?