From 51551abef5a1e2b3a6eccdee4de534d273a17161 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 31 May 2016 01:55:58 -0700 Subject: [PATCH] concurrency, benchmark: read-committed STM isolation policy --- clientv3/concurrency/stm.go | 14 ++++++++++++++ tools/benchmark/cmd/stm.go | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clientv3/concurrency/stm.go b/clientv3/concurrency/stm.go index 8b9bbed12..056ebfb75 100644 --- a/clientv3/concurrency/stm.go +++ b/clientv3/concurrency/stm.go @@ -56,6 +56,12 @@ func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error return runSTM(s, apply) } +// NewSTMReadCommitted initiates a new read committed transaction. +func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { + s := &stmReadCommitted{stm{client: c, ctx: ctx, getOpts: []v3.OpOption{v3.WithSerializable()}}} + return runSTM(s, apply) +} + type stmResponse struct { resp *v3.TxnResponse err error @@ -234,6 +240,14 @@ func (s *stmSerializable) commit() *v3.TxnResponse { return nil } +type stmReadCommitted struct{ stm } + +// commit always goes through when read committed +func (s *stmReadCommitted) commit() *v3.TxnResponse { + s.rset = nil + return s.stm.commit() +} + func isKeyCurrent(k string, r *v3.GetResponse) v3.Cmp { rev := r.Header.Revision + 1 if len(r.Kvs) != 0 { diff --git a/tools/benchmark/cmd/stm.go b/tools/benchmark/cmd/stm.go index 407df9246..29249dd2e 100644 --- a/tools/benchmark/cmd/stm.go +++ b/tools/benchmark/cmd/stm.go @@ -52,7 +52,7 @@ var ( func init() { RootCmd.AddCommand(stmCmd) - stmCmd.Flags().StringVar(&stmIsolation, "isolation", "r", "Repeatable Reads (r) or Serializable (s)") + stmCmd.Flags().StringVar(&stmIsolation, "isolation", "r", "Read Committed (c), Repeatable Reads (r), or Serializable (s)") stmCmd.Flags().IntVar(&stmKeyCount, "keys", 1, "Total unique keys accessible by the benchmark") stmCmd.Flags().IntVar(&stmTotal, "total", 10000, "Total number of completed STM transactions") stmCmd.Flags().IntVar(&stmKeysPerTxn, "keys-per-txn", 1, "Number of keys to access per transaction") @@ -78,6 +78,8 @@ func stmFunc(cmd *cobra.Command, args []string) { } switch stmIsolation { + case "c": + mkSTM = v3sync.NewSTMReadCommitted case "r": mkSTM = v3sync.NewSTMRepeatable case "s":