Skip to content

Commit 94602f8

Browse files
authored
Introduce a new Option to set asyncToSync timeout. (#3205)
This introduces a new `Option` for setting `asyncToSyncTimeout` to avoiding blocking forever on futures that may never return. An example of such future is waiting for `getReadVersion` JNI call to comeback against an unreachable FDB instance. This fixes #3213.
1 parent cdf256e commit 94602f8

File tree

2 files changed

+14
-0
lines changed
  • fdb-relational-api/src/main/java/com/apple/foundationdb/relational/api
  • fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server

2 files changed

+14
-0
lines changed

fdb-relational-api/src/main/java/com/apple/foundationdb/relational/api/Options.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ public enum Name {
188188
* that can be used in EXECUTE CONTINUATION statements.
189189
*/
190190
CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS,
191+
192+
/**
193+
* Timeout for asynchronous operations in milliseconds, this is usually used to set an upperbound time limit for
194+
* operations interacting with FDB.
195+
* Scope: Engine
196+
*/
197+
ASYNC_OPERATIONS_TIMEOUT_MILLIS
191198
}
192199

193200
public enum IndexFetchMethod {
@@ -221,6 +228,7 @@ public enum IndexFetchMethod {
221228
builder.put(Name.DRY_RUN, false);
222229
builder.put(Name.CASE_SENSITIVE_IDENTIFIERS, false);
223230
builder.put(Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
231+
builder.put(Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS, 10_000L);
224232
OPTIONS_DEFAULT_VALUES = builder.build();
225233
}
226234

@@ -355,6 +363,7 @@ private static Map<Name, List<OptionContract>> makeContracts() {
355363
data.put(Name.CURRENT_PLAN_HASH_MODE, List.of(TypeContract.stringType()));
356364
data.put(Name.VALID_PLAN_HASH_MODES, List.of(TypeContract.stringType()));
357365
data.put(Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, List.of(TypeContract.booleanType()));
366+
data.put(Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS, List.of(TypeContract.longType(), RangeContract.of(0L, Long.MAX_VALUE)));
358367

359368
return Collections.unmodifiableMap(data);
360369
}

fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.Collections;
6464
import java.util.List;
6565
import java.util.Optional;
66+
import java.util.concurrent.TimeUnit;
6667

6768
/**
6869
* Temporary class. "The Relational Database".
@@ -88,6 +89,10 @@ public FRL() throws RelationalException {
8889
@SpotBugsSuppressWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Should consider refactoring but throwing exceptions for now")
8990
public FRL(@Nonnull Options options) throws RelationalException {
9091
final FDBDatabase fdbDb = FDBDatabaseFactory.instance().getDatabase();
92+
final Long asyncToSyncTimeout = options.getOption(Options.Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS);
93+
if (asyncToSyncTimeout > 0) {
94+
fdbDb.setAsyncToSyncTimeout(asyncToSyncTimeout, TimeUnit.MILLISECONDS);
95+
}
9196
this.fdbDatabase = new DirectFdbConnection(fdbDb, NoOpMetricRegistry.INSTANCE);
9297

9398
final RelationalKeyspaceProvider keyspaceProvider = RelationalKeyspaceProvider.instance();

0 commit comments

Comments
 (0)