Skip to content
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

Adding exp backoff for replay and get changes #135

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -71,9 +71,17 @@ class ShardReplicationTask(id: Long, type: String, action: String, description:
private val remoteClient = client.getRemoteClusterClient(leaderAlias)
private val retentionLeaseHelper = RemoteClusterRetentionLeaseHelper(clusterService.clusterName.value(), remoteClient)
private var paused = false
private val backOffForNodeDiscovery = 1000L
private var lastLeaseRenewalMillis = System.currentTimeMillis()

//Start backOff for exceptions with a second
private val initialBackoffMillis = 1000L
//Start backOff for exceptions with a second
private var backOffForRetry = initialBackoffMillis
//Max timeout for backoff
private val maxTimeOut = 60000L
//Backoff factor after every retry
private val factor = 2.0

private val clusterStateListenerForTaskInterruption = ClusterStateListenerForTaskInterruption()

override val log = Loggers.getLogger(javaClass, followerShardId)!!
Expand Down Expand Up @@ -216,6 +224,7 @@ class ShardReplicationTask(id: Long, type: String, action: String, description:
val batchToFetch = changeTracker.requestBatchToFetch()
val fromSeqNo = batchToFetch.first
val toSeqNo = batchToFetch.second

try {
logDebug("Getting changes $fromSeqNo-$toSeqNo")
val changesResponse = getChanges(fromSeqNo, toSeqNo)
Expand All @@ -224,14 +233,17 @@ class ShardReplicationTask(id: Long, type: String, action: String, description:
logDebug("pushed to sequencer $fromSeqNo-$toSeqNo")
changeTracker.updateBatchFetched(true, fromSeqNo, toSeqNo, changesResponse.changes.lastOrNull()?.seqNo() ?: fromSeqNo - 1,
changesResponse.lastSyncedGlobalCheckpoint)

//reset backoff after every successful getChanges call
backOffForRetry = initialBackoffMillis
} catch (e: OpenSearchTimeoutException) {
//TimeoutException is thrown if leader fails to send new changes in 1 minute, so we dont need a backoff again here for this exception
logInfo("Timed out waiting for new changes. Current seqNo: $fromSeqNo. $e")
changeTracker.updateBatchFetched(false, fromSeqNo, toSeqNo, fromSeqNo - 1,-1)
} catch (e: NodeNotConnectedException) {
followerClusterStats.stats[followerShardId]!!.opsReadFailures.addAndGet(1)
logInfo("Node not connected. Retrying request using a different node. ${e.stackTraceToString()}")
delay(backOffForNodeDiscovery)
delay(backOffForRetry)
backOffForRetry = (backOffForRetry * factor).toLong().coerceAtMost(maxTimeOut)
changeTracker.updateBatchFetched(false, fromSeqNo, toSeqNo, fromSeqNo - 1,-1)
} catch (e: Exception) {
followerClusterStats.stats[followerShardId]!!.opsReadFailures.addAndGet(1)
Expand All @@ -248,6 +260,8 @@ class ShardReplicationTask(id: Long, type: String, action: String, description:
throw e
}
}
delay(backOffForRetry)
backOffForRetry = (backOffForRetry * factor).toLong().coerceAtMost(maxTimeOut)
} finally {
rateLimiter.release()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.opensearch.replication.action.changes.GetChangesResponse
import org.opensearch.replication.action.replay.ReplayChangesAction
import org.opensearch.replication.action.replay.ReplayChangesRequest
import org.opensearch.replication.metadata.store.ReplicationMetadata
import org.opensearch.replication.util.suspendExecute
import org.opensearch.replication.util.suspendExecuteWithRetries
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ObsoleteCoroutinesApi
Expand Down Expand Up @@ -65,7 +65,7 @@ class TranslogSequencer(scope: CoroutineScope, private val replicationMetadata:
replayRequest.parentTask = parentTaskId
launch {
var relativeStartNanos = System.nanoTime()
val replayResponse = client.suspendExecute(replicationMetadata, ReplayChangesAction.INSTANCE, replayRequest)
val replayResponse = client.suspendExecuteWithRetries(replicationMetadata, ReplayChangesAction.INSTANCE, replayRequest, log = log)
if (replayResponse.shardInfo.failed > 0) {
replayResponse.shardInfo.failures.forEachIndexed { i, failure ->
log.error("Failed replaying changes. Failure:$i:$failure")
Expand Down