Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
confoc committed May 24, 2024
1 parent c84c1af commit 84262a5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
6 changes: 4 additions & 2 deletions 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
metastore 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().BoolVarP(&options.metastore, "memory-meta-storage", "m", 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.metastore))
if len(options.GreptimeBinVersion) > 0 {
opts = append(opts, baremetal.WithGreptimeVersion(options.GreptimeBinVersion))
}
Expand All @@ -199,7 +201,7 @@ func NewCluster(args []string, options *clusterCreateCliOptions, l logger.Logger
opts = append(opts, baremetal.WithReplaceConfig(&cfg))
}

cluster, err = baremetal.NewCluster(l, clusterName, opts...)
cluster, err = baremetal.NewCluster(l, clusterName, opts...) //ops.metastore
if err != nil {
return err
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/cluster/baremetal/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Cluster struct {
config *config.BareMetalClusterConfig
createNoDirs bool
enableCache bool
metastore 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, metastore bool) *ClusterComponents {
return &ClusterComponents{
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger),
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger, metastore),
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(metastore bool) Option {
return func(c *Cluster) {
c.metastore = metastore
}
}

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.metastore)

return c, nil
}
8 changes: 5 additions & 3 deletions pkg/cluster/baremetal/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ 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.metastore {
if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
return err
}
}
if err := withSpinner("GreptimeDB Cluster", c.createCluster); err != nil {
if err := withSpinner("GreptimeDB Cluster", c.createCluster); err != nil { //options
if err := c.Wait(ctx, true); err != nil {
return err
}
Expand Down
13 changes: 10 additions & 3 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 @@ -36,17 +37,19 @@ type metaSrv struct {
workingDirs WorkingDirs
wg *sync.WaitGroup
logger logger.Logger
metastore bool

allocatedDirs
}

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

Expand Down Expand Up @@ -75,13 +78,12 @@ 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,
logDir: metaSrvLogDir,
pidDir: metaSrvPidDir,
args: m.BuildArgs(i, bindAddr),
args: m.BuildArgs(i, bindAddr), //如果我传进来就在这里
}
if err := runBinary(ctx, stop, option, m.wg, m.logger); err != nil {
return err
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.metastore == true {
metastore := strconv.FormatBool(m.metastore)
args = GenerateAddrArg("--use-memory-store", metastore, nodeID, args)
}

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

0 comments on commit 84262a5

Please sign in to comment.