Skip to content

Commit

Permalink
add replicas support for frontend in bare-metal mode (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: sh2 <[email protected]>
  • Loading branch information
shawnh2 authored Aug 3, 2023
1 parent 4151288 commit 07caf14
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
39 changes: 25 additions & 14 deletions pkg/deployer/baremetal/component/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type frontend struct {
wg *sync.WaitGroup
logger logger.Logger

frontendDirs []string
frontendLogDirs []string
frontendPidDirs []string
}

func newFrontend(config *config.Frontend, metaSrvAddr string, workDirs WorkDirs, wg *sync.WaitGroup, logger logger.Logger) BareMetalClusterComponent {
Expand All @@ -47,20 +48,24 @@ func newFrontend(config *config.Frontend, metaSrvAddr string, workDirs WorkDirs,
}

func (f *frontend) Start(ctx context.Context, binary string) error {
var (
frontendLogDir = path.Join(f.workDirs.LogsDir, "frontend")
frontendPidDir = path.Join(f.workDirs.PidsDir, "frontend")
frontendDirs = []string{frontendLogDir, frontendPidDir}
)
for _, dir := range frontendDirs {
if err := utils.CreateDirIfNotExists(dir); err != nil {
for i := 0; i < f.config.Replicas; i++ {
dirName := fmt.Sprintf("frontend.%d", i)

frontendLogDir := path.Join(f.workDirs.LogsDir, dirName)
if err := utils.CreateDirIfNotExists(frontendLogDir); err != nil {
return err
}
}
f.frontendDirs = frontendDirs
f.frontendLogDirs = append(f.frontendLogDirs, frontendLogDir)

if err := runBinary(ctx, binary, f.BuildArgs(ctx), frontendLogDir, frontendPidDir, f.wg, f.logger); err != nil {
return err
frontendPidDir := path.Join(f.workDirs.PidsDir, dirName)
if err := utils.CreateDirIfNotExists(frontendPidDir); err != nil {
return err
}
f.frontendPidDirs = append(f.frontendPidDirs, frontendPidDir)

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

return nil
Expand All @@ -85,11 +90,17 @@ func (f *frontend) IsRunning(ctx context.Context) bool {
}

func (f *frontend) Delete(ctx context.Context) error {
for _, dir := range f.frontendDirs {
for _, dir := range f.frontendLogDirs {
if err := utils.DeleteDirIfExists(dir); err != nil {
return err
}
}
f.frontendDirs = nil

for _, dir := range f.frontendPidDirs {
if err := utils.DeleteDirIfExists(dir); err != nil {
return err
}
}

return nil
}
4 changes: 3 additions & 1 deletion pkg/deployer/baremetal/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func DefaultConfig() *Config {
Artifact: &Artifact{
Version: DefaultGreptimeVersion,
},
Frontend: &Frontend{},
Frontend: &Frontend{
Replicas: 1,
},
MetaSrv: &MetaSrv{
StoreAddr: "127.0.0.1:2379",
ServerAddr: "0.0.0.0:3002",
Expand Down
2 changes: 2 additions & 0 deletions pkg/deployer/baremetal/config/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package config

type Frontend struct {
Replicas int `yaml:"replicas" validate:"gt=0"`

GRPCAddr string `yaml:"grpcAddr" validate:"omitempty,hostname_port"`
HTTPAddr string `yaml:"httpAddr" validate:"omitempty,hostname_port"`
PostgresAddr string `yaml:"postgresAddr" validate:"omitempty,hostname_port"`
Expand Down

0 comments on commit 07caf14

Please sign in to comment.