adjust replication state set

This commit is contained in:
siddontang 2015-02-11 10:13:21 +08:00
parent cbbec9d625
commit 87cbf6cefc
1 changed files with 16 additions and 2 deletions

View File

@ -34,6 +34,17 @@ const (
replConnectedState replConnectedState
) )
type syncBuffer struct {
m *master
bytes.Buffer
}
func (b *syncBuffer) Write(data []byte) (int, error) {
b.m.state.Set(replSyncState)
n, err := b.Buffer.Write(data)
return n, err
}
type master struct { type master struct {
sync.Mutex sync.Mutex
@ -47,7 +58,7 @@ type master struct {
wg sync.WaitGroup wg sync.WaitGroup
syncBuf bytes.Buffer syncBuf syncBuffer
state sync2.AtomicInt32 state sync2.AtomicInt32
} }
@ -57,6 +68,7 @@ func newMaster(app *App) *master {
m.app = app m.app = app
m.quit = make(chan struct{}, 1) m.quit = make(chan struct{}, 1)
m.syncBuf = syncBuffer{m: m}
m.state.Set(replConnectState) m.state.Set(replConnectState)
@ -255,7 +267,7 @@ func (m *master) sync() error {
return err return err
} }
m.state.Set(replSyncState) m.state.Set(replConnectedState)
m.syncBuf.Reset() m.syncBuf.Reset()
@ -271,6 +283,8 @@ func (m *master) sync() error {
} }
} }
m.state.Set(replConnectedState)
buf := m.syncBuf.Bytes() buf := m.syncBuf.Bytes()
if len(buf) < 8 { if len(buf) < 8 {