Skip to content

Commit

Permalink
stability: truncate multiple sst files to avoid #501
Browse files Browse the repository at this point in the history
  • Loading branch information
zyguan committed May 20, 2019
1 parent e12ac8e commit 4bd7fba
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions tests/pkg/ops/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const retryLimit = 15
const (
retryLimit = 15
maxSSTFilesToTruncate = 20
)

type TruncateOptions struct {
Namespace string
Expand Down Expand Up @@ -79,29 +82,36 @@ func (ops *TiKVOps) TruncateSSTFile(opts TruncateOptions) error {
}
}

sst := ""
ssts := make([]string, 0, maxSSTFilesToTruncate)
for k := range sstCandidates {
if len(ssts) >= maxSSTFilesToTruncate {
break
}
if strings.HasSuffix(k, ".sst") && !sstCandidates[k+".save"] {
sst = k
ssts = append(ssts, k)
}
}
if len(sst) == 0 {
if len(ssts) == 0 {
glog.Warning(logHdr + "cannot find a sst file")
continue
}

_, stderr, err = exec("cp", sst, sst+".save")
if err != nil {
glog.Warningf(logHdr+"backup sst file: stderr=%s err=%s", stderr, err.Error())
continue
truncated := 0
for _, sst := range ssts {
_, stderr, err = exec("sh", "-c",
fmt.Sprintf("cp %s %s.save && truncate -s 0 %s", sst, sst, sst))
if err != nil {
glog.Warningf(logHdr+"truncate sst file: sst=%s stderr=%s err=%s", sst, stderr, err.Error())
continue
}
truncated++
}

_, stderr, err = exec("truncate", "-s", "0", sst)
if err != nil {
glog.Warningf(logHdr+"truncate sst file: stderr=%s err=%s", stderr, err.Error())
if truncated == 0 {
glog.Warningf(logHdr + "no sst file has been truncated")
continue
}

glog.Infof(logHdr+"%d sst files got truncated", truncated)
break
}

Expand Down

0 comments on commit 4bd7fba

Please sign in to comment.