diff --git a/etcdserver/apply.go b/etcdserver/apply.go index fa8d0af42..2f1ecbf2a 100644 --- a/etcdserver/apply.go +++ b/etcdserver/apply.go @@ -345,34 +345,23 @@ func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) { return nil, err } - revision := a.s.KV().Rev() - // When executing the operations of txn, we need to hold the txn lock. // So the reader will not see any intermediate results. txnID := a.s.KV().TxnBegin() - defer func() { - err := a.s.KV().TxnEnd(txnID) - if err != nil { - panic(fmt.Sprint("unexpected error when closing txn", txnID)) - } - }() resps := make([]*pb.ResponseOp, len(reqs)) - changedKV := false for i := range reqs { - if reqs[i].GetRequestRange() == nil { - changedKV = true - } resps[i] = a.applyUnion(txnID, reqs[i]) } - if changedKV { - revision += 1 + err := a.s.KV().TxnEnd(txnID) + if err != nil { + panic(fmt.Sprint("unexpected error when closing txn", txnID)) } txnResp := &pb.TxnResponse{} txnResp.Header = &pb.ResponseHeader{} - txnResp.Header.Revision = revision + txnResp.Header.Revision = a.s.KV().Rev() txnResp.Responses = resps txnResp.Succeeded = ok return txnResp, nil diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index 3ff476dbf..18bac81c4 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -288,6 +288,18 @@ func TestV3TxnRevision(t *testing.T) { t.Fatalf("got rev %d, wanted rev %d", tresp.Header.Revision, presp.Header.Revision) } + txndr := &pb.RequestOp{Request: &pb.RequestOp_RequestDeleteRange{RequestDeleteRange: &pb.DeleteRangeRequest{Key: []byte("def")}}} + txn = &pb.TxnRequest{Success: []*pb.RequestOp{txndr}} + tresp, err = kvc.Txn(context.TODO(), txn) + if err != nil { + t.Fatal(err) + } + + // did not update revision + if presp.Header.Revision != tresp.Header.Revision { + t.Fatalf("got rev %d, wanted rev %d", tresp.Header.Revision, presp.Header.Revision) + } + txnput := &pb.RequestOp{Request: &pb.RequestOp_RequestPut{RequestPut: &pb.PutRequest{Key: []byte("abc"), Value: []byte("123")}}} txn = &pb.TxnRequest{Success: []*pb.RequestOp{txnput}} tresp, err = kvc.Txn(context.TODO(), txn)