Skip to content

Commit

Permalink
tracker(dm): add task name to unistore folder name (#5341)
Browse files Browse the repository at this point in the history
ref #5334
  • Loading branch information
lance6716 authored May 10, 2022
1 parent 3ecf202 commit 57c19c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dm/pkg/schema/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -149,7 +150,7 @@ func NewTracker(ctx context.Context, task string, sessionCfg map[string]string,
}
}

storePath, err = ioutil.TempDir("./", "schema-tracker")
storePath, err = newTmpFolderForTracker(task)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -234,6 +235,10 @@ func NewTracker(ctx context.Context, task string, sessionCfg map[string]string,
}, nil
}

func newTmpFolderForTracker(task string) (string, error) {
return ioutil.TempDir("./", url.PathEscape(task)+"-tracker")
}

// Exec runs an SQL (DDL) statement.
func (tr *Tracker) Exec(ctx context.Context, db string, sql string) error {
tr.se.GetSessionVars().CurrentDB = db
Expand Down
10 changes: 10 additions & 0 deletions dm/pkg/schema/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"os"
"sort"
"testing"
"time"
Expand Down Expand Up @@ -1027,3 +1028,12 @@ func TestTrackerRecreateTables(t *testing.T) {
require.Equal(t, tiInfos[i], cloneTi)
}
}

func TestNewTmpFolderForTracker(t *testing.T) {
got, err := newTmpFolderForTracker("task/db01")
require.NoError(t, err)
require.Contains(t, got, "task%2Fdb01")
require.DirExists(t, got)
err = os.RemoveAll(got)
require.NoError(t, err)
}
8 changes: 6 additions & 2 deletions dm/syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,10 @@ func (s *testSyncerSuite) TestTrackDDL(c *C) {
syncer.ddlDBConn = dbconn.NewDBConn(s.cfg, conn.NewBaseConn(dbConn, &retry.FiniteRetryStrategy{}))
syncer.checkpoint.(*RemoteCheckPoint).dbConn = dbconn.NewDBConn(s.cfg, conn.NewBaseConn(checkPointDBConn, &retry.FiniteRetryStrategy{}))
syncer.schemaTracker, err = schema.NewTracker(context.Background(), s.cfg.Name, defaultTestSessionCfg, syncer.ddlDBConn)
c.Assert(err, IsNil)
defer syncer.schemaTracker.Close()
syncer.exprFilterGroup = NewExprFilterGroup(utils.NewSessionCtx(nil), nil)
c.Assert(syncer.genRouter(), IsNil)
c.Assert(err, IsNil)

cases := []struct {
sql string
Expand Down Expand Up @@ -1579,6 +1580,7 @@ func (s *testSyncerSuite) TestTrackDownstreamTableWontOverwrite(c *C) {
syncer.downstreamTrackConn = dbconn.NewDBConn(s.cfg, conn.NewBaseConn(dbConn, &retry.FiniteRetryStrategy{}))
syncer.schemaTracker, err = schema.NewTracker(ctx, s.cfg.Name, defaultTestSessionCfg, syncer.downstreamTrackConn)
c.Assert(err, IsNil)
defer syncer.schemaTracker.Close()

upTable := &filter.Table{
Schema: "test",
Expand Down Expand Up @@ -1660,8 +1662,10 @@ func (s *testSyncerSuite) TestDownstreamTableHasAutoRandom(c *C) {
"tidb_skip_utf8_check": "0",
schema.TiDBClusteredIndex: "ON",
}
c.Assert(syncer.schemaTracker.Close(), IsNil)
syncer.schemaTracker, err = schema.NewTracker(ctx, s.cfg.Name, sessionCfg, syncer.downstreamTrackConn)
c.Assert(err, IsNil)
defer syncer.schemaTracker.Close()
v, ok := syncer.schemaTracker.GetSystemVar(schema.TiDBClusteredIndex)
c.Assert(v, Equals, "ON")
c.Assert(ok, IsTrue)
Expand Down Expand Up @@ -1839,8 +1843,8 @@ func TestSyncerGetTableInfo(t *testing.T) {
syncer.ddlDBConn = dbconn.NewDBConn(cfg, baseConn)
syncer.downstreamTrackConn = dbconn.NewDBConn(cfg, conn.NewBaseConn(dbConn, &retry.FiniteRetryStrategy{}))
syncer.schemaTracker, err = schema.NewTracker(ctx, cfg.Name, defaultTestSessionCfg, syncer.downstreamTrackConn)
defer syncer.schemaTracker.Close()
require.NoError(t, err)
defer syncer.schemaTracker.Close()

upTable := &filter.Table{
Schema: "test",
Expand Down

0 comments on commit 57c19c8

Please sign in to comment.