update replication

This commit is contained in:
siddontang 2014-10-22 20:54:37 +08:00
parent 4bf22615cf
commit 041a1737c8
1 changed files with 12 additions and 4 deletions

View File

@ -384,7 +384,9 @@ func (app *App) publishNewLog(l *rpl.Log) {
app.slock.Lock() app.slock.Lock()
total := (len(app.slaves) + 1) / 2 slaveNum := len(app.slaves)
total := (slaveNum + 1) / 2
if app.cfg.Replication.WaitMaxSlaveAcks > 0 { if app.cfg.Replication.WaitMaxSlaveAcks > 0 {
total = num.MinInt(total, app.cfg.Replication.WaitMaxSlaveAcks) total = num.MinInt(total, app.cfg.Replication.WaitMaxSlaveAcks)
} }
@ -409,15 +411,21 @@ func (app *App) publishNewLog(l *rpl.Log) {
startTime := time.Now() startTime := time.Now()
done := make(chan struct{}, 1) done := make(chan struct{}, 1)
go func(total int) { go func() {
for i := 0; i < total; i++ { n := 0
for i := 0; i < slaveNum; i++ {
id := <-app.slaveSyncAck id := <-app.slaveSyncAck
if id < logId { if id < logId {
log.Info("some slave may close with last logid %d < %d", id, logId) log.Info("some slave may close with last logid %d < %d", id, logId)
} else {
n++
if n >= total {
break
}
} }
} }
done <- struct{}{} done <- struct{}{}
}(total) }()
select { select {
case <-done: case <-done: