Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the new option --memory-meta-storage #200

Merged
merged 18 commits into from
May 28, 2024
4 changes: 3 additions & 1 deletion cmd/gtctl/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type clusterCreateCliOptions struct {
Config string
GreptimeBinVersion string
EnableCache bool
UseMemoryMeta bool

// Common options.
Timeout int
Expand Down Expand Up @@ -109,6 +110,7 @@ func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
cmd.Flags().StringVar(&options.GreptimeDBClusterValuesFile, "greptimedb-cluster-values-file", "", "The values file for greptimedb cluster.")
cmd.Flags().StringVar(&options.EtcdClusterValuesFile, "etcd-cluster-values-file", "", "The values file for etcd cluster.")
cmd.Flags().StringVar(&options.GreptimeDBOperatorValuesFile, "greptimedb-operator-values-file", "", "The values file for greptimedb operator.")
cmd.Flags().BoolVar(&options.UseMemoryMeta, "use-memory-meta", false, "Bootstrap the whole cluster without installing etcd for testing purposes through using the memory storage of metasrv in bare-metal mode.")

return cmd
}
Expand Down Expand Up @@ -182,7 +184,7 @@ func NewCluster(args []string, options *clusterCreateCliOptions, l logger.Logger
l.V(0).Infof("Creating GreptimeDB cluster '%s' on bare-metal", logger.Bold(clusterName))

var opts []baremetal.Option
opts = append(opts, baremetal.WithEnableCache(options.EnableCache))
opts = append(opts, baremetal.WithEnableCache(options.EnableCache), baremetal.WithMetastore(options.UseMemoryMeta))
if len(options.GreptimeBinVersion) > 0 {
opts = append(opts, baremetal.WithGreptimeVersion(options.GreptimeBinVersion))
}
Expand Down
19 changes: 13 additions & 6 deletions pkg/cluster/baremetal/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
)

type Cluster struct {
config *config.BareMetalClusterConfig
createNoDirs bool
enableCache bool
config *config.BareMetalClusterConfig
createNoDirs bool
enableCache bool
useMemoryMeta bool

am artifacts.Manager
mm metadata.Manager
Expand All @@ -54,9 +55,9 @@ type ClusterComponents struct {
}

func NewClusterComponents(config *config.BareMetalClusterComponentsConfig, workingDirs components.WorkingDirs,
wg *sync.WaitGroup, logger logger.Logger) *ClusterComponents {
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) *ClusterComponents {
return &ClusterComponents{
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger),
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger, useMemoryMeta),
Datanode: components.NewDataNode(config.Datanode, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
Frontend: components.NewFrontend(config.Frontend, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
Etcd: components.NewEtcd(workingDirs, wg, logger),
Expand Down Expand Up @@ -84,6 +85,12 @@ func WithEnableCache(enableCache bool) Option {
}
}

func WithMetastore(useMemoryMeta bool) Option {
return func(c *Cluster) {
c.useMemoryMeta = useMemoryMeta
}
}

func WithCreateNoDirs() Option {
return func(c *Cluster) {
c.createNoDirs = true
Expand Down Expand Up @@ -136,7 +143,7 @@ func NewCluster(l logger.Logger, clusterName string, opts ...Option) (cluster.Op
DataDir: csd.DataDir,
LogsDir: csd.LogsDir,
PidsDir: csd.PidsDir,
}, &c.wg, c.logger)
}, &c.wg, c.logger, c.useMemoryMeta)

return c, nil
}
6 changes: 4 additions & 2 deletions pkg/cluster/baremetal/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
return nil
}

if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
return err
if c.useMemoryMeta {
if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
return err
}
}
if err := withSpinner("GreptimeDB Cluster", c.createCluster); err != nil {
if err := c.Wait(ctx, true); err != nil {
Expand Down
25 changes: 16 additions & 9 deletions pkg/components/metasrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"net/http"
"path"
"strconv"
"sync"
"time"

Expand All @@ -33,20 +34,22 @@ import (
type metaSrv struct {
config *config.MetaSrv

workingDirs WorkingDirs
wg *sync.WaitGroup
logger logger.Logger
workingDirs WorkingDirs
wg *sync.WaitGroup
logger logger.Logger
useMemoryMeta bool

allocatedDirs
}

func NewMetaSrv(config *config.MetaSrv, workingDirs WorkingDirs,
wg *sync.WaitGroup, logger logger.Logger) ClusterComponent {
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) ClusterComponent {
return &metaSrv{
config: config,
workingDirs: workingDirs,
wg: wg,
logger: logger,
config: config,
workingDirs: workingDirs,
wg: wg,
logger: logger,
useMemoryMeta: useMemoryMeta,
}
}

Expand Down Expand Up @@ -75,7 +78,6 @@ func (m *metaSrv) Start(ctx context.Context, stop context.CancelFunc, binary str
return err
}
m.pidsDirs = append(m.pidsDirs, metaSrvPidDir)

option := &RunOptions{
Binary: binary,
Name: dirName,
Expand Down Expand Up @@ -126,6 +128,11 @@ func (m *metaSrv) BuildArgs(params ...interface{}) []string {
args = GenerateAddrArg("--http-addr", m.config.HTTPAddr, nodeID, args)
args = GenerateAddrArg("--bind-addr", bindAddr, nodeID, args)

if m.useMemoryMeta {
useMemoryMeta := strconv.FormatBool(m.useMemoryMeta)
args = GenerateAddrArg("--use-memory-store", useMemoryMeta, nodeID, args)
}

if len(m.config.Config) > 0 {
args = append(args, fmt.Sprintf("-c=%s", m.config.Config))
}
Expand Down
Loading