@@ -42,28 +42,23 @@ type DB struct {
42
42
// refer to discussion in https://github.com/etcd-io/bbolt/issues/577.
43
43
stats Stats
44
44
45
- // When enabled, the database will perform a Check() after every commit.
46
- // A panic is issued if the database is in an inconsistent state. This
47
- // flag has a large performance impact so it should only be used for
48
- // debugging purposes.
49
- StrictMode bool
45
+ pagePool sync.Pool
50
46
51
- // Setting the NoSync flag will cause the database to skip fsync()
52
- // calls after each commit. This can be useful when bulk loading data
53
- // into a database and you can restart the bulk load in the event of
54
- // a system failure or database corruption. Do not set this flag for
55
- // normal use.
56
- //
57
- // If the package global IgnoreNoSync constant is true, this value is
58
- // ignored. See the comment on that constant for more details.
59
- //
60
- // THIS IS UNSAFE. PLEASE USE WITH CAUTION.
61
- NoSync bool
47
+ logger Logger
62
48
63
- // When true, skips syncing freelist to disk. This improves the database
64
- // write performance under normal operation, but requires a full database
65
- // re-sync during recovery.
66
- NoFreelistSync bool
49
+ openFile func (string , int , os.FileMode ) (* os.File , error )
50
+ file * os.File
51
+ data * [maxMapSize ]byte
52
+ meta0 * common.Meta
53
+ meta1 * common.Meta
54
+ rwtx * Tx
55
+
56
+ freelist * freelist
57
+ batch * batch
58
+
59
+ ops struct {
60
+ writeAt func (b []byte , off int64 ) (n int , err error )
61
+ }
67
62
68
63
// FreelistType sets the backend freelist type. There are two options. Array which is simple but endures
69
64
// dramatic performance degradation if database is large and fragmentation in freelist is common.
@@ -72,18 +67,12 @@ type DB struct {
72
67
// The default type is array
73
68
FreelistType FreelistType
74
69
75
- // When true, skips the truncate call when growing the database.
76
- // Setting this to true is only safe on non-ext3/ext4 systems.
77
- // Skipping truncation avoids preallocation of hard drive space and
78
- // bypasses a truncate() and fsync() syscall on remapping.
79
- //
80
- // https://github.com/boltdb/bolt/issues/284
81
- NoGrowSync bool
82
-
83
- // When `true`, bbolt will always load the free pages when opening the DB.
84
- // When opening db in write mode, this flag will always automatically
85
- // set to `true`.
86
- PreLoadFreelist bool
70
+ path string
71
+ // `dataref` isn't used at all on Windows, and the golangci-lint
72
+ // always fails on Windows platform.
73
+ //nolint
74
+ dataref []byte // mmap'ed readonly, write throws SEGV
75
+ txs []* Tx
87
76
88
77
// If you want to read the entire database fast, you can set MmapFlag to
89
78
// syscall.MAP_POPULATE on Linux 2.6.23+ for sequential read-ahead.
@@ -110,46 +99,61 @@ type DB struct {
110
99
// of truncate() and fsync() when growing the data file.
111
100
AllocSize int
112
101
113
- // Mlock locks database file in memory when set to true.
114
- // It prevents major page faults, however used memory can't be reclaimed.
115
- //
116
- // Supported only on Unix via mlock/munlock syscalls.
117
- Mlock bool
118
-
119
- logger Logger
120
-
121
- path string
122
- openFile func (string , int , os.FileMode ) (* os.File , error )
123
- file * os.File
124
- // `dataref` isn't used at all on Windows, and the golangci-lint
125
- // always fails on Windows platform.
126
- //nolint
127
- dataref []byte // mmap'ed readonly, write throws SEGV
128
- data * [maxMapSize ]byte
129
102
datasz int
130
- meta0 * common.Meta
131
- meta1 * common.Meta
132
103
pageSize int
133
- opened bool
134
- rwtx * Tx
135
- txs []* Tx
104
+ mmaplock sync.RWMutex // Protects mmap access during remapping.
105
+ statlock sync.RWMutex // Protects stats access.
136
106
137
- freelist * freelist
138
107
freelistLoad sync.Once
139
108
140
- pagePool sync.Pool
141
-
142
109
batchMu sync.Mutex
143
- batch * batch
144
110
145
- rwlock sync.Mutex // Allows only one writer at a time.
146
- metalock sync.Mutex // Protects meta page access.
147
- mmaplock sync.RWMutex // Protects mmap access during remapping.
148
- statlock sync.RWMutex // Protects stats access.
111
+ rwlock sync.Mutex // Allows only one writer at a time.
112
+ metalock sync.Mutex // Protects meta page access.
149
113
150
- ops struct {
151
- writeAt func (b []byte , off int64 ) (n int , err error )
152
- }
114
+ // When enabled, the database will perform a Check() after every commit.
115
+ // A panic is issued if the database is in an inconsistent state. This
116
+ // flag has a large performance impact so it should only be used for
117
+ // debugging purposes.
118
+ StrictMode bool
119
+
120
+ // Setting the NoSync flag will cause the database to skip fsync()
121
+ // calls after each commit. This can be useful when bulk loading data
122
+ // into a database and you can restart the bulk load in the event of
123
+ // a system failure or database corruption. Do not set this flag for
124
+ // normal use.
125
+ //
126
+ // If the package global IgnoreNoSync constant is true, this value is
127
+ // ignored. See the comment on that constant for more details.
128
+ //
129
+ // THIS IS UNSAFE. PLEASE USE WITH CAUTION.
130
+ NoSync bool
131
+
132
+ // When true, skips syncing freelist to disk. This improves the database
133
+ // write performance under normal operation, but requires a full database
134
+ // re-sync during recovery.
135
+ NoFreelistSync bool
136
+
137
+ // When true, skips the truncate call when growing the database.
138
+ // Setting this to true is only safe on non-ext3/ext4 systems.
139
+ // Skipping truncation avoids preallocation of hard drive space and
140
+ // bypasses a truncate() and fsync() syscall on remapping.
141
+ //
142
+ // https://github.com/boltdb/bolt/issues/284
143
+ NoGrowSync bool
144
+
145
+ // When `true`, bbolt will always load the free pages when opening the DB.
146
+ // When opening db in write mode, this flag will always automatically
147
+ // set to `true`.
148
+ PreLoadFreelist bool
149
+
150
+ // Mlock locks database file in memory when set to true.
151
+ // It prevents major page faults, however used memory can't be reclaimed.
152
+ //
153
+ // Supported only on Unix via mlock/munlock syscalls.
154
+ Mlock bool
155
+
156
+ opened bool
153
157
154
158
// Read only mode.
155
159
// When true, Update() and Begin(true) return ErrDatabaseReadOnly immediately.
@@ -1016,8 +1020,8 @@ type call struct {
1016
1020
type batch struct {
1017
1021
db * DB
1018
1022
timer * time.Timer
1019
- start sync.Once
1020
1023
calls []call
1024
+ start sync.Once
1021
1025
}
1022
1026
1023
1027
// trigger runs the batch if it hasn't already been run.
@@ -1284,21 +1288,13 @@ func (db *DB) freepages() []common.Pgid {
1284
1288
1285
1289
// Options represents the options that can be set when opening a database.
1286
1290
type Options struct {
1287
- // Timeout is the amount of time to wait to obtain a file lock.
1288
- // When set to zero it will wait indefinitely.
1289
- Timeout time.Duration
1290
-
1291
- // Sets the DB.NoGrowSync flag before memory mapping the file.
1292
- NoGrowSync bool
1293
1291
1294
- // Do not sync freelist to disk. This improves the database write performance
1295
- // under normal operation, but requires a full database re-sync during recovery.
1296
- NoFreelistSync bool
1292
+ // Logger is the logger used for bbolt.
1293
+ Logger Logger
1297
1294
1298
- // PreLoadFreelist sets whether to load the free pages when opening
1299
- // the db file. Note when opening db in write mode, bbolt will always
1300
- // load the free pages.
1301
- PreLoadFreelist bool
1295
+ // OpenFile is used to open files. It defaults to os.OpenFile. This option
1296
+ // is useful for writing hermetic tests.
1297
+ OpenFile func (string , int , os.FileMode ) (* os.File , error )
1302
1298
1303
1299
// FreelistType sets the backend freelist type. There are two options. Array which is simple but endures
1304
1300
// dramatic performance degradation if database is large and fragmentation in freelist is common.
@@ -1307,9 +1303,9 @@ type Options struct {
1307
1303
// The default type is array
1308
1304
FreelistType FreelistType
1309
1305
1310
- // Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
1311
- // grab a shared lock (UNIX) .
1312
- ReadOnly bool
1306
+ // Timeout is the amount of time to wait to obtain a file lock.
1307
+ // When set to zero it will wait indefinitely .
1308
+ Timeout time. Duration
1313
1309
1314
1310
// Sets the DB.MmapFlags flag before memory mapping the file.
1315
1311
MmapFlags int
@@ -1327,22 +1323,31 @@ type Options struct {
1327
1323
// PageSize overrides the default OS page size.
1328
1324
PageSize int
1329
1325
1326
+ // Sets the DB.NoGrowSync flag before memory mapping the file.
1327
+ NoGrowSync bool
1328
+
1329
+ // Do not sync freelist to disk. This improves the database write performance
1330
+ // under normal operation, but requires a full database re-sync during recovery.
1331
+ NoFreelistSync bool
1332
+
1333
+ // PreLoadFreelist sets whether to load the free pages when opening
1334
+ // the db file. Note when opening db in write mode, bbolt will always
1335
+ // load the free pages.
1336
+ PreLoadFreelist bool
1337
+
1338
+ // Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
1339
+ // grab a shared lock (UNIX).
1340
+ ReadOnly bool
1341
+
1330
1342
// NoSync sets the initial value of DB.NoSync. Normally this can just be
1331
1343
// set directly on the DB itself when returned from Open(), but this option
1332
1344
// is useful in APIs which expose Options but not the underlying DB.
1333
1345
NoSync bool
1334
1346
1335
- // OpenFile is used to open files. It defaults to os.OpenFile. This option
1336
- // is useful for writing hermetic tests.
1337
- OpenFile func (string , int , os.FileMode ) (* os.File , error )
1338
-
1339
1347
// Mlock locks database file in memory when set to true.
1340
1348
// It prevents potential page faults, however
1341
1349
// used memory can't be reclaimed. (UNIX only)
1342
1350
Mlock bool
1343
-
1344
- // Logger is the logger used for bbolt.
1345
- Logger Logger
1346
1351
}
1347
1352
1348
1353
func (o * Options ) String () string {
0 commit comments