Skip to content

Commit

Permalink
GOCBC-317 Don't pass CAS value to TouchEx
Browse files Browse the repository at this point in the history
Motivation
----------
Touch should not send a non-zero CAS value to the server. As of
server 5.x this is enforced by the server and will return an error.

Changes
-------
Don't pass CAS from touch to TouchEx and change signature of touch,
leaving signatute of Touch and TouchDura as is. Fail fast in Touch
and TouchDura if a non-0 CAS value is provided.

Change-Id: I4f763ad276482346cf9955e47b9aa2e25b614b63
Reviewed-on: http://review.couchbase.org/95807
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
chvck committed Jul 17, 2018
1 parent 03652b9 commit 129fbfb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions bucket_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ func (b *Bucket) GetReplica(key string, valuePtr interface{}, replicaIdx int) (C
}

// Touch touches a document, specifying a new expiry time for it.
// The Cas value must be 0.
func (b *Bucket) Touch(key string, cas Cas, expiry uint32) (Cas, error) {
span := b.startKvOpTrace("Touch")
defer span.Finish()

cas, _, err := b.touch(span.Context(), key, cas, expiry)
if cas != 0 {
return 0, ErrNonZeroCas
}

cas, _, err := b.touch(span.Context(), key, expiry)
return cas, err
}

Expand Down Expand Up @@ -302,11 +307,10 @@ func (b *Bucket) getReplica(tracectx opentracing.SpanContext, key string, valueP
return
}

func (b *Bucket) touch(tracectx opentracing.SpanContext, key string, cas Cas, expiry uint32) (casOut Cas, mtOut MutationToken, errOut error) {
func (b *Bucket) touch(tracectx opentracing.SpanContext, key string, expiry uint32) (casOut Cas, mtOut MutationToken, errOut error) {
ctrl := b.newOpManager(tracectx)
err := ctrl.Wait(b.client.TouchEx(gocbcore.TouchOptions{
Key: []byte(key),
Cas: gocbcore.Cas(cas),
Expiry: expiry,
TraceContext: tracectx,
}, func(res *gocbcore.TouchResult, err error) {
Expand Down
7 changes: 6 additions & 1 deletion bucket_dura.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,16 @@ func (b *Bucket) durability(tracectx opentracing.SpanContext, key string, cas Ca
}

// TouchDura touches a document, specifying a new expiry time for it. Additionally checks document durability.
// The Cas value must be 0.
func (b *Bucket) TouchDura(key string, cas Cas, expiry uint32, replicateTo, persistTo uint) (Cas, error) {
span := b.startKvOpTrace("TouchDura")
defer span.Finish()

cas, mt, err := b.touch(span.Context(), key, cas, expiry)
if cas != 0 {
return 0, ErrNonZeroCas
}

cas, mt, err := b.touch(span.Context(), key, expiry)
if err != nil {
return cas, err
}
Expand Down
2 changes: 2 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ var (
ErrInvalidCert = gocbcore.ErrInvalidCert
// ErrInvalidCredentials is returned when an invalid set of credentials is provided for a service.
ErrInvalidCredentials = gocbcore.ErrInvalidCredentials
// ErrNonZeroCas occurs when an operation that require a CAS value of 0 is used with a non-zero value.
ErrNonZeroCas = gocbcore.ErrNonZeroCas

// ErrShutdown occurs when an operation is performed on a bucket that has been closed.
ErrShutdown = gocbcore.ErrShutdown
Expand Down

0 comments on commit 129fbfb

Please sign in to comment.