Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
chore(sql): jitter around sql write retries (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
asher authored Sep 13, 2019
1 parent 3101c2d commit ff26d8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SqlQueueProperties {
* See: https://github.com/spinnaker/kork/blob/master/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/SqlRetryProperties.kt
*/
var retries: SqlRetryProperties = SqlRetryProperties(
transactions = RetryProperties(maxRetries = 10, backoffMs = 100),
transactions = RetryProperties(maxRetries = 20, backoffMs = 100),
reads = RetryProperties()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import java.util.concurrent.TimeUnit
import kotlin.Exception
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random.Default.nextLong

@KotlinOpen
class SqlQueue(
Expand Down Expand Up @@ -116,6 +117,9 @@ class SqlQueue(

private val lockTtlDuration = Duration.ofSeconds(lockTtlSeconds.toLong())

private val writeRetryBackoffMin = max(sqlRetryProperties.transactions.backoffMs - 25, 25)
private val writeRetryBackoffMax = max(sqlRetryProperties.transactions.backoffMs + 50, 100)

init {
log.info("Configured $javaClass queue: $queueName")
initTables()
Expand Down Expand Up @@ -716,7 +720,9 @@ class SqlQueue(
"sqlWrite",
RetryConfig.custom<T>()
.maxAttempts(sqlRetryProperties.transactions.maxRetries)
.waitDuration(Duration.ofMillis(sqlRetryProperties.transactions.backoffMs))
.waitDuration(
Duration.ofMillis(
nextLong(writeRetryBackoffMin, writeRetryBackoffMax)))
.ignoreExceptions(SQLDialectNotSupportedException::class.java)
.build()
)
Expand Down

0 comments on commit ff26d8f

Please sign in to comment.