Skip to content

Commit

Permalink
GOCBC-32: Added support for CAS when performing a Touch operation.
Browse files Browse the repository at this point in the history
Additionally removed some additional network overhead associated
with using the Touch method.
  • Loading branch information
brett19 committed May 22, 2015
1 parent e61231c commit 6b279a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func (b *Bucket) GetReplica(key string, valuePtr interface{}, replicaIdx int) (u
}

// Touches a document, specifying a new expiry time for it.
func (b *Bucket) Touch(key string, expiry uint32) (uint64, error) {
func (b *Bucket) Touch(key string, cas uint64, expiry uint32) (uint64, error) {
return b.hlpCasExec(func(cb ioCasCallback) (pendingOp, error) {
op, err := b.client.Touch([]byte(key), expiry, gocbcore.TouchCallback(cb))
op, err := b.client.Touch([]byte(key), cas, expiry, gocbcore.TouchCallback(cb))
return op, err
})
}
Expand Down
30 changes: 25 additions & 5 deletions gocbcore/agentops.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,31 @@ func (c *Agent) GetReplica(key []byte, replicaIdx int, cb GetCallback) (PendingO
}
}

func (c *Agent) Touch(key []byte, expiry uint32, cb TouchCallback) (PendingOp, error) {
// This seems odd, but this is how it's done in Node.js
return c.GetAndTouch(key, expiry, func(value []byte, flags uint32, cas uint64, err error) {
cb(cas, err)
})
func (c *Agent) Touch(key []byte, cas uint64, expiry uint32, cb TouchCallback) (PendingOp, error) {
handler := func(resp *memdResponse, err error) {
if err != nil {
cb(0, err)
return
}
cb(resp.Cas, nil)
}

extraBuf := make([]byte, 4)
binary.BigEndian.PutUint32(extraBuf[0:], expiry)

req := &memdQRequest{
memdRequest: memdRequest{
Magic: ReqMagic,
Opcode: CmdTouch,
Datatype: 0,
Cas: cas,
Extras: extraBuf,
Key: key,
Value: nil,
},
Callback: handler,
}
return c.dispatchOp(req)
}

func (c *Agent) Unlock(key []byte, cas uint64, cb UnlockCallback) (PendingOp, error) {
Expand Down

0 comments on commit 6b279a9

Please sign in to comment.