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

syncer/checkpoint: ignore cancel for update/delete (#1174) #1177

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions syncer/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package syncer

import (
"bytes"
"context"
"database/sql"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -321,8 +322,11 @@ func (cp *RemoteCheckPoint) Clear(tctx *tcontext.Context) error {
defer cp.Unlock()

// delete all checkpoints
// use a new context apart from syncer, to make sure when syncer call `cancel` checkpoint could update
tctx2, cancel := tctx.WithContext(context.Background()).WithTimeout(maxDMLConnectionDuration)
defer cancel()
_, err := cp.dbConn.executeSQL(
tctx,
tctx2,
[]string{`DELETE FROM ` + cp.tableName + ` WHERE id = ?`},
[]interface{}{cp.id},
)
Expand Down Expand Up @@ -390,9 +394,12 @@ func (cp *RemoteCheckPoint) DeleteTablePoint(tctx *tcontext.Context, sourceSchem
return nil
}

// use a new context apart from syncer, to make sure when syncer call `cancel` checkpoint could update
tctx2, cancel := tctx.WithContext(context.Background()).WithTimeout(maxDMLConnectionDuration)
defer cancel()
cp.logCtx.L().Info("delete table checkpoint", zap.String("schema", sourceSchema), zap.String("table", sourceTable))
_, err := cp.dbConn.executeSQL(
tctx,
tctx2,
[]string{`DELETE FROM ` + cp.tableName + ` WHERE id = ? AND cp_schema = ? AND cp_table = ?`},
[]interface{}{cp.id, sourceSchema, sourceTable},
)
Expand All @@ -412,9 +419,12 @@ func (cp *RemoteCheckPoint) DeleteSchemaPoint(tctx *tcontext.Context, sourceSche
return nil
}

// use a new context apart from syncer, to make sure when syncer call `cancel` checkpoint could update
tctx2, cancel := tctx.WithContext(context.Background()).WithTimeout(maxDMLConnectionDuration)
defer cancel()
cp.logCtx.L().Info("delete schema checkpoint", zap.String("schema", sourceSchema))
_, err := cp.dbConn.executeSQL(
tctx,
tctx2,
[]string{`DELETE FROM ` + cp.tableName + ` WHERE id = ? AND cp_schema = ?`},
[]interface{}{cp.id, sourceSchema},
)
Expand Down Expand Up @@ -522,7 +532,10 @@ func (cp *RemoteCheckPoint) FlushPointsExcept(tctx *tcontext.Context, exceptTabl
args = append(args, extraArgs[i])
}

_, err := cp.dbConn.executeSQL(tctx, sqls, args...)
// use a new context apart from syncer, to make sure when syncer call `cancel` checkpoint could update
tctx2, cancel := tctx.WithContext(context.Background()).WithTimeout(maxDMLConnectionDuration)
defer cancel()
_, err := cp.dbConn.executeSQL(tctx2, sqls, args...)
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,7 @@ func (s *Syncer) flushCheckPoints() error {
s.tctx.L().Info("prepare flush sqls", zap.Strings("shard meta sqls", shardMetaSQLs), zap.Reflect("shard meta arguments", shardMetaArgs))
}

tctx, cancel := s.tctx.WithContext(context.Background()).WithTimeout(maxDMLConnectionDuration)
defer cancel()
err := s.checkpoint.FlushPointsExcept(tctx, exceptTables, shardMetaSQLs, shardMetaArgs)
err := s.checkpoint.FlushPointsExcept(s.tctx, exceptTables, shardMetaSQLs, shardMetaArgs)
if err != nil {
return terror.Annotatef(err, "flush checkpoint %s", s.checkpoint)
}
Expand Down