Skip to content

Commit

Permalink
refactor: update some naming nits
Browse files Browse the repository at this point in the history
Signed-off-by: sh2 <[email protected]>
  • Loading branch information
shawnh2 committed Aug 3, 2023
1 parent ac84693 commit 06e6ab4
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 63 deletions.
24 changes: 12 additions & 12 deletions pkg/deployer/baremetal/component/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (

// BareMetalCluster describes all the components need to be deployed under bare-metal mode.
type BareMetalCluster struct {
MetaSrv BareMetalClusterComponent
DataNodes BareMetalClusterComponent
Frontend BareMetalClusterComponent
Etcd BareMetalClusterComponent
MetaSrv BareMetalClusterComponent
Datanode BareMetalClusterComponent
Frontend BareMetalClusterComponent
Etcd BareMetalClusterComponent
}

// BareMetalClusterComponent is the basic unit of running GreptimeDB Cluster in bare-metal mode.
Expand All @@ -52,17 +52,17 @@ type BareMetalClusterComponent interface {
}

func NewGreptimeDBCluster(config *config.Cluster, dataDir, logsDir, pidsDir string,
wait *sync.WaitGroup, logger logger.Logger) *BareMetalCluster {
wg *sync.WaitGroup, logger logger.Logger) *BareMetalCluster {
return &BareMetalCluster{
MetaSrv: newMetaSrv(config.Meta, logsDir, pidsDir, wait, logger),
DataNodes: newDataNodes(config.Datanode, config.Meta.ServerAddr, dataDir, logsDir, pidsDir, wait, logger),
Frontend: newFrontend(config.Frontend, config.Meta.ServerAddr, logsDir, pidsDir, wait, logger),
Etcd: newEtcd(dataDir, logsDir, pidsDir, wait, logger),
MetaSrv: newMetaSrv(config.MetaSrv, logsDir, pidsDir, wg, logger),
Datanode: newDataNodes(config.Datanode, config.MetaSrv.ServerAddr, dataDir, logsDir, pidsDir, wg, logger),
Frontend: newFrontend(config.Frontend, config.MetaSrv.ServerAddr, logsDir, pidsDir, wg, logger),
Etcd: newEtcd(dataDir, logsDir, pidsDir, wg, logger),
}
}

func runBinary(ctx context.Context, binary string, args []string, logDir string, pidDir string,
wait *sync.WaitGroup, logger logger.Logger) error {
wg *sync.WaitGroup, logger logger.Logger) error {
cmd := exec.CommandContext(ctx, binary, args...)

// output to binary.
Expand Down Expand Up @@ -94,8 +94,8 @@ func runBinary(ctx context.Context, binary string, args []string, logDir string,
}

go func() {
defer wait.Done()
wait.Add(1)
defer wg.Done()
wg.Add(1)
if err := cmd.Wait(); err != nil {
// Caught signal kill and interrupt error then ignore.
if exit, ok := err.(*exec.ExitError); ok {
Expand Down
20 changes: 10 additions & 10 deletions pkg/deployer/baremetal/component/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import (
"github.com/GreptimeTeam/gtctl/pkg/utils"
)

type dataNodes struct {
type datanode struct {
config *config.Datanode
metaSrvAddr string

dataDir string
logsDir string
pidsDir string
wait *sync.WaitGroup
wg *sync.WaitGroup
logger logger.Logger

dataHome string
Expand All @@ -46,19 +46,19 @@ type dataNodes struct {
}

func newDataNodes(config *config.Datanode, metaSrvAddr, dataDir, logsDir, pidsDir string,
wait *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
return &dataNodes{
wg *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
return &datanode{
config: config,
metaSrvAddr: metaSrvAddr,
dataDir: dataDir,
logsDir: logsDir,
pidsDir: pidsDir,
wait: wait,
wg: wg,
logger: logger,
}
}

func (d *dataNodes) Start(ctx context.Context, binary string) error {
func (d *datanode) Start(ctx context.Context, binary string) error {
dataHome := path.Join(d.dataDir, "home")
if err := utils.CreateDirIfNotExists(dataHome); err != nil {
return err
Expand Down Expand Up @@ -86,7 +86,7 @@ func (d *dataNodes) Start(ctx context.Context, binary string) error {
}
d.dataNodeDataDirs = append(d.dataNodeDataDirs, path.Join(d.dataDir, dirName))

if err := runBinary(ctx, binary, d.BuildArgs(ctx, i, walDir), datanodeLogDir, datanodePidDir, d.wait, d.logger); err != nil {
if err := runBinary(ctx, binary, d.BuildArgs(ctx, i, walDir), datanodeLogDir, datanodePidDir, d.wg, d.logger); err != nil {
return err
}
}
Expand All @@ -110,7 +110,7 @@ CHECKER:
return nil
}

func (d *dataNodes) BuildArgs(ctx context.Context, params ...interface{}) []string {
func (d *datanode) BuildArgs(ctx context.Context, params ...interface{}) []string {
logLevel := d.config.LogLevel
if logLevel == "" {
logLevel = "info"
Expand All @@ -132,7 +132,7 @@ func (d *dataNodes) BuildArgs(ctx context.Context, params ...interface{}) []stri
return args
}

func (d *dataNodes) IsRunning(ctx context.Context) bool {
func (d *datanode) IsRunning(ctx context.Context) bool {
for i := 0; i < d.config.Replicas; i++ {
addr := generateDatanodeAddr(d.config.HTTPAddr, i)
_, httpPort, err := net.SplitHostPort(addr)
Expand All @@ -159,7 +159,7 @@ func (d *dataNodes) IsRunning(ctx context.Context) bool {
return true
}

func (d *dataNodes) Delete(ctx context.Context) error {
func (d *datanode) Delete(ctx context.Context) error {
if err := utils.DeleteDirIfExists(d.dataHome); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/deployer/baremetal/component/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ type etcd struct {
dataDir string
logsDir string
pidsDir string
wait *sync.WaitGroup
wg *sync.WaitGroup
logger logger.Logger

etcdDirs []string
}

func newEtcd(dataDir, logsDir, pidsDir string,
wait *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
wg *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
return &etcd{
dataDir: dataDir,
logsDir: logsDir,
pidsDir: pidsDir,
wait: wait,
wg: wg,
logger: logger,
}
}
Expand All @@ -58,7 +58,7 @@ func (e *etcd) Start(ctx context.Context, binary string) error {
}
e.etcdDirs = etcdDirs

if err := runBinary(ctx, binary, e.BuildArgs(ctx, etcdDataDir), etcdLogDir, etcdPidDir, e.wait, e.logger); err != nil {
if err := runBinary(ctx, binary, e.BuildArgs(ctx, etcdDataDir), etcdLogDir, etcdPidDir, e.wg, e.logger); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/deployer/baremetal/component/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ type frontend struct {

logsDir string
pidsDir string
wait *sync.WaitGroup
wg *sync.WaitGroup
logger logger.Logger

frontendDirs []string
}

func newFrontend(config *config.Frontend, metaSrvAddr, logsDir, pidsDir string,
wait *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
wg *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
return &frontend{
config: config,
metaSrvAddr: metaSrvAddr,
logsDir: logsDir,
pidsDir: pidsDir,
wait: wait,
wg: wg,
logger: logger,
}
}
Expand All @@ -62,7 +62,7 @@ func (f *frontend) Start(ctx context.Context, binary string) error {
}
f.frontendDirs = frontendDirs

if err := runBinary(ctx, binary, f.BuildArgs(ctx), frontendLogDir, frontendPidDir, f.wait, f.logger); err != nil {
if err := runBinary(ctx, binary, f.BuildArgs(ctx), frontendLogDir, frontendPidDir, f.wg, f.logger); err != nil {
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ import (
)

type metaSrv struct {
config *config.Meta
config *config.MetaSrv

logsDir string
pidsDir string
wait *sync.WaitGroup
wg *sync.WaitGroup
logger logger.Logger

metaSrvDirs []string
}

func newMetaSrv(config *config.Meta, logsDir, pidsDir string,
wait *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
func newMetaSrv(config *config.MetaSrv, logsDir, pidsDir string,
wg *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
return &metaSrv{
config: config,
logsDir: logsDir,
pidsDir: pidsDir,
wait: wait,
wg: wg,
logger: logger,
}
}
Expand All @@ -63,7 +63,7 @@ func (m *metaSrv) Start(ctx context.Context, binary string) error {
}
m.metaSrvDirs = metaSrvDirs

if err := runBinary(ctx, binary, m.BuildArgs(ctx), metaSrvLogDir, metaSrvPidDir, m.wait, m.logger); err != nil {
if err := runBinary(ctx, binary, m.BuildArgs(ctx), metaSrvLogDir, metaSrvPidDir, m.wg, m.logger); err != nil {
return err
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/deployer/baremetal/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

package config

const (
// GtctlDir is the root directory that contains states of cluster info.
GtctlDir = ".gtctl"

DefaultEtcdVersion = "v3.5.7"
DefaultGreptimeVersion = "latest"
)

// Config is the desired state of a GreptimeDB cluster on bare metal.
//
// The field of Config that with `validate` tag will be validated
Expand All @@ -28,7 +36,7 @@ type Config struct {
type Cluster struct {
Artifact *Artifact `yaml:"artifact" validate:"required"`
Frontend *Frontend `yaml:"frontend" validate:"required"`
Meta *Meta `yaml:"meta" validate:"required"`
MetaSrv *MetaSrv `yaml:"meta" validate:"required"`
Datanode *Datanode `yaml:"datanode" validate:"required"`
}

Expand All @@ -48,7 +56,7 @@ func DefaultConfig() *Config {
Version: DefaultGreptimeVersion,
},
Frontend: &Frontend{},
Meta: &Meta{
MetaSrv: &MetaSrv{
StoreAddr: "127.0.0.1:2379",
ServerAddr: "0.0.0.0:3002",
HTTPAddr: "0.0.0.0:14001",
Expand Down
23 changes: 0 additions & 23 deletions pkg/deployer/baremetal/config/constants.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package config

type Meta struct {
type MetaSrv struct {
StoreAddr string `yaml:"storeAddr" validate:"hostname_port"`
ServerAddr string `yaml:"serverAddr" validate:"hostname_port"`
BindAddr string `yaml:"bindAddr" validate:"omitempty,hostname_port"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployer/baremetal/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (d *Deployer) CreateGreptimeDBCluster(ctx context.Context, clusterName stri
return err
}

if err := d.bm.DataNodes.Start(ctx, binary); err != nil {
if err := d.bm.Datanode.Start(ctx, binary); err != nil {
return err
}

Expand Down

0 comments on commit 06e6ab4

Please sign in to comment.