wal: report when wal is ready
in this way the wal instance will be used only after it's ready (initialized etcd when needed)
This commit is contained in:
parent
d13fe43e19
commit
65c425b22b
|
@ -95,8 +95,13 @@ func NewConfigStore(ctx context.Context, c *config.ConfigStore) (*ConfigStore, e
|
||||||
|
|
||||||
func (s *ConfigStore) Run(ctx context.Context) error {
|
func (s *ConfigStore) Run(ctx context.Context) error {
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
|
walReadyCh := make(chan struct{})
|
||||||
|
|
||||||
|
go func() { errCh <- s.wal.Run(ctx, walReadyCh) }()
|
||||||
|
|
||||||
|
// wait for wal to be ready
|
||||||
|
<-walReadyCh
|
||||||
|
|
||||||
go func() { errCh <- s.wal.Run(ctx) }()
|
|
||||||
go func() { errCh <- s.readDB.Run(ctx) }()
|
go func() { errCh <- s.readDB.Run(ctx) }()
|
||||||
|
|
||||||
// noop coors handler
|
// noop coors handler
|
||||||
|
|
|
@ -1193,8 +1193,14 @@ func NewScheduler(ctx context.Context, c *config.RunServiceScheduler) (*Schedule
|
||||||
|
|
||||||
func (s *Scheduler) Run(ctx context.Context) error {
|
func (s *Scheduler) Run(ctx context.Context) error {
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
|
walReadyCh := make(chan struct{})
|
||||||
|
|
||||||
|
go func() { errCh <- s.wal.Run(ctx, walReadyCh) }()
|
||||||
|
|
||||||
|
// wait for wal to be ready
|
||||||
|
<-walReadyCh
|
||||||
|
|
||||||
|
|
||||||
go func() { errCh <- s.wal.Run(ctx) }()
|
|
||||||
go s.readDB.Run(ctx)
|
go s.readDB.Run(ctx)
|
||||||
|
|
||||||
ch := make(chan *types.ExecutorTask)
|
ch := make(chan *types.ExecutorTask)
|
||||||
|
|
|
@ -1241,8 +1241,7 @@ func NewWalManager(ctx context.Context, logger *zap.Logger, conf *WalManagerConf
|
||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WalManager) Run(ctx context.Context) error {
|
func (w *WalManager) Run(ctx context.Context, readyCh chan struct{}) error {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := w.InitEtcd(ctx)
|
err := w.InitEtcd(ctx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1252,6 +1251,8 @@ func (w *WalManager) Run(ctx context.Context) error {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readyCh <- struct{}{}
|
||||||
|
|
||||||
go w.watcherLoop(ctx)
|
go w.watcherLoop(ctx)
|
||||||
go w.syncLoop(ctx)
|
go w.syncLoop(ctx)
|
||||||
go w.checkpointLoop(ctx)
|
go w.checkpointLoop(ctx)
|
||||||
|
|
|
@ -89,8 +89,9 @@ func TestEtcdReset(t *testing.T) {
|
||||||
EtcdWalsKeepNum: 10,
|
EtcdWalsKeepNum: 10,
|
||||||
}
|
}
|
||||||
wal, err := NewWalManager(ctx, logger, walConfig)
|
wal, err := NewWalManager(ctx, logger, walConfig)
|
||||||
go wal.Run(ctx)
|
walReadyCh := make(chan struct{})
|
||||||
time.Sleep(1 * time.Second)
|
go wal.Run(ctx, walReadyCh)
|
||||||
|
<-walReadyCh
|
||||||
|
|
||||||
actions := []*Action{
|
actions := []*Action{
|
||||||
{
|
{
|
||||||
|
@ -123,8 +124,8 @@ func TestEtcdReset(t *testing.T) {
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
go wal.Run(ctx)
|
go wal.Run(ctx, walReadyCh)
|
||||||
time.Sleep(5 * time.Second)
|
<-walReadyCh
|
||||||
|
|
||||||
curObjects := []string{}
|
curObjects := []string{}
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
|
@ -178,8 +179,9 @@ func TestConcurrentUpdate(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
go wal.Run(ctx)
|
walReadyCh := make(chan struct{})
|
||||||
time.Sleep(1 * time.Second)
|
go wal.Run(ctx, walReadyCh)
|
||||||
|
<-walReadyCh
|
||||||
|
|
||||||
cgNames := []string{"changegroup01", "changegroup02"}
|
cgNames := []string{"changegroup01", "changegroup02"}
|
||||||
cgt := wal.GetChangeGroupsUpdateToken(cgNames)
|
cgt := wal.GetChangeGroupsUpdateToken(cgNames)
|
||||||
|
@ -253,8 +255,9 @@ func TestWalCleaner(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
go wal.Run(ctx)
|
walReadyCh := make(chan struct{})
|
||||||
time.Sleep(1 * time.Second)
|
go wal.Run(ctx, walReadyCh)
|
||||||
|
<-walReadyCh
|
||||||
|
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
if _, err := wal.WriteWal(ctx, actions, nil); err != nil {
|
if _, err := wal.WriteWal(ctx, actions, nil); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue