Skip to content

Commit

Permalink
move cache key into FileImporter
Browse files Browse the repository at this point in the history
Signed-off-by: hillium <[email protected]>
  • Loading branch information
YuJuncen committed Dec 1, 2022
1 parent 43ae7c8 commit 0d02b32
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions br/pkg/restore/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"crypto/tls"
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -101,21 +99,15 @@ type importClient struct {
tlsConf *tls.Config

keepaliveConf keepalive.ClientParameters
cacheId string
}

// NewImportClient returns a new ImporterClient.
func NewImportClient(metaClient split.SplitClient, tlsConf *tls.Config, keepaliveConf keepalive.ClientParameters) ImporterClient {
hn, err := os.Hostname()
if err != nil {
hn = strconv.Itoa(int(rand.Int63()))
}
return &importClient{
metaClient: metaClient,
clients: make(map[uint64]import_sstpb.ImportSSTClient),
tlsConf: tlsConf,
keepaliveConf: keepaliveConf,
cacheId: fmt.Sprintf("BR-%s-%d-%s", time.Now().Format("20060102150405"), rand.Int63(), hn),
}
}

Expand Down Expand Up @@ -152,7 +144,6 @@ func (ic *importClient) DownloadSST(
if err != nil {
return nil, errors.Trace(err)
}
req.StorageCacheId = ic.cacheId
return client.Download(ctx, req)
}

Expand Down Expand Up @@ -258,6 +249,8 @@ type FileImporter struct {
rawStartKey []byte
rawEndKey []byte
supportMultiIngest bool

cacheKey string
}

// NewFileImporter returns a new file importClient.
Expand All @@ -272,6 +265,7 @@ func NewFileImporter(
backend: backend,
importClient: importClient,
isRawKvMode: isRawKvMode,
cacheKey: fmt.Sprintf("BR-%s-%d", time.Now().Format("20060102150405"), rand.Int63()),
}
}

Expand Down Expand Up @@ -647,6 +641,7 @@ func (importer *FileImporter) downloadSST(
Name: file.GetName(),
RewriteRule: rule,
CipherInfo: cipher,
StorageCacheId: importer.cacheKey,
}
log.Debug("download SST",
logutil.SSTMeta(&sstMeta),
Expand Down Expand Up @@ -726,6 +721,7 @@ func (importer *FileImporter) downloadRawKVSST(
RewriteRule: rule,
IsRawKv: true,
CipherInfo: cipher,
StorageCacheId: importer.cacheKey,
}
log.Debug("download SST", logutil.SSTMeta(&sstMeta), logutil.Region(regionInfo.Region))

Expand Down

0 comments on commit 0d02b32

Please sign in to comment.