Skip to content

Commit

Permalink
WithSchemaLease
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Mar 3, 2022
1 parent 6637e85 commit 0c7854e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3342,9 +3342,8 @@ func TestCommitWhenSchemaChange(t *testing.T) {
conf.Log.SlowThreshold = 10000
conf.Experimental.AllowsExpressionIndex = true
})
store, dom, clean := testkit.CreateMockStoreAndDomainWithoutZeroSchemaLease(t)
store, clean := testkit.CreateMockStoreWithSchemaLease(t, time.Second)
defer clean()
dom.SetStatsUpdating(true)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@global.tidb_max_delta_schema_count= 4096")
tk.MustExec("use test")
Expand Down
36 changes: 14 additions & 22 deletions testkit/mockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package testkit

import (
"testing"
"time"

"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
Expand All @@ -39,12 +40,12 @@ func CreateMockStore(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (store
func CreateMockStoreAndDomain(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain, func()) {
store, err := mockstore.NewMockStore(opts...)
require.NoError(t, err)
dom, clean := bootstrap(t, store)
dom, clean := bootstrap(t, store, 0)
return store, dom, clean
}

func bootstrap(t testing.TB, store kv.Storage) (*domain.Domain, func()) {
session.SetSchemaLease(0)
func bootstrap(t testing.TB, store kv.Storage, lease time.Duration) (*domain.Domain, func()) {
session.SetSchemaLease(lease)
session.DisableStats4Test()
dom, err := session.BootstrapSession(store)
require.NoError(t, err)
Expand All @@ -59,27 +60,18 @@ func bootstrap(t testing.TB, store kv.Storage) (*domain.Domain, func()) {
return dom, clean
}

// CreateMockStoreAndDomainWithoutZeroSchemaLease return a new mock kv.Storage and *domain.Domain.
func CreateMockStoreAndDomainWithoutZeroSchemaLease(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain, func()) {
store, err := mockstore.NewMockStore(opts...)
require.NoError(t, err)
dom, clean := bootstrapWithoutZeroSchemaLease(t, store)
return store, dom, clean
// CreateMockStoreWithSchemaLease return a new mock kv.Storage.
func CreateMockStoreWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) (store kv.Storage, clean func()) {
store, _, clean = CreateMockStoreAndDomainWithSchemaLease(t, lease, opts...)
return
}

func bootstrapWithoutZeroSchemaLease(t testing.TB, store kv.Storage) (*domain.Domain, func()) {
session.DisableStats4Test()
dom, err := session.BootstrapSession(store)
// CreateMockStoreAndDomainWithSchemaLease return a new mock kv.Storage and *domain.Domain.
func CreateMockStoreAndDomainWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain, func()) {
store, err := mockstore.NewMockStore(opts...)
require.NoError(t, err)

dom.SetStatsUpdating(true)

clean := func() {
dom.Close()
err := store.Close()
require.NoError(t, err)
}
return dom, clean
dom, clean := bootstrap(t, store, lease)
return store, dom, clean
}

// CreateMockStoreWithOracle returns a new mock kv.Storage and *domain.Domain, providing the oracle for the store.
Expand All @@ -88,6 +80,6 @@ func CreateMockStoreWithOracle(t testing.TB, oracle oracle.Oracle, opts ...mocks
require.NoError(t, err)
store.GetOracle().Close()
store.(tikv.Storage).SetOracle(oracle)
dom, clean := bootstrap(t, store)
dom, clean := bootstrap(t, store, 0)
return store, dom, clean
}

0 comments on commit 0c7854e

Please sign in to comment.