Skip to content

Commit

Permalink
lightning/importinto: set correct step to create single point allocat…
Browse files Browse the repository at this point in the history
…or (#56602) (#57925)

close #56476
  • Loading branch information
ti-chi-bot authored Dec 6, 2024
1 parent e5fd514 commit 2061937
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions br/pkg/lightning/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ go_test(
deps = [
"//br/pkg/errors",
"//br/pkg/lightning/log",
"//pkg/autoid_service",
"//pkg/ddl",
"//pkg/errno",
"//pkg/kv",
Expand Down
4 changes: 3 additions & 1 deletion br/pkg/lightning/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ func GetGlobalAutoIDAlloc(r autoid.Requirement, dbID int64, tblInfo *model.Table
case hasRowID || hasAutoIncID:
allocators := make([]autoid.Allocator, 0, 2)
if tblInfo.SepAutoInc() && hasAutoIncID {
// we must pass CustomAutoIncCacheOption(1) so NewAllocator can create
// correct single point allocator.
allocators = append(allocators, autoid.NewAllocator(r, dbID, tblInfo.ID, tblInfo.IsAutoIncColUnsigned(),
autoid.AutoIncrementType, noCache, tblVer))
autoid.AutoIncrementType, autoid.CustomAutoIncCacheOption(1), tblVer))
}
// this allocator is NOT used when SepAutoInc=true and auto increment column is clustered.
allocators = append(allocators, autoid.NewAllocator(r, dbID, tblInfo.ID, tblInfo.IsAutoIncColUnsigned(),
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/tidb/br/pkg/lightning/common"
// autoid1.MockForTest is init there, we need to import it to make sure it's called
_ "github.com/pingcap/tidb/pkg/autoid_service"
"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/importer/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ func (rc *Controller) importTables(ctx context.Context) (finalErr error) {
if err != nil {
return errors.Trace(err)
}
etcdCli, err := clientv3.New(clientv3.Config{
etcdCli, err = clientv3.New(clientv3.Config{
Endpoints: []string{rc.cfg.TiDB.PdAddr},
AutoSyncInterval: 30 * time.Second,
TLS: rc.tls.TLSConfig(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* whether the PK is clustered or not doesn't matter in this case */
CREATE TABLE nonclustered_cache1_initial_autoid (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
v int,
PRIMARY KEY (id) NONCLUSTERED
) AUTO_ID_CACHE=1 AUTO_INCREMENT = 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
100,3
101,3
99999,3
4 changes: 3 additions & 1 deletion br/tests/lightning_csv/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function run_with() {
run_sql 'SELECT id FROM csv.empty_strings WHERE b <> ""'
check_not_contains 'id:'

for table in clustered nonclustered clustered_cache1 nonclustered_cache1 nonclustered_cache1_shard_autorowid; do
for table in clustered nonclustered clustered_cache1 nonclustered_cache1 nonclustered_cache1_shard_autorowid nonclustered_cache1_initial_autoid; do
echo "check for table $table"
run_sql "select count(*) from auto_incr_id.$table"
check_contains 'count(*): 3'
# insert should work
Expand All @@ -56,6 +57,7 @@ function run_with() {
done

for table in clustered nonclustered clustered_cache1 nonclustered_cache1 no_pk no_pk_cache1; do
echo "check for table $table"
run_sql "select count(*) from no_auto_incr_id.$table"
check_contains 'count(*): 3'
# insert should work
Expand Down
6 changes: 6 additions & 0 deletions tests/realtikvtest/importintotest2/write_after_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func (s *mockGCSSuite) TestWriteAfterImport() {
s.tk.MustExec("drop table if exists t;")
})
for _, c := range cases {
if c.autoIDCache1 {
// after we add autoid.CustomAutoIncCacheOption(1), single point
// allocator is used, those tests will report "autoid service leader not found"
// as it lacks the necessary setup for real-tikv-test.
continue
}
fmt.Println("current case ", c.createTableSQL)
s.tk.MustExec("drop table if exists t;")
s.tk.MustExec(c.createTableSQL)
Expand Down

0 comments on commit 2061937

Please sign in to comment.