Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn: rename snapshot related methods in txnManager. #35912

Merged
merged 8 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,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
Expand Down
6 changes: 4 additions & 2 deletions session/txnmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ func (m *txnManager) GetReadReplicaScope() string {
return m.ctxProvider.GetReadReplicaScope()
}

func (m *txnManager) GetReadSnapshot() (kv.Snapshot, error) {
// 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")
}
return m.ctxProvider.GetSnapshotWithStmtReadTS()
}

func (m *txnManager) GetForUpdateSnapshot() (kv.Snapshot, error) {
// 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")
}
Expand Down
12 changes: 6 additions & 6 deletions sessiontxn/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ 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 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
Expand Down Expand Up @@ -159,10 +159,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 gets snapshot with read ts
GetSnapshotWithStmtReadTS() (kv.Snapshot, error)
// GetSnapshotWithStmtForUpdateTS gets snapshot with for update ts
GetSnapshotWithStmtForUpdateTS() (kv.Snapshot, error)

// EnterNewTxn enters a new transaction.
EnterNewTxn(ctx context.Context, req *EnterNewTxnRequest) error
Expand Down
4 changes: 2 additions & 2 deletions sessiontxn/isolation/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,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 {
Expand All @@ -318,7 +318,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 {
Expand Down
2 changes: 1 addition & 1 deletion sessiontxn/isolation/readcommitted.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions sessiontxn/staleread/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,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)
Expand All @@ -186,7 +186,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")
}
24 changes: 12 additions & 12 deletions sessiontxn/txn_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand Down