-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: shard implicit row ID #5513
*: shard implicit row ID #5513
Conversation
ddl/ddl_api.go
Outdated
@@ -828,8 +828,22 @@ func handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo) { | |||
tbInfo.Charset = op.StrValue | |||
case ast.TableOptionCollate: | |||
tbInfo.Collate = op.StrValue | |||
case ast.TableOptionShardRowID: | |||
if !hasAutoIncrementColumn(tbInfo) { | |||
//tbInfo.ShardRowID = op.UintValue != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this?
executor/show.go
Outdated
@@ -623,6 +623,10 @@ func (e *ShowExec) fetchShowCreateTable() error { | |||
} | |||
} | |||
|
|||
if tb.Meta().ShardRowID { | |||
buf.WriteString(" SHARD_ROW_ID=1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we enable shard_row_id by SHARD_ROW_ID=2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enabled too.
parser/parser.y
Outdated
@@ -5272,6 +5273,10 @@ TableOption: | |||
{ | |||
$$ = &ast.TableOption{Tp: ast.TableOptionStatsPersistent} | |||
} | |||
| "SHARD_ROW_ID" EqOpt LengthNum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is EqOpt LengthNum
necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can disable it after enabled.
@zhangjinpeng1987 PTAL |
ddl/ddl_api.go
Outdated
@@ -932,6 +956,36 @@ func (d *ddl) RebaseAutoID(ctx context.Context, ident ast.Ident, newBase int64) | |||
return errors.Trace(err) | |||
} | |||
|
|||
func (d *ddl) ShardRowID(ctx context.Context, ident ast.Ident, uVal uint64) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment for this function
ddl/ddl_api.go
Outdated
return errors.Trace(err) | ||
} | ||
|
||
func (d *ddl) createJobByIdent(ident ast.Ident) (*model.Job, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createJobByName is a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ident
has both Schema
and TableName
, it's not a single name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createJobForTable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createJobForTable is a better name.
var buf [8]byte | ||
binary.LittleEndian.PutUint64(buf[:], startTS) | ||
hashVal := int64(murmur3.Sum32(buf[:])) | ||
return (hashVal & (1<<t.meta.ShardRowIDBits - 1)) << (64 - t.meta.ShardRowIDBits - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make the (1<<t.meta.ShardRowIDBits - 1)) << (64 - t.meta.ShardRowIDBits - 1)
a const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, t.meta.ShardRowIDBits
is different for each table.
ddl/ddl_api.go
Outdated
} | ||
t, err := is.TableByName(ident.Schema, ident.Name) | ||
if err != nil { | ||
return nil, errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this trace ?
ddl/ddl_api.go
Outdated
switch opt.Tp { | ||
case ast.TableOptionShardRowID: | ||
if opt.UintValue > 15 { | ||
opt.UintValue = 15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we define a constant as 15? We use it in multiple places.
executor/ddl_test.go
Outdated
if (h >> 56) > 0 { | ||
hasShardedID = true | ||
} | ||
count++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this line to line 355? Then we can make sure all IDs are sharded ID
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sharded ID still include shard 0, then (h >> 56) == 0
.
executor/ddl_test.go
Outdated
c.Assert(tk.Se.NewTxn(), IsNil) | ||
err = tbl.IterRecords(tk.Se, tbl.FirstKey(), nil, func(h int64, rec []types.Datum, cols []*table.Column) (more bool, err error) { | ||
c.Assert(h, GreaterEqual, int64(0)) | ||
if (h >> 56) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why there is 56
? Can we use a temporary variable to replace it? Then make it more readable.
ddl/ddl_api.go
Outdated
return errors.Trace(err) | ||
} | ||
|
||
func (d *ddl) createJobByIdent(ident ast.Ident) (*model.Job, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createJobForTable is a better name.
@@ -27,7 +27,7 @@ import ( | |||
) | |||
|
|||
// Test needs to change it, so it's a variable. | |||
var step = int64(5000) | |||
var step = int64(30000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a metrics for auto-id allocation latter.
executor/show.go
Outdated
@@ -623,6 +623,10 @@ func (e *ShowExec) fetchShowCreateTable() error { | |||
} | |||
} | |||
|
|||
if tb.Meta().ShardRowIDBits > 0 { | |||
buf.WriteString(fmt.Sprintf(" SHARD_ROW_ID_BITS=%d", tb.Meta().ShardRowIDBits)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use special-comment for show create table
. Or users will meet error when migrating data from TiDB to MySQL.
} | ||
upperQuery := strings.ToUpper(ddlQuery) | ||
reg, err := regexp.Compile(`SHARD_ROW_ID_BITS\s*=\s*\d+`) | ||
terror.Log(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If err isn't nil, reg may be nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just added to pass errcheck
, it never returns nil
LGTM |
LGTM |
…w-id Conflicts: ast/ddl.go parser/parser.y
/run-all-tests |
Shard the implicit row ID to avoid hot spot.