@@ -156,6 +156,14 @@ type RetryPolicy interface {
156156 GetRetryType (error ) RetryType
157157}
158158
159+ // LWTRetryPolicy is a similar interface to RetryPolicy
160+ // If a query is recognized as an LWT query and its RetryPolicy satisfies this
161+ // interface, then this interface will be used instead of RetryPolicy.
162+ type LWTRetryPolicy interface {
163+ AttemptLWT (RetryableQuery ) bool
164+ GetRetryTypeLWT (error ) RetryType
165+ }
166+
159167// SimpleRetryPolicy has simple logic for attempting a query a fixed number of times.
160168//
161169// See below for examples of usage:
@@ -175,10 +183,22 @@ func (s *SimpleRetryPolicy) Attempt(q RetryableQuery) bool {
175183 return q .Attempts () <= s .NumRetries
176184}
177185
186+ func (s * SimpleRetryPolicy ) AttemptLWT (q RetryableQuery ) bool {
187+ return s .Attempt (q )
188+ }
189+
178190func (s * SimpleRetryPolicy ) GetRetryType (err error ) RetryType {
179191 return RetryNextHost
180192}
181193
194+ // Retrying on a different host is fine for normal (non-LWT) queries,
195+ // but in case of LWTs it will cause Paxos contention and possibly
196+ // even timeouts if other clients send statements touching the same
197+ // partition to the original node at the same time.
198+ func (s * SimpleRetryPolicy ) GetRetryTypeLWT (err error ) RetryType {
199+ return Retry
200+ }
201+
182202// ExponentialBackoffRetryPolicy sleeps between attempts
183203type ExponentialBackoffRetryPolicy struct {
184204 NumRetries int
@@ -193,6 +213,10 @@ func (e *ExponentialBackoffRetryPolicy) Attempt(q RetryableQuery) bool {
193213 return true
194214}
195215
216+ func (e * ExponentialBackoffRetryPolicy ) AttemptLWT (q RetryableQuery ) bool {
217+ return e .Attempt (q )
218+ }
219+
196220// used to calculate exponentially growing time
197221func getExponentialTime (min time.Duration , max time.Duration , attempts int ) time.Duration {
198222 if min <= 0 {
@@ -215,6 +239,14 @@ func (e *ExponentialBackoffRetryPolicy) GetRetryType(err error) RetryType {
215239 return RetryNextHost
216240}
217241
242+ // Retrying on a different host is fine for normal (non-LWT) queries,
243+ // but in case of LWTs it will cause Paxos contention and possibly
244+ // even timeouts if other clients send statements touching the same
245+ // partition to the original node at the same time.
246+ func (e * ExponentialBackoffRetryPolicy ) GetRetryTypeLWT (err error ) RetryType {
247+ return Retry
248+ }
249+
218250// DowngradingConsistencyRetryPolicy: Next retry will be with the next consistency level
219251// provided in the slice
220252//
0 commit comments