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