Hi @Eli_gotesman this depends on why you want to access the KV_LOCKED reason.
If you just want to know the timeout was caused by the document being locked then you could use errors.As
as documented in our docs here and then check what the retry reason is.
If you don’t actually want to retry until timeout and want to fail as soon as you see that the doc is locked then you could implement a custom retry strategy which fails fast on the locked retry reason and otherwise falls back to the best effort strategy otherwise. Something like…
type myRetryStrategy struct {
base *gocb.BestEffortRetryStrategy
}
func (rs *myRetryStrategy) RetryAfter(req gocb.RetryRequest, reason gocb.RetryReason) gocb.RetryAction {
if reason == gocb.KVLockedRetryReason {
// Bail out.
return &gocb.NoRetryRetryAction{}
}
return rs.base.RetryAfter(req, reason)
}
...
...
retryStat := &myRetryStrategy{
base: gocb.NewBestEffortRetryStrategy(nil),
}
_, err = col.GetAndLock("mydoc", 5*time.Second, &gocb.GetAndLockOptions{
RetryStrategy: retryStat,
})
if err != nil {
if errors.Is(err, gocb.ErrDocumentLocked) {
log.Println("IM LOCKED")
}
// do something else
}