From bf08a6142ce08bbd8fc36c810c406b3812f5e663 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 4 Nov 2016 09:12:06 -0700 Subject: [PATCH] grpcproxy: invalidate comparison keys after txn If the txn comparison block makes claims about a key's current state, then it may say a key has been updated. Future range/txn operations may expect this update to eventually be propagated through the cluster and show up in serialized requests. To avoid spinning forever on txn/serialized range loops, invalidate the comparison keys. --- proxy/grpcproxy/kv.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/proxy/grpcproxy/kv.go b/proxy/grpcproxy/kv.go index ed6b310e0..9ffcb8d02 100644 --- a/proxy/grpcproxy/kv.go +++ b/proxy/grpcproxy/kv.go @@ -89,7 +89,15 @@ func (p *kvProxy) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, e } resp, err := txn.If(cmps...).Then(thenops...).Else(elseops...).Commit() - return (*pb.TxnResponse)(resp), err + + if err != nil { + return nil, err + } + // txn may claim an outdated key is updated; be safe and invalidate + for _, cmp := range r.Compare { + p.cache.Invalidate(cmp.Key, nil) + } + return (*pb.TxnResponse)(resp), nil } func (p *kvProxy) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) {