From 62a1a3844976d77bbfb0fad4e9f02148ab187f1e Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 11 Jan 2018 14:57:10 +0000 Subject: [PATCH] Add cli option to specify db shrink policy --- cli/flags.go | 9 +++++---- cli/start.go | 3 ++- cnf/cnf.go | 19 +++++++++++-------- kvs/rixxdb/main.go | 3 ++- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cli/flags.go b/cli/flags.go index 6ad6bcb5..04d676d2 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -15,10 +15,11 @@ package cli var flags = map[string]string{ - "db": `Database configuration path used for storing data. Available backend stores are memory, file, s3, gcs, rixxdb, or dendrodb. (default "memory").`, - "key": `Encryption key to use for intra-cluster communications, and on-disk encryption. For AES-128 encryption use a 16 bit key, for AES-192 encryption use a 24 bit key, and for AES-256 encryption use a 32 bit key.`, - "sync": `A time duration to use when syncing data to persistent storage. To sync data with every write specify '0', otherwise the data will be persisted asynchronously after the specified duration.`, - "join": `A comma-separated list of addresses to use when a new node is joining an existing cluster. For the first node in a cluster, --join should NOT be specified.`, + "db": `Database configuration path used for storing data. Available backend stores are memory, file, s3, gcs, rixxdb, or dendrodb. (default "memory").`, + "key": `Encryption key to use for intra-cluster communications, and on-disk encryption. For AES-128 encryption use a 16 bit key, for AES-192 encryption use a 24 bit key, and for AES-256 encryption use a 32 bit key.`, + "sync": `A time duration to use when syncing data to persistent storage. To sync data with every write specify '0', otherwise the data will be persisted asynchronously after the specified duration.`, + "shrink": `A time duration to use when shrinking data on persistent storage. To shrink data asynchronously after a repeating period of time, specify a duration.`, + "join": `A comma-separated list of addresses to use when a new node is joining an existing cluster. For the first node in a cluster, --join should NOT be specified.`, } var usage = map[string][]string{ diff --git a/cli/start.go b/cli/start.go index 799650a9..62ba810d 100644 --- a/cli/start.go +++ b/cli/start.go @@ -94,7 +94,8 @@ func init() { startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Crt, "db-crt", "", "Path to the certificate file used to connect to the remote database.") startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Key, "db-key", "", "Path to the private key file used to connect to the remote database.") startCmd.PersistentFlags().StringVar(&opts.DB.Path, "db-path", "", flag("db")) - startCmd.PersistentFlags().DurationVar(&opts.DB.Time, "db-sync", 0, flag("sync")) + startCmd.PersistentFlags().DurationVar(&opts.DB.Proc.Sync, "db-sync", 0, flag("sync")) + startCmd.PersistentFlags().DurationVar(&opts.DB.Proc.Shrink, "db-shrink", 0, flag("shrink")) startCmd.PersistentFlags().StringSliceVarP(&opts.Node.Join, "join", "j", nil, flag("join")) diff --git a/cnf/cnf.go b/cnf/cnf.go index 26ba2b2d..4dac4ac8 100644 --- a/cnf/cnf.go +++ b/cnf/cnf.go @@ -76,14 +76,17 @@ type Auth struct { // Options defines global configuration options type Options struct { DB struct { - Key []byte // Data encryption key - Code string // Data encryption key string - Path string // Path to store the data file - Type string // HTTP scheme type to use - Host string // Surreal host to connect to - Port string // Surreal port to connect to - Base string // Base key to use in KV stores - Time time.Duration // Timeframe for syncing data + Key []byte // Data encryption key + Code string // Data encryption key string + Path string // Path to store the data file + Type string // HTTP scheme type to use + Host string // Surreal host to connect to + Port string // Surreal port to connect to + Base string // Base key to use in KV stores + Proc struct { + Sync time.Duration // Timeframe for syncing data + Shrink time.Duration // Timeframe for shrinking data + } Cert struct { CA string Crt string diff --git a/kvs/rixxdb/main.go b/kvs/rixxdb/main.go index 278711a0..5af271d4 100644 --- a/kvs/rixxdb/main.go +++ b/kvs/rixxdb/main.go @@ -31,7 +31,8 @@ func init() { path := strings.TrimPrefix(opts.DB.Path, "rixxdb://") pntr, err = rixxdb.Open(path, &rixxdb.Config{ - SyncPolicy: opts.DB.Time, + SyncPolicy: opts.DB.Proc.Sync, + ShrinkPolicy: opts.DB.Proc.Shrink, EncryptionKey: opts.DB.Key, })