MCPcopy Create free account
hub / github.com/dadgar/onecache / ReplicaTouch

Method ReplicaTouch

onecache/onecache_rpc.go:380–402  ·  view source on GitHub ↗

ReplicaTouch is used for setting the expiration of a key on a replica. It allows setting the version of the key so that only the most updated version of the value is stored.

(args ReplicaStorageArgs, resp *struct{})

Source from the content-addressed store, hash-verified

378// allows setting the version of the key so that only the most updated version
379// of the value is stored.
380func (r *rpcServer) ReplicaTouch(args ReplicaStorageArgs, resp *struct{}) error {
381 target := r.targetNode(args.Key, args.ExplicitPeer)
382 if target != r.n.name {
383 return r.forward(target, "Node.ReplicaTouch", args, resp)
384 }
385
386 r.l.Lock()
387 defer r.l.Unlock()
388 v := r.versions[args.Key]
389
390 // Check if we are trying to set an old version.
391 if v != nil && v.Peer == args.Peer && args.Version <= v.Version {
392 return nil
393 }
394
395 if err := r.n.data.Touch(args.Key, args.Exp); err != nil {
396 return err
397 }
398
399 // Update the replica version.
400 r.versions[args.Key] = &args.ReplicaVersion
401 return nil
402}

Callers 1

replicateTouchMethod · 0.80

Calls 3

targetNodeMethod · 0.95
forwardMethod · 0.95
TouchMethod · 0.45

Tested by

no test coverage detected