From cea1df9365fbb078607d9ce6efa68f7be4d35102 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 4 Jun 2018 13:24:40 +0200 Subject: [PATCH] Compute total db size from stats --- blockbook.go | 2 +- common/internalstate.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/blockbook.go b/blockbook.go index 77df065b..d92a4ddc 100644 --- a/blockbook.go +++ b/blockbook.go @@ -178,7 +178,7 @@ func main() { if err != nil { glog.Error("internalState: ", err) } - glog.Info("DB size on disk: ", index.DatabaseSizeOnDisk()) + glog.Info("DB size on disk: ", index.DatabaseSizeOnDisk(), ", DB size as computed: ", internalState.DBSizeTotal()) return } diff --git a/common/internalstate.go b/common/internalstate.go index 4f77470e..24c0b989 100644 --- a/common/internalstate.go +++ b/common/internalstate.go @@ -113,6 +113,16 @@ func (is *InternalState) SetDBColumnStats(c int, rowsDiff int64, keysSumDiff int is.DbColumns[c].ValuesSum = valuesSumDiff } +func (is *InternalState) DBSizeTotal() int64 { + is.mux.Lock() + defer is.mux.Unlock() + total := int64(0) + for _, c := range is.DbColumns { + total += c.KeysSum + c.ValuesSum + } + return total +} + func (is *InternalState) Pack() ([]byte, error) { is.mux.Lock() defer is.mux.Unlock()