Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
use prev row id for auto random and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv committed Nov 9, 2020
1 parent 3f39ff2 commit 11acecf
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lightning/backend/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewTableKVEncoder(tbl table.Table, options *SessionOptions, chunk *checkpoi
if hasSignBit {
incrementalBits -= 1
}
autoRandomBits = rand.New(rand.NewSource(chunk.Chunk.Offset)).Int63n(1<<tbl.Meta().AutoRandomBits) << incrementalBits
autoRandomBits = rand.New(rand.NewSource(chunk.Chunk.PrevRowIDMax)).Int63n(1<<tbl.Meta().AutoRandomBits) << incrementalBits
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion lightning/backend/sql2kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (s *kvSuite) TestDefaultAutoRandoms(c *C) {
SQLMode: mysql.ModeStrictAllTables,
Timestamp: 1234567893,
RowFormatVersion: "2",
}, &checkpoints.ChunkCheckpoint{Chunk: mydump.Chunk{Offset: 456}})
}, &checkpoints.ChunkCheckpoint{Chunk: mydump.Chunk{PrevRowIDMax: 456}})
logger := log.Logger{Logger: zap.NewNop()}
pairs, err := encoder.Encode(logger, []types.Datum{types.NewStringDatum("")}, 70, []int{-1, 0})
c.Assert(err, IsNil)
Expand Down
5 changes: 0 additions & 5 deletions tests/alter_random/data/alter_random.t.1.sql

This file was deleted.

4 changes: 2 additions & 2 deletions tests/alter_random/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ for backend in tidb importer local; do
run_lightning --backend $backend

run_sql "SELECT count(*) from alter_random.t"
check_contains "count(*): 6"
check_contains "count(*): 3"

run_sql "SELECT id & b'000001111111111111111111111111111111111111111111111111111111111' as inc FROM alter_random.t"
check_contains 'inc: 1'
Expand All @@ -40,6 +40,6 @@ for backend in tidb importer local; do
if [ "$backend" = 'tidb' ]; then
check_contains 'inc: 30002'
else
check_contains 'inc: 7'
check_contains 'inc: 4'
fi
done
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE `alter_random` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
5 changes: 5 additions & 0 deletions tests/auto_random_default/data/alter_random.t-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!40103 SET TIME_ZONE='+00:00' */;
CREATE TABLE `t` (
`id` bigint unsigned primary key auto_random,
`s` varchar(32)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
5 changes: 5 additions & 0 deletions tests/auto_random_default/data/alter_random.t.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!40103 SET TIME_ZONE='+00:00' */;
INSERT INTO `t` (`s`) VALUES
(""),
(""),
("");
45 changes: 45 additions & 0 deletions tests/auto_random_default/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# FIXME: auto-random is only stable on master currently.
check_cluster_version 4 0 0 AUTO_RANDOM || exit 0

for backend in tidb importer local; do
if [ "$backend" = 'local' ]; then
check_cluster_version 4 0 0 'local backend' || continue
fi

run_sql 'DROP DATABASE IF EXISTS alter_random;'
run_lightning --backend $backend

run_sql "SELECT count(*) from alter_random.t"
check_contains "count(*): 6"

run_sql "SELECT id & b'000001111111111111111111111111111111111111111111111111111111111' as inc FROM alter_random.t"
check_contains 'inc: 1'
check_contains 'inc: 2'
check_contains 'inc: 3'

# auto random base is 4
run_sql "INSERT INTO alter_random.t VALUES ();"
run_sql "SELECT id & b'000001111111111111111111111111111111111111111111111111111111111' as inc FROM alter_random.t"
if [ "$backend" = 'tidb' ]; then
check_contains 'inc: 30002'
else
check_contains 'inc: 4'
fi
done

0 comments on commit 11acecf

Please sign in to comment.