From 218700ce442355d505d682b4af083b009dc39c8a Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 14 Feb 2015 14:40:58 +0800 Subject: [PATCH] repo conf command should check replication ok --- server/cmd_replication.go | 4 ++++ server/replication.go | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server/cmd_replication.go b/server/cmd_replication.go index 9bcba86..84fc974 100644 --- a/server/cmd_replication.go +++ b/server/cmd_replication.go @@ -157,6 +157,10 @@ func replconfCommand(c *client) error { return ErrCmdParams } + if !c.app.ldb.ReplicationUsed() { + return ledis.ErrRplNotSupport + } + //now only support "listening-port" for i := 0; i < len(args); i += 2 { switch strings.ToLower(hack.String(args[i])) { diff --git a/server/replication.go b/server/replication.go index 15e3657..e86589a 100644 --- a/server/replication.go +++ b/server/replication.go @@ -76,7 +76,11 @@ func newMaster(app *App) *master { } func (m *master) Close() { - m.quit <- struct{}{} + select { + case m.quit <- struct{}{}: + default: + break + } m.closeConn() @@ -161,7 +165,12 @@ func (m *master) runReplication(restart bool) { if _, err := m.conn.Do("ping"); err != nil { log.Errorf("ping master %s error %s, try 3s later", m.addr, err.Error()) - time.Sleep(3 * time.Second) + + select { + case <-time.After(3 * time.Second): + case <-m.quit: + return + } continue } @@ -172,7 +181,17 @@ func (m *master) runReplication(restart bool) { m.state.Set(replConnectedState) if err := m.replConf(); err != nil { - log.Errorf("replconf error %s", err.Error()) + if strings.Contains(err.Error(), ledis.ErrRplNotSupport.Error()) { + log.Fatalf("master doesn't support replication, wait 10s and retry") + select { + case <-time.After(10 * time.Second): + case <-m.quit: + return + } + } else { + log.Errorf("replconf error %s", err.Error()) + } + continue }