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