Skip to content

Commit

Permalink
Prevent remote upload before CM starts the primary shard
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <ssashish@amazon.com>
  • Loading branch information
ashking94 committed Nov 25, 2023
1 parent 1fca1a7 commit 827d0f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 10 additions & 2 deletions server/src/main/java/org/opensearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3881,10 +3881,10 @@ private EngineConfig newEngineConfig(LongSupplier globalCheckpointSupplier) thro
circuitBreakerService,
globalCheckpointSupplier,
replicationTracker::getRetentionLeases,
() -> getOperationPrimaryTerm(),
this::getOperationPrimaryTerm,
tombstoneDocSupplier(),
isReadOnlyReplica,
replicationTracker::isPrimaryMode,
this::isStartedPrimary,
translogFactorySupplier.apply(indexSettings, shardRouting),
isTimeSeriesDescSortOptimizationEnabled() ? DataStream.TIMESERIES_LEAF_SORTER : null // DESC @timestamp default order for
// timeseries
Expand All @@ -3899,6 +3899,14 @@ public boolean isRemoteTranslogEnabled() {
return indexSettings() != null && indexSettings().isRemoteTranslogStoreEnabled();
}

/**
* This checks if we are in state to upload to remote store.
* @return
*/
public boolean isStartedPrimary() {
return replicationTracker.isPrimaryMode() && state == IndexShardState.STARTED;
}

/**
* @return true if segment reverse search optimization is enabled for time series based workload.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ private void initializeRemoteDirectoryOnTermUpdate() throws IOException {
* @return true iff primaryMode is true and index shard is not in closed state.
*/
private boolean isReadyForUpload() {
boolean isReady = (indexShard.getReplicationTracker().isPrimaryMode() && indexShard.state() != IndexShardState.CLOSED)
|| isLocalOrSnapshotRecovery();
boolean isReady = indexShard.isStartedPrimary() || isLocalOrSnapshotRecovery();

if (isReady == false) {
StringBuilder sb = new StringBuilder("Skipped syncing segments with");
Expand All @@ -507,7 +506,7 @@ private boolean isReadyForUpload() {
sb.append(" recoverySourceType=").append(indexShard.recoveryState().getRecoverySource().getType());
sb.append(" primary=").append(indexShard.shardRouting.primary());
}
logger.trace(sb.toString());
logger.info(sb.toString());
}
return isReady;
}
Expand Down

0 comments on commit 827d0f0

Please sign in to comment.