Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
cdclog: fix lost delete (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer authored May 6, 2021
1 parent b1ed365 commit e3ca195
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"sort"

"github.com/pingcap/errors"
sst "github.com/pingcap/kvproto/pkg/import_sstpb"
"github.com/pingcap/log"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
Expand Down Expand Up @@ -57,6 +58,10 @@ type Iter interface {
Value() []byte
// Close close this iter.
Close() error
// OpType represents operations of pair. currently we have two types.
// 1. Put
// 2. Delete
OpType() sst.Pair_OP
}

// IterProducer produces iterator with given range.
Expand Down Expand Up @@ -171,6 +176,14 @@ func (s *SimpleKVIter) Close() error {
return nil
}

// OpType implements Iter.KeyIsDelete.
func (s *SimpleKVIter) OpType() sst.Pair_OP {
if s.Valid() && s.pairs[s.index].IsDelete {
return sst.Pair_Delete
}
return sst.Pair_Put
}

// Encoder encodes a row of SQL values into some opaque type which can be
// consumed by OpenEngine.WriteEncoded.
type Encoder interface {
Expand Down
1 change: 1 addition & 0 deletions pkg/restore/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (i *Ingester) writeToTiKV(
pair := &sst.Pair{
Key: bytesBuf.AddBytes(iter.Key()),
Value: bytesBuf.AddBytes(iter.Value()),
Op: iter.OpType(),
}
pairs = append(pairs, pair)
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/br_log_restore/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ if [ "$row_count" -ne "1" ]; then
echo "TEST: [$TEST_NAME] fail on recover ts range test."
fi

# record a=3 should be deleted
row_count=$(run_sql "SELECT COUNT(*) FROM ${DB}_DDL2.t2 WHERE a=3;" | awk '/COUNT/{print $2}')
if [ "$row_count" -ne "0" ]; then
fail=true
echo "TEST: [$TEST_NAME] fail on key not deleted."
fi


for i in $(seq $DB_COUNT); do
if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then
fail=true
Expand Down

0 comments on commit e3ca195

Please sign in to comment.