mirror of https://github.com/etcd-io/bbolt.git
ensure the stats is always 64bit aligned
The first word in an allocated struct can be relied upon to be 64-bit aligned. Refer to https://pkg.go.dev/sync/atomic#pkg-note-BUG. Signed-off-by: Benjamin Wang <wachao@vmware.com>pull/584/head
parent
233156a53a
commit
26f89a5951
15
db.go
15
db.go
|
@ -36,6 +36,12 @@ const (
|
||||||
// All data access is performed through transactions which can be obtained through the DB.
|
// All data access is performed through transactions which can be obtained through the DB.
|
||||||
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
|
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
|
||||||
type DB struct {
|
type DB struct {
|
||||||
|
// Put `stats` at the first field to ensure it's 64-bit aligned. Note that
|
||||||
|
// the first word in an allocated struct can be relied upon to be 64-bit
|
||||||
|
// aligned. Refer to https://pkg.go.dev/sync/atomic#pkg-note-BUG. Also
|
||||||
|
// refer to discussion in https://github.com/etcd-io/bbolt/issues/577.
|
||||||
|
stats Stats
|
||||||
|
|
||||||
// When enabled, the database will perform a Check() after every commit.
|
// When enabled, the database will perform a Check() after every commit.
|
||||||
// A panic is issued if the database is in an inconsistent state. This
|
// A panic is issued if the database is in an inconsistent state. This
|
||||||
// flag has a large performance impact so it should only be used for
|
// flag has a large performance impact so it should only be used for
|
||||||
|
@ -125,7 +131,6 @@ type DB struct {
|
||||||
opened bool
|
opened bool
|
||||||
rwtx *Tx
|
rwtx *Tx
|
||||||
txs []*Tx
|
txs []*Tx
|
||||||
stats Stats
|
|
||||||
|
|
||||||
freelist *freelist
|
freelist *freelist
|
||||||
freelistLoad sync.Once
|
freelistLoad sync.Once
|
||||||
|
@ -1275,6 +1280,12 @@ var DefaultOptions = &Options{
|
||||||
|
|
||||||
// Stats represents statistics about the database.
|
// Stats represents statistics about the database.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
|
// Put `TxStats` at the first field to ensure it's 64-bit aligned. Note
|
||||||
|
// that the first word in an allocated struct can be relied upon to be
|
||||||
|
// 64-bit aligned. Refer to https://pkg.go.dev/sync/atomic#pkg-note-BUG.
|
||||||
|
// Also refer to discussion in https://github.com/etcd-io/bbolt/issues/577.
|
||||||
|
TxStats TxStats // global, ongoing stats.
|
||||||
|
|
||||||
// Freelist stats
|
// Freelist stats
|
||||||
FreePageN int // total number of free pages on the freelist
|
FreePageN int // total number of free pages on the freelist
|
||||||
PendingPageN int // total number of pending pages on the freelist
|
PendingPageN int // total number of pending pages on the freelist
|
||||||
|
@ -1284,8 +1295,6 @@ type Stats struct {
|
||||||
// Transaction stats
|
// Transaction stats
|
||||||
TxN int // total number of started read transactions
|
TxN int // total number of started read transactions
|
||||||
OpenTxN int // number of currently open read transactions
|
OpenTxN int // number of currently open read transactions
|
||||||
|
|
||||||
TxStats TxStats // global, ongoing stats.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub calculates and returns the difference between two sets of database stats.
|
// Sub calculates and returns the difference between two sets of database stats.
|
||||||
|
|
Loading…
Reference in New Issue