From 2bd5160fcc7a09d55665c542cd7e5c89815ba3a4 Mon Sep 17 00:00:00 2001 From: SpadeA-Tang Date: Mon, 4 Jul 2022 14:12:20 +0800 Subject: [PATCH 1/3] update Signed-off-by: SpadeA-Tang --- executor/builder.go | 4 ++-- session/txnmanager.go | 6 ++++-- sessiontxn/interface.go | 8 ++++---- sessiontxn/txn_manager_test.go | 24 ++++++++++++------------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index 8f930f5d7a107..0c04595bbeb3b 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -1539,9 +1539,9 @@ func (b *executorBuilder) getSnapshot() (kv.Snapshot, error) { txnManager := sessiontxn.GetTxnManager(b.ctx) if b.inInsertStmt || b.inUpdateStmt || b.inDeleteStmt || b.inSelectLockStmt { - snapshot, err = txnManager.GetForUpdateSnapshot() + snapshot, err = txnManager.GetSnapshotWithStmtForUpdateTS() } else { - snapshot, err = txnManager.GetReadSnapshot() + snapshot, err = txnManager.GetSnapshotWithStmtReadTS() } if err != nil { return nil, err diff --git a/session/txnmanager.go b/session/txnmanager.go index 63c5340e41e3a..5eb310e81a950 100644 --- a/session/txnmanager.go +++ b/session/txnmanager.go @@ -94,14 +94,16 @@ func (m *txnManager) GetStmtForUpdateTS() (uint64, error) { return ts, nil } -func (m *txnManager) GetReadSnapshot() (kv.Snapshot, error) { +// GetSnapshotWithStmtReadTS get snapshot with read ts +func (m *txnManager) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { if m.ctxProvider == nil { return nil, errors.New("context provider not set") } return m.ctxProvider.GetSnapshotWithStmtReadTS() } -func (m *txnManager) GetForUpdateSnapshot() (kv.Snapshot, error) { +// GetSnapshotWithStmtForUpdateTS get snapshot with for update ts +func (m *txnManager) GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) { if m.ctxProvider == nil { return nil, errors.New("context provider not set") } diff --git a/sessiontxn/interface.go b/sessiontxn/interface.go index 6d809fa923c38..d660c04596b08 100644 --- a/sessiontxn/interface.go +++ b/sessiontxn/interface.go @@ -151,10 +151,10 @@ type TxnManager interface { GetStmtForUpdateTS() (uint64, error) // GetContextProvider returns the current TxnContextProvider GetContextProvider() TxnContextProvider - // GetReadSnapshot get snapshot with read ts - GetReadSnapshot() (kv.Snapshot, error) - // GetForUpdateSnapshot get snapshot with for update ts - GetForUpdateSnapshot() (kv.Snapshot, error) + // GetSnapshotWithStmtReadTS get snapshot with read ts + GetSnapshotWithStmtReadTS() (kv.Snapshot, error) + // GetSnapshotWithStmtForUpdateTS get snapshot with for update ts + GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) // EnterNewTxn enters a new transaction. EnterNewTxn(ctx context.Context, req *EnterNewTxnRequest) error diff --git a/sessiontxn/txn_manager_test.go b/sessiontxn/txn_manager_test.go index 137a06bcd7ce1..983513fa44d03 100644 --- a/sessiontxn/txn_manager_test.go +++ b/sessiontxn/txn_manager_test.go @@ -307,7 +307,7 @@ func TestGetSnapshot(t *testing.T) { ts, err := mgr.GetStmtReadTS() require.NoError(t, err) compareSnap := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err := mgr.GetReadSnapshot() + snap, err := mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap, snap)) @@ -317,10 +317,10 @@ func TestGetSnapshot(t *testing.T) { ts, err = mgr.GetStmtForUpdateTS() require.NoError(t, err) compareSnap2 := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err = mgr.GetReadSnapshot() + snap, err = mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.False(t, isSnapshotEqual(t, compareSnap2, snap)) - snap, err = mgr.GetForUpdateSnapshot() + snap, err = mgr.GetSnapshotWithStmtForUpdateTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) @@ -337,7 +337,7 @@ func TestGetSnapshot(t *testing.T) { ts, err := mgr.GetStmtReadTS() require.NoError(t, err) compareSnap := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err := mgr.GetReadSnapshot() + snap, err := mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap, snap)) @@ -347,10 +347,10 @@ func TestGetSnapshot(t *testing.T) { ts, err = mgr.GetStmtForUpdateTS() require.NoError(t, err) compareSnap2 := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err = mgr.GetReadSnapshot() + snap, err = mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) - snap, err = mgr.GetForUpdateSnapshot() + snap, err = mgr.GetSnapshotWithStmtForUpdateTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) @@ -366,7 +366,7 @@ func TestGetSnapshot(t *testing.T) { ts, err := mgr.GetStmtReadTS() require.NoError(t, err) compareSnap := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err := mgr.GetReadSnapshot() + snap, err := mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap, snap)) @@ -376,10 +376,10 @@ func TestGetSnapshot(t *testing.T) { ts, err = mgr.GetStmtForUpdateTS() require.NoError(t, err) compareSnap2 := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err = mgr.GetReadSnapshot() + snap, err = mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) - snap, err = mgr.GetForUpdateSnapshot() + snap, err = mgr.GetSnapshotWithStmtForUpdateTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) @@ -397,7 +397,7 @@ func TestGetSnapshot(t *testing.T) { ts, err := mgr.GetStmtReadTS() require.NoError(t, err) compareSnap := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err := mgr.GetReadSnapshot() + snap, err := mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap, snap)) @@ -407,10 +407,10 @@ func TestGetSnapshot(t *testing.T) { ts, err = mgr.GetStmtForUpdateTS() require.NoError(t, err) compareSnap2 := sessiontxn.GetSnapshotWithTS(sctx, ts) - snap, err = mgr.GetReadSnapshot() + snap, err = mgr.GetSnapshotWithStmtReadTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) - snap, err = mgr.GetForUpdateSnapshot() + snap, err = mgr.GetSnapshotWithStmtForUpdateTS() require.NoError(t, err) require.True(t, isSnapshotEqual(t, compareSnap2, snap)) From 6c47af85608de5ba488863699b928313eb410bb5 Mon Sep 17 00:00:00 2001 From: SpadeA-Tang Date: Mon, 4 Jul 2022 14:50:43 +0800 Subject: [PATCH 2/3] update comment Signed-off-by: SpadeA-Tang --- session/txnmanager.go | 2 +- sessiontxn/interface.go | 4 ++-- sessiontxn/isolation/base.go | 2 +- sessiontxn/isolation/readcommitted.go | 2 +- sessiontxn/staleread/provider.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/session/txnmanager.go b/session/txnmanager.go index 5eb310e81a950..1362641b56f93 100644 --- a/session/txnmanager.go +++ b/session/txnmanager.go @@ -94,7 +94,7 @@ func (m *txnManager) GetStmtForUpdateTS() (uint64, error) { return ts, nil } -// GetSnapshotWithStmtReadTS get snapshot with read ts +// GetSnapshotWithStmtReadTS gets snapshot with read ts func (m *txnManager) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { if m.ctxProvider == nil { return nil, errors.New("context provider not set") diff --git a/sessiontxn/interface.go b/sessiontxn/interface.go index d660c04596b08..8682a9d7801af 100644 --- a/sessiontxn/interface.go +++ b/sessiontxn/interface.go @@ -121,7 +121,7 @@ type TxnContextProvider interface { GetStmtReadTS() (uint64, error) // GetStmtForUpdateTS returns the read timestamp used by update/insert/delete or select ... for update GetStmtForUpdateTS() (uint64, error) - // GetSnapshotWithStmtReadTS get snapshot with read ts + // GetSnapshotWithStmtReadTS gets snapshot with read ts GetSnapshotWithStmtReadTS() (kv.Snapshot, error) // GetSnapshotWithStmtForUpdateTS get snapshot with for update ts GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) @@ -151,7 +151,7 @@ type TxnManager interface { GetStmtForUpdateTS() (uint64, error) // GetContextProvider returns the current TxnContextProvider GetContextProvider() TxnContextProvider - // GetSnapshotWithStmtReadTS get snapshot with read ts + // GetSnapshotWithStmtReadTS gets snapshot with read ts GetSnapshotWithStmtReadTS() (kv.Snapshot, error) // GetSnapshotWithStmtForUpdateTS get snapshot with for update ts GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) diff --git a/sessiontxn/isolation/base.go b/sessiontxn/isolation/base.go index 53386fa32c47c..2963b876f50da 100644 --- a/sessiontxn/isolation/base.go +++ b/sessiontxn/isolation/base.go @@ -288,7 +288,7 @@ func (p *baseTxnContextProvider) AdviseOptimizeWithPlan(_ interface{}) error { return nil } -// GetSnapshotWithStmtReadTS get snapshot with read ts +// GetSnapshotWithStmtReadTS gets snapshot with read ts func (p *baseTxnContextProvider) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { ts, err := p.GetStmtReadTS() if err != nil { diff --git a/sessiontxn/isolation/readcommitted.go b/sessiontxn/isolation/readcommitted.go index d2afad4c2ea26..06adc9fcba4fc 100644 --- a/sessiontxn/isolation/readcommitted.go +++ b/sessiontxn/isolation/readcommitted.go @@ -258,7 +258,7 @@ func (p *PessimisticRCTxnContextProvider) AdviseOptimizeWithPlan(val interface{} return nil } -// GetSnapshotWithStmtReadTS get snapshot with read ts +// GetSnapshotWithStmtReadTS gets snapshot with read ts func (p *PessimisticRCTxnContextProvider) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { snapshot, err := p.baseTxnContextProvider.GetSnapshotWithStmtForUpdateTS() if err != nil { diff --git a/sessiontxn/staleread/provider.go b/sessiontxn/staleread/provider.go index 289d4bcc024e8..44dbb1aef786c 100644 --- a/sessiontxn/staleread/provider.go +++ b/sessiontxn/staleread/provider.go @@ -150,7 +150,7 @@ func (p *StalenessTxnContextProvider) AdviseOptimizeWithPlan(_ interface{}) erro return nil } -// GetSnapshotWithStmtReadTS get snapshot with read ts and set the transaction related options +// GetSnapshotWithStmtReadTS gets snapshot with read ts and set the transaction related options // before return func (p *StalenessTxnContextProvider) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { txn, err := p.sctx.Txn(false) From 996897d669c8bef0eb30dc376fd3b9fcde2a4a42 Mon Sep 17 00:00:00 2001 From: SpadeA-Tang Date: Mon, 4 Jul 2022 14:51:29 +0800 Subject: [PATCH 3/3] update comment Signed-off-by: SpadeA-Tang --- session/txnmanager.go | 2 +- sessiontxn/interface.go | 4 ++-- sessiontxn/isolation/base.go | 2 +- sessiontxn/staleread/provider.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/session/txnmanager.go b/session/txnmanager.go index 1362641b56f93..8cfe1a2241258 100644 --- a/session/txnmanager.go +++ b/session/txnmanager.go @@ -102,7 +102,7 @@ func (m *txnManager) GetSnapshotWithStmtReadTS() (kv.Snapshot, error) { return m.ctxProvider.GetSnapshotWithStmtReadTS() } -// GetSnapshotWithStmtForUpdateTS get snapshot with for update ts +// GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts func (m *txnManager) GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) { if m.ctxProvider == nil { return nil, errors.New("context provider not set") diff --git a/sessiontxn/interface.go b/sessiontxn/interface.go index 8682a9d7801af..2e43a28340723 100644 --- a/sessiontxn/interface.go +++ b/sessiontxn/interface.go @@ -123,7 +123,7 @@ type TxnContextProvider interface { GetStmtForUpdateTS() (uint64, error) // GetSnapshotWithStmtReadTS gets snapshot with read ts GetSnapshotWithStmtReadTS() (kv.Snapshot, error) - // GetSnapshotWithStmtForUpdateTS get snapshot with for update ts + // GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) // OnInitialize is the hook that should be called when enter a new txn with this provider @@ -153,7 +153,7 @@ type TxnManager interface { GetContextProvider() TxnContextProvider // GetSnapshotWithStmtReadTS gets snapshot with read ts GetSnapshotWithStmtReadTS() (kv.Snapshot, error) - // GetSnapshotWithStmtForUpdateTS get snapshot with for update ts + // GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) // EnterNewTxn enters a new transaction. diff --git a/sessiontxn/isolation/base.go b/sessiontxn/isolation/base.go index 2963b876f50da..ec2ad6d41f59b 100644 --- a/sessiontxn/isolation/base.go +++ b/sessiontxn/isolation/base.go @@ -298,7 +298,7 @@ func (p *baseTxnContextProvider) GetSnapshotWithStmtReadTS() (kv.Snapshot, error return p.getSnapshotByTS(ts) } -// GetSnapshotWithStmtForUpdateTS get snapshot with for update ts +// GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts func (p *baseTxnContextProvider) GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) { ts, err := p.GetStmtForUpdateTS() if err != nil { diff --git a/sessiontxn/staleread/provider.go b/sessiontxn/staleread/provider.go index 44dbb1aef786c..36d8113679564 100644 --- a/sessiontxn/staleread/provider.go +++ b/sessiontxn/staleread/provider.go @@ -174,7 +174,7 @@ func (p *StalenessTxnContextProvider) GetSnapshotWithStmtReadTS() (kv.Snapshot, return snapshot, nil } -// GetSnapshotWithStmtForUpdateTS get snapshot with for update ts +// GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts func (p *StalenessTxnContextProvider) GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error) { return nil, errors.New("GetSnapshotWithStmtForUpdateTS not supported for stalenessTxnProvider") }