MCPcopy
hub / github.com/etcd-io/bbolt / pagesFunc

Function pagesFunc

cmd/bbolt/command/command_pages.go:44–93  ·  view source on GitHub ↗
(cmd *cobra.Command, dbPath string)

Source from the content-addressed store, hash-verified

42}
43
44func pagesFunc(cmd *cobra.Command, dbPath string) error {
45 if _, err := checkSourceDBPath(dbPath); err != nil {
46 return err
47 }
48
49 // Open database.
50 db, err := bolt.Open(dbPath, 0600, &bolt.Options{
51 ReadOnly: true,
52 PreLoadFreelist: true,
53 })
54 if err != nil {
55 return err
56 }
57 defer db.Close()
58
59 // Write header.
60 fmt.Fprintln(cmd.OutOrStdout(), "ID TYPE ITEMS OVRFLW")
61 fmt.Fprintln(cmd.OutOrStdout(), "======== ========== ====== ======")
62
63 return db.View(func(tx *bolt.Tx) error {
64 var id int
65 for {
66 p, err := tx.Page(id)
67 if err != nil {
68 return &PageError{ID: id, Err: err}
69 } else if p == nil {
70 break
71 }
72
73 // Only display count and overflow if this is a non-free page.
74 var count, overflow string
75 if p.Type != "free" {
76 count = strconv.Itoa(p.Count)
77 if p.OverflowCount > 0 {
78 overflow = strconv.Itoa(p.OverflowCount)
79 }
80 }
81
82 // Print table row.
83 fmt.Fprintf(cmd.OutOrStdout(), "%-8d %-10s %-6s %-6s\n", p.ID, p.Type, count, overflow)
84
85 // Move to the next non-overflow page.
86 id += 1
87 if p.Type != "free" {
88 id += p.OverflowCount
89 }
90 }
91 return nil
92 })
93}

Callers 1

newPagesCommandFunction · 0.85

Calls 4

checkSourceDBPathFunction · 0.85
ViewMethod · 0.80
PageMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected