From f4c066fafa42c20d5d0d8728bc98f9a54d84ec15 Mon Sep 17 00:00:00 2001 From: Ewan Chou Date: Thu, 1 Sep 2016 10:29:13 +0800 Subject: [PATCH] *: address comment --- sessionctx/binloginfo/binloginfo.go | 5 ++- table/tables/tables.go | 60 ++++++++++++++++------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/sessionctx/binloginfo/binloginfo.go b/sessionctx/binloginfo/binloginfo.go index 860cbed4929d5..00ceb7f747d87 100644 --- a/sessionctx/binloginfo/binloginfo.go +++ b/sessionctx/binloginfo/binloginfo.go @@ -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 ( diff --git a/table/tables/tables.go b/table/tables/tables.go index 46f52de2e9967..f042338016703 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -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