/
storage.go
77 lines (64 loc) · 1.75 KB
/
storage.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package lind
import (
"fmt"
_ "net/http/pprof" // for profiling
"github.com/eleme/lindb/storage"
"github.com/spf13/cobra"
)
var (
storageCfgPath = ""
storageDebug = false
)
// newStorageCmd returns a new storage-cmd
func newStorageCmd() *cobra.Command {
storageCmd := &cobra.Command{
Use: "storage",
Aliases: []string{"sto", "stor"},
Short: "The storage layer of LinDB",
}
runStorageCmd.PersistentFlags().StringVar(&storageCfgPath, "config", "",
fmt.Sprintf("storage config file path, default is %s", storage.DefaultStorageCfgFile))
runStorageCmd.PersistentFlags().BoolVar(&storageDebug, "debug", false,
"profiling Go programs with pprof")
storageCmd.AddCommand(
runStorageCmd,
initializeStorageConfigCmd,
databaseCmd,
)
return storageCmd
}
var runStorageCmd = &cobra.Command{
Use: "run",
Short: "starts the storage",
RunE: serveStorage,
}
var initializeStorageConfigCmd = &cobra.Command{
Use: "initialize-config",
Short: "initialize a new storage-config by steps",
Run: func(cmd *cobra.Command, args []string) {
// todo: @codingcrush
},
}
func serveStorage(cmd *cobra.Command, args []string) error {
ctx := newCtxWithSignals()
// start storage server
storage := storage.NewStorageRuntime(storageCfgPath)
if err := storage.Run(); err != nil {
return fmt.Errorf("run storage server error:%s", err)
}
// waiting system exit signal
<-ctx.Done()
// stop storage server
if err := storage.Stop(); err != nil {
return fmt.Errorf("stop storage server error:%s", err)
}
return nil
}
// databaseCmd provides the ability to control the database of storage
var databaseCmd = &cobra.Command{
Use: "database",
Short: "Control the database of LinDB",
Run: func(cmd *cobra.Command, args []string) {
// todo: @codingcrush
},
}