Skip to content

Commit

Permalink
*: address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Sep 1, 2016
1 parent ff923f2 commit f4c066f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
5 changes: 4 additions & 1 deletion sessionctx/binloginfo/binloginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ type keyType int

// String defines a Stringer function for debugging and pretty printing.
func (k keyType) String() string {
return "schema_version"
if k == schemaVersionKey {
return "schema_version"
}
return "binlog"
}

const (
Expand Down
60 changes: 33 additions & 27 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,35 +526,41 @@ func (t *Table) RemoveRecord(ctx context.Context, h int64, r []types.Datum) erro
return errors.Trace(err)
}
if binloginfo.Enable {
mutation := t.getMutation(ctx)
if t.meta.PKIsHandle {
mutation.DeletedIds = append(mutation.DeletedIds, h)
} else {
var primaryIdx *model.IndexInfo
for _, idx := range t.meta.Indices {
if idx.Primary {
primaryIdx = idx
break
}
err = t.addDeleteBinlog(ctx, h, r)
}
return errors.Trace(err)
}

func (t *Table) addDeleteBinlog(ctx context.Context, h int64, r []types.Datum) error {
mutation := t.getMutation(ctx)
if t.meta.PKIsHandle {
mutation.DeletedIds = append(mutation.DeletedIds, h)
} else {
var primaryIdx *model.IndexInfo
for _, idx := range t.meta.Indices {
if idx.Primary {
primaryIdx = idx
break
}
var data []byte
if primaryIdx != nil {
indexedValues := make([]types.Datum, len(primaryIdx.Columns))
for i := range indexedValues {
indexedValues[i] = r[primaryIdx.Columns[i].Offset]
}
data, err = codec.EncodeKey(nil, indexedValues...)
if err != nil {
return errors.Trace(err)
}
mutation.DeletedPks = append(mutation.DeletedPks, data)
} else {
data, err = codec.EncodeValue(nil, r...)
if err != nil {
return errors.Trace(err)
}
mutation.DeletedRows = append(mutation.DeletedRows, data)
}
var data []byte
var err error
if primaryIdx != nil {
indexedValues := make([]types.Datum, len(primaryIdx.Columns))
for i := range indexedValues {
indexedValues[i] = r[primaryIdx.Columns[i].Offset]
}
data, err = codec.EncodeKey(nil, indexedValues...)
if err != nil {
return errors.Trace(err)
}
mutation.DeletedPks = append(mutation.DeletedPks, data)
} else {
data, err = codec.EncodeValue(nil, r...)
if err != nil {
return errors.Trace(err)
}
mutation.DeletedRows = append(mutation.DeletedRows, data)
}
}
return nil
Expand Down

0 comments on commit f4c066f

Please sign in to comment.