/
ingest_sst.go
executable file
·60 lines (54 loc) · 1.64 KB
/
ingest_sst.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package client
import (
"fmt"
"github.com/linxGnu/grocksdb"
"github.com/spf13/cobra"
"github.com/swag-eag/swa/versiondb/tsrocksdb"
)
func IngestVersionDBSSTCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "ingest-versiondb-sst versiondb-path [file1.sst file2.sst ...]",
Short: "Ingest sst files into versiondb and update the latest version",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
dbPath := args[0]
moveFiles, err := cmd.Flags().GetBool(flagMoveFiles)
if err != nil {
return err
}
db, cfHandle, err := tsrocksdb.OpenVersionDB(dbPath)
if err != nil {
return err
}
if len(args) > 1 {
ingestOpts := grocksdb.NewDefaultIngestExternalFileOptions()
ingestOpts.SetMoveFiles(moveFiles)
if err := db.IngestExternalFileCF(cfHandle, args[1:], ingestOpts); err != nil {
return err
}
}
maxVersion, err := cmd.Flags().GetInt64(flagMaximumVersion)
if err != nil {
return err
}
if maxVersion > 0 {
// update latest version
store := tsrocksdb.NewStoreWithDB(db, cfHandle)
latestVersion, err := store.GetLatestVersion()
if err != nil {
return err
}
if maxVersion > latestVersion {
fmt.Println("update latest version to", maxVersion)
if err := store.SetLatestVersion(maxVersion); err != nil {
return err
}
}
}
return nil
},
}
cmd.Flags().Bool(flagMoveFiles, false, "move sst files instead of copy them")
cmd.Flags().Int64(flagMaximumVersion, 0, "Specify the maximum version covered by the ingested files, if it's bigger than existing recorded latest version, will update it.")
return cmd
}