ReplicaSet is used for setting the value of a key to 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{})
| 351 | // setting the version of the key so that only the most updated version of the |
| 352 | // value is stored. |
| 353 | func (r *rpcServer) ReplicaSet(args ReplicaStorageArgs, resp *struct{}) error { |
| 354 | target := r.targetNode(args.Key, args.ExplicitPeer) |
| 355 | if target != r.n.name { |
| 356 | return r.forward(target, "Node.ReplicaSet", args, resp) |
| 357 | } |
| 358 | |
| 359 | r.l.Lock() |
| 360 | defer r.l.Unlock() |
| 361 | v := r.versions[args.Key] |
| 362 | |
| 363 | // Check if we are trying to set an old version. |
| 364 | if v != nil && v.Peer == args.Peer && args.Version <= v.Version { |
| 365 | return nil |
| 366 | } |
| 367 | |
| 368 | if err := r.n.data.Set(args.Key, args.Value, args.Exp, args.Flags); err != nil { |
| 369 | return err |
| 370 | } |
| 371 | |
| 372 | // Update the replica version. |
| 373 | r.versions[args.Key] = &args.ReplicaVersion |
| 374 | return nil |
| 375 | } |
| 376 | |
| 377 | // ReplicaTouch is used for setting the expiration of a key on a replica. It |
| 378 | // allows setting the version of the key so that only the most updated version |
no test coverage detected