Skip to content

Commit

Permalink
correct var name
Browse files Browse the repository at this point in the history
Signed-off-by: zhangjinpeng87 <zzzhangjinpeng@gmail.com>
  • Loading branch information
zhangjinpeng87 committed Mar 27, 2024
1 parent 6c3a92a commit 3e052d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/owner/compaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
"golang.org/x/sync/errgroup"
)

type Compaign struct {
type Campaign struct {
cfg *config.OwnerConfig

backend meta.Backend

isOwner atomic.Bool
}

func NewCompaign(cfg *config.OwnerConfig, backend meta.Backend) *Compaign {
return &Compaign{
func NewCampaign(cfg *config.OwnerConfig, backend meta.Backend) *Campaign {
return &Campaign{
cfg: cfg,
backend: backend,
isOwner: atomic.Bool{},
}
}

func (c *Compaign) Start(eg *errgroup.Group, ctx context.Context) {
func (c *Campaign) Start(eg *errgroup.Group, ctx context.Context) {
eg.Go(func() error {
serverId := fmt.Sprintf("%s:%d", c.cfg.Host, c.cfg.Port)

Expand All @@ -48,7 +48,7 @@ func (c *Compaign) Start(eg *errgroup.Group, ctx context.Context) {
}
} else {
// Try to campaign owner
success, err := c.backend.TryCompaignOwner(serverId, c.cfg.LeaseDuration)
success, err := c.backend.TryCampaignOwner(serverId, c.cfg.LeaseDuration)
if err != nil {
// log error
continue
Expand All @@ -64,6 +64,6 @@ func (c *Compaign) Start(eg *errgroup.Group, ctx context.Context) {
})
}

func (c *Compaign) IsOwner() bool {
func (c *Campaign) IsOwner() bool {
return c.isOwner.Load()
}
8 changes: 4 additions & 4 deletions pkg/owner/meta/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Backend interface {
// GetOwner returns the active owner of the tidb2dw service.
GetOwner() (string, error)

// TryCompaignOwner tries to campaign the owner of the tidb2dw service.
TryCompaignOwner(who string, leaseDurSec int) (bool, error)
// TryCampaignOwner tries to campaign the owner of the tidb2dw service.
TryCampaignOwner(who string, leaseDurSec int) (bool, error)

// RenewOwnerLease renews the lease of the owner of the tidb2dw service.
RenewOwnerLease(who string, leaseDurSec int) (bool, error)
Expand Down Expand Up @@ -99,8 +99,8 @@ func (b *RdsBackend) GetOwner() (string, error) {
return who, nil
}

// TryCompaignOwner tries to campaign the owner of the tidb2dw service.
func (b *RdsBackend) TryCompaignOwner(who string, leaseDurSec int) (bool, error) {
// TryCampaignOwner tries to campaign the owner of the tidb2dw service.
func (b *RdsBackend) TryCampaignOwner(who string, leaseDurSec int) (bool, error) {
res, err := b.db.Exec("UPDATE owner SET who = ?, lease_expire = DATE_ADD(NOW(), INTERVAL ? SECOND) WHERE id = 1 AND lease_expire < NOW()", who, leaseDurSec)
if err != nil {
return false, err
Expand Down
10 changes: 5 additions & 5 deletions pkg/owner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Server struct {

// backend
backend meta.Backend
compaign *Compaign
campaign *Campaign

// errgroup and context
eg *errgroup.Group
Expand All @@ -31,30 +31,30 @@ func NewServer(cfg *config.OwnerConfig) (*Server, error) {
if err != nil {
return nil, err
}
compaign := NewCompaign(cfg, backend)
campaign := NewCampaign(cfg, backend)

ctx, cancel := context.WithCancel(context.Background())
eg, ctx := errgroup.WithContext(ctx)
return &Server{
cfg: cfg,
grpcServer: grpcServer,
backend: backend,
compaign: compaign,
campaign: campaign,
eg: eg,
ctx: ctx,
cancel: cancel,
}, nil
}

// Prepare bootstraps the backend and starts the owner compaign.
// Prepare bootstraps the backend and starts the owner campaign.
func (s *Server) Prepare() error {
// Initialize the backend meta schema.
if err := s.backend.Bootstrap(); err != nil {
return err
}

// Start to campaign the owner.
s.compaign.Start(s.eg, s.ctx)
s.campaign.Start(s.eg, s.ctx)

// Todo:
// Register the owner service to the gRPC server.
Expand Down

0 comments on commit 3e052d6

Please sign in to comment.