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) (#57025)

close #56476
  • Loading branch information
ti-chi-bot authored Oct 31, 2024
1 parent c0288ad commit c8ba94c
Show file tree
Hide file tree
Showing 7 changed files with 19 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 @@ -103,6 +103,7 @@ go_test(
flaky = True,
shard_count = 21,
deps = [
"//autoid_service",
"//br/pkg/errors",
"//br/pkg/lightning/log",
"//ddl",
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 @@ -143,8 +143,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 @@ -19,6 +19,8 @@ import (
"testing"

"github.com/pingcap/errors"
// autoid1.MockForTest is init there, we need to import it to make sure it's called
_ "github.com/pingcap/tidb/autoid_service"
"github.com/pingcap/tidb/br/pkg/lightning/common"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/kv"
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 @@ -1600,7 +1600,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 @@ -44,7 +44,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 @@ -54,6 +55,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

0 comments on commit c8ba94c

Please sign in to comment.