Optimize the vonvert of tikv key and s3 filename for hbr

This commit is contained in:
peitingwei 2022-11-23 11:24:18 +08:00 committed by zoujia
parent a6d4b84d4e
commit 44f96581e3
2 changed files with 28 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"fmt"
"strconv"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@ -65,7 +66,6 @@ func runBackup(cmd *cobra.Command, args []string) {
}
snapshot := client.GetSnapshot(ts)
//iter, err := snapshot.Iter([]byte("foo"), []byte("foo2"))
iter, err := snapshot.Iter([]byte(""), []byte(""))
if err != nil {
fmt.Printf("Iter Error!\n%v\n", err)
@ -74,7 +74,14 @@ func runBackup(cmd *cobra.Command, args []string) {
defer iter.Close()
for iter.Valid() {
k, v := iter.Key(), iter.Value()
fmt.Printf("key:%v\tval:%v\n", string(k), string(v))
var fileneme string = ""
for ki, vi := range k {
fileneme += strconv.Itoa(int(vi))
if ki != len(k)-1 {
fileneme += "-"
}
}
fmt.Printf("fileneme:%s\tkey:%s\n", fileneme, string(k))
if err := iter.Next(); err != nil {
fmt.Printf("Iter Next Error!\n%v\n", err)
return
@ -82,7 +89,7 @@ func runBackup(cmd *cobra.Command, args []string) {
_, err = s3_client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(bucket), // bucket名称
Key: aws.String(backup_name + "/" + string(k)),
Key: aws.String(backup_name + "/" + fileneme),
Body: bytes.NewReader(v),
})
if err != nil {

View File

@ -4,6 +4,8 @@ import (
//"bufio"
"context"
"fmt"
"strconv"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@ -87,7 +89,22 @@ func runRestore(cmd *cobra.Command, args []string) {
fmt.Printf("Tikv Transaction Begin Error!\n%v\n", err)
return
}
if err := txn.Set([]byte((*keys.Key)[len(backup_name)+1:]), data); err != nil {
substrings := strings.Split((*keys.Key)[len(backup_name)+1:], "-")
var tiKey []byte = make([]byte, len(substrings))
for ki, vi := range substrings {
temK, err := strconv.Atoi(vi)
if err != nil {
fmt.Printf("Strconv.Atoi Error!\n%v\n", err)
return
}
tiKey[ki] = byte(temK)
}
fmt.Printf("fileneme:%s\ttikey:%v\n", (*keys.Key)[len(backup_name)+1:], tiKey)
if err := txn.Set(tiKey, data); err != nil {
fmt.Printf("Tikv Set Error!\n%v\n", err)
return
}