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{})
| 378 | // allows setting the version of the key so that only the most updated version |
| 379 | // of the value is stored. |
| 380 | func (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 | } |
no test coverage detected