mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
core/rawdb: fix db inspect
This commit is contained in:
parent
cbbc94fbce
commit
ff247428af
2 changed files with 32 additions and 38 deletions
|
|
@ -24,24 +24,23 @@ import (
|
|||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
)
|
||||
|
||||
type tableSize struct {
|
||||
name string
|
||||
size common.StorageSize
|
||||
type tableInfo struct {
|
||||
name string
|
||||
size common.StorageSize
|
||||
count uint64
|
||||
}
|
||||
|
||||
// freezerInfo contains the basic information of the freezer.
|
||||
type freezerInfo struct {
|
||||
name string // The identifier of freezer
|
||||
head uint64 // The number of last stored item in the freezer
|
||||
tail uint64 // The number of first stored item in the freezer
|
||||
count uint64 // The number of stored items in the freezer
|
||||
sizes []tableSize // The storage size per table
|
||||
name string // The identifier of freezer
|
||||
head uint64 // The number of last stored item in the freezer
|
||||
tables []tableInfo // Per-table storage size and item count
|
||||
}
|
||||
|
||||
// size returns the storage size of the entire freezer.
|
||||
func (info *freezerInfo) size() common.StorageSize {
|
||||
var total common.StorageSize
|
||||
for _, table := range info.sizes {
|
||||
for _, table := range info.tables {
|
||||
total += table.size
|
||||
}
|
||||
return total
|
||||
|
|
@ -49,46 +48,41 @@ func (info *freezerInfo) size() common.StorageSize {
|
|||
|
||||
func inspect(name string, order map[string]freezerTableConfig, reader ethdb.AncientReader) (freezerInfo, error) {
|
||||
info := freezerInfo{name: name}
|
||||
for t := range order {
|
||||
size, err := reader.AncientSize(t)
|
||||
if err != nil {
|
||||
return freezerInfo{}, err
|
||||
}
|
||||
info.sizes = append(info.sizes, tableSize{name: t, size: common.StorageSize(size)})
|
||||
}
|
||||
// Retrieve the number of last stored item
|
||||
|
||||
// Retrieve the number of last stored item.
|
||||
ancients, err := reader.Ancients()
|
||||
if err != nil {
|
||||
return freezerInfo{}, err
|
||||
}
|
||||
if ancients > 0 {
|
||||
info.head = ancients - 1
|
||||
} else {
|
||||
info.head = 0
|
||||
}
|
||||
|
||||
// Retrieve the highest tail across all known tail groups. The inspected
|
||||
// freezer info uses a single tail value for display, which corresponds to
|
||||
// the most-pruned group.
|
||||
groups := make(map[string]struct{})
|
||||
// Resolve per-group tails so each table can report its own item count.
|
||||
groupTails := make(map[string]uint64)
|
||||
for _, cfg := range order {
|
||||
if cfg.tailGroup != "" {
|
||||
groups[cfg.tailGroup] = struct{}{}
|
||||
if cfg.tailGroup == "" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
for g := range groups {
|
||||
t, err := reader.Tail(g)
|
||||
if _, ok := groupTails[cfg.tailGroup]; ok {
|
||||
continue
|
||||
}
|
||||
t, err := reader.Tail(cfg.tailGroup)
|
||||
if err != nil {
|
||||
return freezerInfo{}, err
|
||||
}
|
||||
if t > info.tail {
|
||||
info.tail = t
|
||||
}
|
||||
groupTails[cfg.tailGroup] = t
|
||||
}
|
||||
if ancients == 0 {
|
||||
info.count = 0
|
||||
} else {
|
||||
info.count = info.head - info.tail + 1
|
||||
for t, cfg := range order {
|
||||
size, err := reader.AncientSize(t)
|
||||
if err != nil {
|
||||
return freezerInfo{}, err
|
||||
}
|
||||
var count uint64
|
||||
if ancients > 0 {
|
||||
tail := groupTails[cfg.tailGroup] // 0 for non-prunable tables
|
||||
count = ancients - tail
|
||||
}
|
||||
info.tables = append(info.tables, tableInfo{name: t, size: common.StorageSize(size), count: count})
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -658,12 +658,12 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
|||
return err
|
||||
}
|
||||
for _, ancient := range ancients {
|
||||
for _, table := range ancient.sizes {
|
||||
for _, table := range ancient.tables {
|
||||
stats = append(stats, []string{
|
||||
fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)),
|
||||
strings.Title(table.name),
|
||||
table.size.String(),
|
||||
fmt.Sprintf("%d", ancient.count),
|
||||
fmt.Sprintf("%d", table.count),
|
||||
})
|
||||
}
|
||||
total.Add(uint64(ancient.size()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue