mirror of
https://gitee.com/he3db/he3pg.git
synced 2024-11-30 03:07:37 +08:00
Optimize the vonvert of tikv key and s3 filename for hbr
This commit is contained in:
parent
a6d4b84d4e
commit
44f96581e3
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
@ -65,7 +66,6 @@ func runBackup(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
snapshot := client.GetSnapshot(ts)
|
snapshot := client.GetSnapshot(ts)
|
||||||
|
|
||||||
//iter, err := snapshot.Iter([]byte("foo"), []byte("foo2"))
|
|
||||||
iter, err := snapshot.Iter([]byte(""), []byte(""))
|
iter, err := snapshot.Iter([]byte(""), []byte(""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Iter Error!\n%v\n", err)
|
fmt.Printf("Iter Error!\n%v\n", err)
|
||||||
@ -74,7 +74,14 @@ func runBackup(cmd *cobra.Command, args []string) {
|
|||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for iter.Valid() {
|
for iter.Valid() {
|
||||||
k, v := iter.Key(), iter.Value()
|
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 {
|
if err := iter.Next(); err != nil {
|
||||||
fmt.Printf("Iter Next Error!\n%v\n", err)
|
fmt.Printf("Iter Next Error!\n%v\n", err)
|
||||||
return
|
return
|
||||||
@ -82,7 +89,7 @@ func runBackup(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
_, err = s3_client.PutObject(&s3.PutObjectInput{
|
_, err = s3_client.PutObject(&s3.PutObjectInput{
|
||||||
Bucket: aws.String(bucket), // bucket名称
|
Bucket: aws.String(bucket), // bucket名称
|
||||||
Key: aws.String(backup_name + "/" + string(k)),
|
Key: aws.String(backup_name + "/" + fileneme),
|
||||||
Body: bytes.NewReader(v),
|
Body: bytes.NewReader(v),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
//"bufio"
|
//"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"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)
|
fmt.Printf("Tikv Transaction Begin Error!\n%v\n", err)
|
||||||
return
|
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)
|
fmt.Printf("Tikv Set Error!\n%v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user