Skip to content

Commit 1ceda45

Browse files
committed
Deprecated sync lock API functions
1 parent f102a36 commit 1ceda45

File tree

7 files changed

+45
-36
lines changed

7 files changed

+45
-36
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ protected CompletableFuture<FDBStoredRecord<Message>> recordIfInIndexedTypes(FDB
152152
@SuppressWarnings("PMD.CloseResource")
153153
public CompletableFuture<Void> buildIndexAsync(boolean markReadable) {
154154
KeyValueLogMessage message = KeyValueLogMessage.build("build index online",
155-
LogMessageKeys.SHOULD_MARK_READABLE, markReadable);
155+
LogMessageKeys.SHOULD_MARK_READABLE, markReadable,
156+
LogMessageKeys.INDEXER_ID, common.getIndexerId());
156157
long startNanos = System.nanoTime();
157158
FDBDatabaseRunner runner = getRunner();
158159
final FDBStoreTimer timer = runner.getTimer();
159160
if ( timer != null) {
160161
lastProgressSnapshot = StoreTimerSnapshot.from(timer);
161162
}
162-
message.addKeyAndValue(LogMessageKeys.SESSION_ID, common.getUuid());
163163
AtomicReference<Throwable> indexingException = new AtomicReference<>(null);
164164
return handleStateAndDoBuildIndexAsync(markReadable, message)
165165
.handle((ret, ex) -> {
@@ -362,7 +362,7 @@ public void enforceStampOverwrite() {
362362
private CompletableFuture<Void> setIndexingTypeOrThrow(FDBRecordStore store, boolean continuedBuild) {
363363
// continuedBuild is set if this session isn't a continuation of a previous indexing
364364
IndexBuildProto.IndexBuildIndexingStamp indexingTypeStamp = getIndexingTypeStamp(store);
365-
heartbeat = new IndexingHeartbeat(common.getUuid(), indexingTypeStamp.getMethod(), common.config.getLeaseLengthMillis());
365+
heartbeat = new IndexingHeartbeat(common.getIndexerId(), indexingTypeStamp.getMethod(), common.config.getLeaseLengthMillis());
366366

367367
return forEachTargetIndex(index -> setIndexingTypeOrThrow(store, continuedBuild, index, indexingTypeStamp));
368368
}
@@ -506,7 +506,7 @@ RecordCoreException newPartlyBuiltException(boolean continuedBuild,
506506
IndexBuildProto.IndexBuildIndexingStamp savedStamp,
507507
IndexBuildProto.IndexBuildIndexingStamp expectedStamp,
508508
Index index) {
509-
return new PartlyBuiltException(savedStamp, expectedStamp, index, common.getUuid(),
509+
return new PartlyBuiltException(savedStamp, expectedStamp, index, common.getIndexerId(),
510510
savedStamp.getBlock() ?
511511
"This index was partly built, and blocked" :
512512
"This index was partly built by another method");
@@ -901,7 +901,7 @@ private void validateTypeStamp(final IndexBuildProto.IndexBuildIndexingStamp typ
901901
}
902902
if (typeStamp == null || typeStamp.getMethod() != expectedTypeStamp.getMethod() || isTypeStampBlocked(typeStamp)) {
903903
throw new PartlyBuiltException(typeStamp, expectedTypeStamp,
904-
index, common.getUuid(), "Indexing stamp had changed");
904+
index, common.getIndexerId(), "Indexing stamp had changed");
905905
}
906906
}
907907

@@ -1041,7 +1041,7 @@ protected void validateOrThrowEx(boolean isValid, @Nonnull String msg) {
10411041
throw new ValidationException(msg,
10421042
LogMessageKeys.INDEX_NAME, common.getTargetIndexesNames(),
10431043
LogMessageKeys.SOURCE_INDEX, policy.getSourceIndex(),
1044-
LogMessageKeys.INDEXER_ID, common.getUuid());
1044+
LogMessageKeys.INDEXER_ID, common.getIndexerId());
10451045
}
10461046
}
10471047

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private Index getSourceIndex(RecordMetaData metaData) {
103103
throw new ValidationException("no source index",
104104
LogMessageKeys.INDEX_NAME, common.getIndex().getName(),
105105
LogMessageKeys.SOURCE_INDEX, policy.getSourceIndex(),
106-
LogMessageKeys.INDEXER_ID, common.getUuid());
106+
LogMessageKeys.INDEXER_ID, common.getIndexerId());
107107
}
108108

109109
@Nonnull

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
@API(API.Status.INTERNAL)
5151
public class IndexingCommon {
52-
private final UUID uuid = UUID.randomUUID();
52+
private final UUID indexerId = UUID.randomUUID();
5353

5454
@Nonnull private final FDBDatabaseRunner runner;
5555

@@ -135,8 +135,8 @@ private void fillTargetIndexers(@Nonnull List<Index> targetIndexes, @Nullable Co
135135
}
136136
}
137137

138-
public UUID getUuid() {
139-
return uuid;
138+
public UUID getIndexerId() {
139+
return indexerId;
140140
}
141141

142142
public List<Object> indexLogMessageKeyValues() {
@@ -156,7 +156,7 @@ public List<Object> indexLogMessageKeyValues(@Nullable String transactionName, @
156156
logIf(true, keyValues,
157157
LogMessageKeys.TARGET_INDEX_NAME, getTargetIndexesNames(),
158158
LogMessageKeys.RECORDS_SCANNED, totalRecordsScanned.get(),
159-
LogMessageKeys.INDEXER_ID, uuid);
159+
LogMessageKeys.INDEXER_ID, indexerId);
160160

161161
if (moreKeyValues != null && !moreKeyValues.isEmpty()) {
162162
keyValues.addAll(moreKeyValues);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939

4040
public class IndexingHeartbeat {
4141
// [prefix, xid] -> [indexing-type, genesis time, heartbeat time]
42-
final UUID sessionId;
42+
final UUID indexerId;
4343
final IndexBuildProto.IndexBuildIndexingStamp.Method indexingMethod;
4444
final long genesisTimeMilliseconds;
4545
final long leaseLength;
4646

47-
public IndexingHeartbeat(final UUID sessionId, IndexBuildProto.IndexBuildIndexingStamp.Method indexingMethod, long leaseLength) {
48-
this.sessionId = sessionId;
47+
public IndexingHeartbeat(final UUID indexerId, IndexBuildProto.IndexBuildIndexingStamp.Method indexingMethod, long leaseLength) {
48+
this.indexerId = indexerId;
4949
this.indexingMethod = indexingMethod;
5050
this.leaseLength = leaseLength;
5151
this.genesisTimeMilliseconds = nowMilliseconds();
5252
}
5353

5454
public void updateHeartbeat(@Nonnull FDBRecordStore store, @Nonnull Index index) {
55-
byte[] key = IndexingSubspaces.indexheartbeatSubspace(store, index, sessionId).pack();
55+
byte[] key = IndexingSubspaces.indexheartbeatSubspace(store, index, indexerId).pack();
5656
byte[] value = IndexBuildProto.IndexBuildHeartbeat.newBuilder()
5757
.setMethod(indexingMethod)
5858
.setGenesisTimeMilliseconds(genesisTimeMilliseconds)
@@ -93,13 +93,13 @@ private void validateNonCompetingHeartbeat(KeyValue kv, long now) {
9393
return;
9494
}
9595
final UUID otherSessionId = keyTuple.getUUID(keyTuple.size() - 1);
96-
if (!otherSessionId.equals(this.sessionId)) {
96+
if (!otherSessionId.equals(this.indexerId)) {
9797
try {
9898
final IndexBuildProto.IndexBuildHeartbeat otherHeartbeat = IndexBuildProto.IndexBuildHeartbeat.parseFrom(kv.getValue());
9999
final long age = now - otherHeartbeat.getHeartbeatTimeMilliseconds();
100100
if (age > 0 && age < leaseLength) {
101101
throw new SynchronizedSessionLockedException("Failed to initialize the session because of an existing session in progress")
102-
.addLogInfo(LogMessageKeys.SESSION_ID, sessionId)
102+
.addLogInfo(LogMessageKeys.SESSION_ID, indexerId)
103103
.addLogInfo(LogMessageKeys.EXISTING_SESSION_ID, otherSessionId)
104104
.addLogInfo(LogMessageKeys.AGE_MILLISECONDS, age)
105105
.addLogInfo(LogMessageKeys.TIME_LIMIT_MILLIS, leaseLength);
@@ -111,7 +111,7 @@ private void validateNonCompetingHeartbeat(KeyValue kv, long now) {
111111
}
112112

113113
public void clearHeartbeat(@Nonnull FDBRecordStore store, @Nonnull Index index) {
114-
store.ensureContextActive().clear(IndexingSubspaces.indexheartbeatSubspace(store, index, sessionId).pack());
114+
store.ensureContextActive().clear(IndexingSubspaces.indexheartbeatSubspace(store, index, indexerId).pack());
115115
}
116116

117117
public static CompletableFuture<Map<UUID, IndexBuildProto.IndexBuildHeartbeat>> getIndexingHeartbeats(FDBRecordStore store, Index index, int maxCount) {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ public void mergeIndex() {
439439
* the lock.
440440
* @return a future that will be ready when the lock is released
441441
* @see SynchronizedSession#endAnySession
442+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #blockIndexBuilds}
442443
*/
444+
@API(API.Status.DEPRECATED)
445+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
446+
@Deprecated(since = "4.4.3.0", forRemoval = true)
443447
public CompletableFuture<Void> stopOngoingOnlineIndexBuildsAsync() {
444448
return runner.runAsync(context -> openRecordStore(context).thenAccept(recordStore ->
445449
stopOngoingOnlineIndexBuilds(recordStore, index)),
@@ -448,7 +452,11 @@ public CompletableFuture<Void> stopOngoingOnlineIndexBuildsAsync() {
448452

449453
/**
450454
* Synchronous/blocking version of {@link #stopOngoingOnlineIndexBuildsAsync()}.
455+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #blockIndexBuilds}
451456
*/
457+
@API(API.Status.DEPRECATED)
458+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
459+
@Deprecated(since = "4.4.3.0", forRemoval = true)
452460
public void stopOngoingOnlineIndexBuilds() {
453461
runner.asyncToSync(FDBStoreTimer.Waits.WAIT_STOP_ONLINE_INDEX_BUILD, stopOngoingOnlineIndexBuildsAsync());
454462
}
@@ -458,15 +466,23 @@ public void stopOngoingOnlineIndexBuilds() {
458466
* the lock.
459467
* @param recordStore record store whose index builds need to be stopped
460468
* @param index the index whose builds need to be stopped
469+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #blockIndexBuilds}
461470
*/
471+
@API(API.Status.DEPRECATED)
472+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
473+
@Deprecated(since = "4.4.3.0", forRemoval = true)
462474
public static void stopOngoingOnlineIndexBuilds(@Nonnull FDBRecordStore recordStore, @Nonnull Index index) {
463475
SynchronizedSession.endAnySession(recordStore.ensureContextActive(), IndexingSubspaces.indexBuildLockSubspace(recordStore, index));
464476
}
465477

466478
/**
467479
* Synchronous/blocking version of {@link #checkAnyOngoingOnlineIndexBuildsAsync()}.
468480
* @return <code>true</code> if the index is being built and <code>false</code> otherwise
481+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #getIndexingHeartbeats(int)}
469482
*/
483+
@API(API.Status.DEPRECATED)
484+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
485+
@Deprecated(since = "4.4.3.0", forRemoval = true)
470486
public boolean checkAnyOngoingOnlineIndexBuilds() {
471487
return runner.asyncToSync(FDBStoreTimer.Waits.WAIT_CHECK_ONGOING_ONLINE_INDEX_BUILD, checkAnyOngoingOnlineIndexBuildsAsync());
472488
}
@@ -475,7 +491,11 @@ public boolean checkAnyOngoingOnlineIndexBuilds() {
475491
* Check if the index is being built by any of the {@link OnlineIndexer}s (only if they use {@link SynchronizedSession}s),
476492
* including <i>this</i> {@link OnlineIndexer}.
477493
* @return a future that will complete to <code>true</code> if the index is being built and <code>false</code> otherwise
494+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #getIndexingHeartbeats(int)}
478495
*/
496+
@API(API.Status.DEPRECATED)
497+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
498+
@Deprecated(since = "4.4.3.0", forRemoval = true)
479499
public CompletableFuture<Boolean> checkAnyOngoingOnlineIndexBuildsAsync() {
480500
return runner.runAsync(context -> openRecordStore(context).thenCompose(recordStore ->
481501
checkAnyOngoingOnlineIndexBuildsAsync(recordStore, index)),
@@ -487,21 +507,18 @@ public CompletableFuture<Boolean> checkAnyOngoingOnlineIndexBuildsAsync() {
487507
* @param recordStore record store whose index builds need to be checked
488508
* @param index the index to check for ongoing index builds
489509
* @return a future that will complete to <code>true</code> if the index is being built and <code>false</code> otherwise
510+
* @deprecated synchronized build was replaced. The functionality of this function can be done with {@link #getIndexingHeartbeats(int)}
490511
*/
512+
@API(API.Status.DEPRECATED)
513+
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") // version is not IP
514+
@Deprecated(since = "4.4.3.0", forRemoval = true)
491515
public static CompletableFuture<Boolean> checkAnyOngoingOnlineIndexBuildsAsync(@Nonnull FDBRecordStore recordStore, @Nonnull Index index) {
492516
return SynchronizedSession.checkActiveSessionExists(recordStore.ensureContextActive(), IndexingSubspaces.indexBuildLockSubspace(recordStore, index));
493517
}
494518

495519
/**
496520
* Builds an index across multiple transactions.
497-
* <p>
498-
* If it is set to use synchronized sessions, it stops with {@link com.apple.foundationdb.synchronizedsession.SynchronizedSessionLockedException}
499-
* when there is another runner actively working on the same index. It first checks and updates index states and
500-
* clear index data respecting the {@link IndexStatePrecondition} being set. It then builds the index across
501-
* multiple transactions honoring the rate-limiting parameters set in the constructor of this class. It also retries
502-
* any retriable errors that it encounters while it runs the build. At the end, it marks the index readable in the
503-
* store.
504-
* </p>
521+
* This is a slow and retrying operation that is intended to be executed by background processes.
505522
* @return a future that will be ready when the build has completed
506523
* @throws com.apple.foundationdb.synchronizedsession.SynchronizedSessionLockedException the build is stopped
507524
* because there may be another build running actively on this index.

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexerBuildIndexTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.apple.foundationdb.record.provider.foundationdb;
2222

2323
import com.apple.foundationdb.async.AsyncUtil;
24-
import com.apple.foundationdb.async.MoreAsyncUtil;
2524
import com.apple.foundationdb.async.RangeSet;
2625
import com.apple.foundationdb.record.IndexState;
2726
import com.apple.foundationdb.record.logging.KeyValueLogMessage;
@@ -34,7 +33,6 @@
3433
import com.apple.foundationdb.tuple.Tuple;
3534
import com.apple.test.RandomizedTestUtils;
3635
import com.google.protobuf.Message;
37-
import org.junit.jupiter.api.Assertions;
3836
import org.slf4j.Logger;
3937
import org.slf4j.LoggerFactory;
4038

@@ -237,12 +235,6 @@ <M extends Message> void singleRebuild(
237235
});
238236
}
239237
}
240-
if (safeBuild) {
241-
buildFuture = MoreAsyncUtil.composeWhenComplete(
242-
buildFuture,
243-
(result, ex) -> indexBuilder.checkAnyOngoingOnlineIndexBuildsAsync().thenAccept(Assertions::assertFalse),
244-
fdb::mapAsyncToSyncException);
245-
}
246238

247239
if (recordsWhileBuilding != null && !recordsWhileBuilding.isEmpty()) {
248240
int i = 0;

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexingHeartbeatTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void testHeartbeatLowLevel() {
7777
Map<UUID, IndexBuildProto.IndexBuildHeartbeat> queried = indexer.getIndexingHeartbeats(0);
7878
Assertions.assertThat(queried).hasSize(count);
7979
Assertions.assertThat(queried.keySet())
80-
.containsExactlyInAnyOrderElementsOf(Arrays.stream(heartbeats).map(ht -> ht.sessionId).collect(Collectors.toList()));
80+
.containsExactlyInAnyOrderElementsOf(Arrays.stream(heartbeats).map(ht -> ht.indexerId).collect(Collectors.toList()));
8181

8282
// Query, partial
8383
queried = indexer.getIndexingHeartbeats(5);
@@ -95,7 +95,7 @@ void testHeartbeatLowLevel() {
9595
Map<UUID, IndexBuildProto.IndexBuildHeartbeat> queried = indexer.getIndexingHeartbeats(100);
9696
Assertions.assertThat(queried).hasSize(count);
9797
Assertions.assertThat(queried.keySet())
98-
.containsExactlyInAnyOrderElementsOf(Arrays.stream(heartbeats).map(ht -> ht.sessionId).collect(Collectors.toList()));
98+
.containsExactlyInAnyOrderElementsOf(Arrays.stream(heartbeats).map(ht -> ht.indexerId).collect(Collectors.toList()));
9999

100100
// clear all
101101
int countDeleted = indexer.clearIndexingHeartbeats(0, 0);

0 commit comments

Comments
 (0)