add put and delete info back

This commit is contained in:
siddontang 2014-10-31 20:33:13 +08:00
parent b0c808e1bd
commit 0009fe83b9
2 changed files with 29 additions and 15 deletions

View File

@ -173,31 +173,33 @@ func (i *info) dumpStore(buf *bytes.Buffer) {
s := i.app.ldb.StoreStat() s := i.app.ldb.StoreStat()
getNum := s.GetNum.Get() // getNum := s.GetNum.Get()
getTotalTime := s.GetTotalTime.Get() // getTotalTime := s.GetTotalTime.Get()
gt := int64(0) // gt := int64(0)
if getNum > 0 { // if getNum > 0 {
gt = getTotalTime.Nanoseconds() / (getNum * 1e3) // gt = getTotalTime.Nanoseconds() / (getNum * 1e3)
} // }
commitNum := s.BatchCommitNum.Get() // commitNum := s.BatchCommitNum.Get()
commitTotalTime := s.BatchCommitTotalTime.Get() // commitTotalTime := s.BatchCommitTotalTime.Get()
ct := int64(0) // ct := int64(0)
if commitNum > 0 { // if commitNum > 0 {
ct = commitTotalTime.Nanoseconds() / (commitNum * 1e3) // ct = commitTotalTime.Nanoseconds() / (commitNum * 1e3)
} // }
i.dumpPairs(buf, infoPair{"name", i.app.cfg.DBName}, i.dumpPairs(buf, infoPair{"name", i.app.cfg.DBName},
infoPair{"get", s.GetNum}, infoPair{"get", s.GetNum},
infoPair{"get_missing", s.GetMissingNum}, infoPair{"get_missing", s.GetMissingNum},
infoPair{"get_per_time", fmt.Sprintf("%0.002fms", float64(gt)/1000.0)}, infoPair{"put", s.PutNum},
infoPair{"delete", s.DeleteNum},
infoPair{"get_total_time", s.GetTotalTime.Get().String()},
infoPair{"iter", s.IterNum}, infoPair{"iter", s.IterNum},
infoPair{"iter_seek", s.IterSeekNum}, infoPair{"iter_seek", s.IterSeekNum},
infoPair{"iter_close", s.IterCloseNum}, infoPair{"iter_close", s.IterCloseNum},
infoPair{"batch_commit", s.BatchCommitNum}, infoPair{"batch_commit", s.BatchCommitNum},
infoPair{"batch_commit_per_time", fmt.Sprintf("%0.002fms", float64(ct)/1000.0)}, infoPair{"batch_commit_total_time", s.BatchCommitTotalTime.Get().String()},
) )
} }

View File

@ -9,19 +9,28 @@ type WriteBatch struct {
wb driver.IWriteBatch wb driver.IWriteBatch
st *Stat st *Stat
db *DB putNum int64
deleteNum int64
db *DB
} }
func (wb *WriteBatch) Put(key []byte, value []byte) { func (wb *WriteBatch) Put(key []byte, value []byte) {
wb.putNum++
wb.wb.Put(key, value) wb.wb.Put(key, value)
} }
func (wb *WriteBatch) Delete(key []byte) { func (wb *WriteBatch) Delete(key []byte) {
wb.deleteNum++
wb.wb.Delete(key) wb.wb.Delete(key)
} }
func (wb *WriteBatch) Commit() error { func (wb *WriteBatch) Commit() error {
wb.st.BatchCommitNum.Add(1) wb.st.BatchCommitNum.Add(1)
wb.st.PutNum.Add(wb.putNum)
wb.st.DeleteNum.Add(wb.deleteNum)
wb.putNum = 0
wb.deleteNum = 0
var err error var err error
t := time.Now() t := time.Now()
if wb.db == nil || !wb.db.needSyncCommit() { if wb.db == nil || !wb.db.needSyncCommit() {
@ -36,5 +45,8 @@ func (wb *WriteBatch) Commit() error {
} }
func (wb *WriteBatch) Rollback() error { func (wb *WriteBatch) Rollback() error {
wb.putNum = 0
wb.deleteNum = 0
return wb.wb.Rollback() return wb.wb.Rollback()
} }