func (clog *CommitLog) SetupLog(topicName string, store LogStorage) (err error) {
	clog.waitingReaders = sync.NewCond(clog.lock.RLocker())
	clog.node_log = utils.GetTopicLogger(topicName, "CommitLog")
	clog.inShutdown = false
	clog.log = store
	clog.commitIndex = 0
	clog.syncPolicy = DEFAULT_SYNC_POLICY
	if clog.syncPolicy == PERIODIC_SYNC {
		go func() {
			timer := time.NewTimer(DEFAULT_PERIODIC_SYNC_PERIOD)
			for {
				<-timer.C
				clog.log.Sync()
				timer.Reset(DEFAULT_PERIODIC_SYNC_PERIOD)
			}
		}()
	}
	return nil
}
/*
LoadLogInfo is used at startup by the Node to read in the persisted state.
PersistentLog's are expected at this point to validate their storage and determine the current state.

commitIndex is the last committed index ID.
nextIndex is the index ID for the next message to be appended to this log.
error is populated if there are any issues loadnig the persisted state that are unrecoverable from.
package commitlog
import (
	"errors"
	"github.com/owlfish/forestbus-server/model"
	"github.com/owlfish/forestbus-server/utils"
	"sync"
	"time"
)
type LogStorage interface {
	GetMessages(index int64, count int64) (model.Messages, error)
	AppendMessages(msgs model.Messages) (lastIndex int64, err error)
	AppendFirstMessages(msgs model.Messages, leaderFirstIndex int64) (lastIndex int64, err error)
	Sync() error
	GetLastIndex() (lastIndex int64, err error)
	GetFirstIndex() (firstIndex int64, err error)
	TruncateMessages(index int64) error
	ExpVar() interface{}
	Shutdown(notifier *utils.ShutdownNotifier)
}
const MAX_MESSAGE_RESULTS = 500
const MAX_RETRIEVE_MESSAGE_COUNT = 2500
type DiskSyncPolicy int
const (
	WRITE_SYNC DiskSyncPolicy = iota
	PERIODIC_SYNC
	OSSYNC
)
const DEFAULT_SYNC_POLICY = OSSYNC
const DEFAULT_PERIODIC_SYNC_PERIOD = 5 * time.Second
type CommitLog struct {
	lock sync.RWMutex
	commitIndex int64
	waitingReaders *sync.Cond
	log LogStorage
	syncPolicy DiskSyncPolicy
	node_log utils.PrintFFunc
	inShutdown bool
}
type CommitLogInfo struct {
	LastCommittedID int64
	Storage         interface{}
}