Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.apple.foundationdb.record.provider.foundationdb;

import com.apple.foundationdb.FDBError;
import com.apple.foundationdb.FDBException;
import com.apple.foundationdb.MutationType;
import com.apple.foundationdb.annotation.API;
Expand Down Expand Up @@ -59,7 +58,6 @@
import java.time.DateTimeException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -1213,22 +1211,6 @@ protected static <T> T findException(@Nullable Throwable ex, Class<T> classT) {
}
return null;
}

protected static boolean shouldLessenWork(@Nullable FDBException ex) {
// These error codes represent a list of errors that can occur if there is too much work to be done
// in a single transaction.
if (ex == null) {
return false;
}
final Set<Integer> lessenWorkCodes = new HashSet<>(Arrays.asList(
FDBError.TIMED_OUT.code(),
FDBError.TRANSACTION_TOO_OLD.code(),
FDBError.NOT_COMMITTED.code(),
FDBError.TRANSACTION_TIMED_OUT.code(),
FDBError.COMMIT_READ_INCOMPLETE.code(),
FDBError.TRANSACTION_TOO_LARGE.code()));
return lessenWorkCodes.contains(ex.getCode());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
mergeControl.mergeHadFailed(); // report to adjust stats
final FDBException ex = IndexingBase.findException(e, FDBException.class);
final IndexDeferredMaintenanceControl.LastStep lastStep = mergeControl.getLastStep();
if (!IndexingBase.shouldLessenWork(ex)) {
if (shouldAbort(ex)) {
giveUpMerging(mergeControl, e);
}
switch (lastStep) {
Expand All @@ -175,6 +175,14 @@
return AsyncUtil.READY_TRUE; // and retry
}

private boolean shouldAbort(@Nullable FDBException ex) {
if (ex == null) {
return true;
}
// TODO: return true if the exception is clearly not retriable

Check warning on line 182 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMerger.java

View check run for this annotation

fdb.teamscale.io / Teamscale | Findings

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMerger.java#L182

TODO: return true if the exception is clearly not retriable https://fdb.teamscale.io/findings/details/foundationdb-fdb-record-layer?t=FORK_MR%2F3732%2Fjjezra%2Fmerger_retry_by_default%3AHEAD&id=8B69489D49D660B961E9007845B5895F
return false;
}

private void handleRepartitioningFailure(final IndexDeferredMaintenanceControl mergeControl, Throwable e) {
repartitionDocumentCount = mergeControl.getRepartitionDocumentCount();
if (repartitionDocumentCount == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.apple.foundationdb.record.provider.foundationdb;

import com.apple.foundationdb.FDBError;
import com.apple.foundationdb.FDBException;
import com.apple.foundationdb.annotation.API;
import com.apple.foundationdb.async.AsyncUtil;
Expand Down Expand Up @@ -133,7 +134,7 @@ boolean mayRetryAfterHandlingException(@Nullable FDBException fdbException,
@Nullable List<Object> additionalLogMessageKeyValues,
int currTries,
final boolean adjustLimits) {
if (currTries >= common.config.getMaxRetries() || !IndexingBase.shouldLessenWork(fdbException)) {
if (currTries >= common.config.getMaxRetries() || !shouldLessenWork(fdbException)) {
// Here: should not retry or no more retries. There is no real need to handle limits.
return false;
}
Expand All @@ -144,6 +145,22 @@ boolean mayRetryAfterHandlingException(@Nullable FDBException fdbException,
return true;
}

private static boolean shouldLessenWork(@Nullable FDBException ex) {
// These error codes represent a list of errors that can occur if there is too much work to be done
// in a single transaction.
if (ex == null) {
return false;
}
final Set<Integer> lessenWorkCodes = new HashSet<>(Arrays.asList(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set can be declared as a static instance - no need to instantiate every time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wonder - wouldn't the JVM do the right thing here? It seems like an obvious optimization and I know that other languages are performing this optimization (and much more).

FDBError.TIMED_OUT.code(),
FDBError.TRANSACTION_TOO_OLD.code(),
FDBError.NOT_COMMITTED.code(),
FDBError.TRANSACTION_TIMED_OUT.code(),
FDBError.COMMIT_READ_INCOMPLETE.code(),
FDBError.TRANSACTION_TOO_LARGE.code()));
return lessenWorkCodes.contains(ex.getCode());
}

void decreaseLimit(@Nonnull FDBException fdbException,
@Nullable List<Object> additionalLogMessageKeyValues) {
// TODO: decrease the limit only for certain errors
Expand Down
Loading