From b7cabcbb5f5ad4815145521daaada21bf00908d3 Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 18 Nov 2014 17:50:22 +0800 Subject: [PATCH] rpl optimize --- ledis/batch.go | 4 ---- rpl/rpl.go | 2 ++ rpl/store.go | 7 ++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ledis/batch.go b/ledis/batch.go index b0d04b9..171a3ea 100644 --- a/ledis/batch.go +++ b/ledis/batch.go @@ -104,10 +104,6 @@ func (l *Ledis) handleCommit(g commitDataGetter, c commiter) error { var err error if l.r != nil { - if b, _ := l.r.CommitIDBehind(); b { - return ErrWriteInROnly - } - var rl *rpl.Log if rl, err = l.r.Log(g.Data()); err != nil { log.Fatal("write wal error %s", err.Error()) diff --git a/rpl/rpl.go b/rpl/rpl.go index d942b49..1e15b6f 100644 --- a/rpl/rpl.go +++ b/rpl/rpl.go @@ -124,6 +124,8 @@ func (r *Replication) Log(data []byte) (*Log, error) { commitId := r.commitID if lastID < commitId { lastID = commitId + } else if lastID > commitId { + return nil, ErrCommitIDBehind } l := new(Log) diff --git a/rpl/store.go b/rpl/store.go index 7af9b0a..9f985ec 100644 --- a/rpl/store.go +++ b/rpl/store.go @@ -9,9 +9,10 @@ const ( ) var ( - ErrLogNotFound = errors.New("log not found") - ErrStoreLogID = errors.New("log id is less") - ErrNoBehindLog = errors.New("no behind commit log") + ErrLogNotFound = errors.New("log not found") + ErrStoreLogID = errors.New("log id is less") + ErrNoBehindLog = errors.New("no behind commit log") + ErrCommitIDBehind = errors.New("commit id is behind last log id") ) type LogStore interface {