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

Method Run

cmd/bbolt/command/command_compact.go:56–94  ·  view source on GitHub ↗
(cmd *cobra.Command, srcPath string)

Source from the content-addressed store, hash-verified

54}
55
56func (o *compactOptions) Run(cmd *cobra.Command, srcPath string) (err error) {
57
58 // ensure source file exists.
59 fi, err := checkSourceDBPath(srcPath)
60 if err != nil {
61 return err
62 }
63 initialSize := fi.Size()
64
65 // open source database.
66 src, err := bolt.Open(srcPath, 0400, &bolt.Options{ReadOnly: true})
67 if err != nil {
68 return err
69 }
70 defer src.Close()
71
72 // open destination database.
73 dst, err := bolt.Open(o.dstPath, fi.Mode(), &bolt.Options{NoSync: o.dstNoSync})
74 if err != nil {
75 return err
76 }
77 defer dst.Close()
78
79 // run compaction.
80 if err := bolt.Compact(dst, src, o.txMaxSize); err != nil {
81 return err
82 }
83
84 // report stats on new size.
85 fi, err = os.Stat(o.dstPath)
86 if err != nil {
87 return err
88 } else if fi.Size() == 0 {
89 return fmt.Errorf("zero db size")
90 }
91 fmt.Fprintf(cmd.OutOrStdout(), "%d -> %d bytes (gain=%.2fx)\n", initialSize, fi.Size(), float64(initialSize)/float64(fi.Size()))
92
93 return
94}

Callers 15

newCompactCommandFunction · 0.95
TestTx_allocatePageStatsFunction · 0.80
TestMethodPageFunction · 0.80
TestMainFunction · 0.80
TestManyDBsFunction · 0.80

Calls 4

checkSourceDBPathFunction · 0.85
SizeMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by 15

TestTx_allocatePageStatsFunction · 0.64
TestMethodPageFunction · 0.64
TestMainFunction · 0.64
TestManyDBsFunction · 0.64
TestTx_MoveBucketFunction · 0.64