Commit Graph

149 Commits (18ced60c946005c527c4df6057ce2dc95df05a60)

Author SHA1 Message Date
Josh Bleecher Snyder 10c6e01e1f Allow GC to reclaim completed transactions
The existing append-based implementation left a hanging reference to
the last tx.

For example, if db.txs was:

[]*Tx{0x1, 0x2, 0x3, 0x4, 0x5}

and we removed the second element, db.txs would now be:

[]*Tx{0x1, 0x3, 0x4, 0x5, 0x5}[:4]

The garbage collector cannot reclaim anything anywhere in a slice,
even pointers between its len and cap, because the len can always
be extended up to the cap.

This hanging reference to the Tx could last indefinitely,
and since the Tx has a reference to user-provided functions,
which could be closures, this bug could prevent arbitrary
amounts of user garbage from being collected.

Since db.txs is unordered anyway, switch to a simpler--and O(1) instead
of O(n)--implementation. Swap the last element into the spot to be
deleted, nil out the original last element, and shrink the slice.
2016-12-23 09:18:57 -08:00
Ben Johnson 0d68f169c5
Fix Stats.Sub() for Stats.TxN.
The subtraction for `TxN` was previously transposed which caused
the result to be a negative number. This change alters the order
to return the correct (positive) result.
2016-10-03 13:04:32 -06:00
Ben Johnson a5aec31dc3
add additional meta page tests 2016-04-24 14:09:45 -06:00
Ben Johnson 5e55b6cc1e
Merge branch '548-fix-errors-with-unsynced-metadata' of https://github.com/cyphar/boltdb into cyphar-548-fix-errors-with-unsynced-metadata 2016-04-24 13:23:29 -06:00
Ben Johnson f5f0f7af77
move page pool to db 2016-04-22 14:24:11 -06:00
Ben Johnson 9145d586f2
Merge branch 'pool_allocate' of https://github.com/LK4D4/bolt into LK4D4-pool_allocate 2016-04-22 14:16:02 -06:00
Aleksa Sarai ef2f3abff7 db: fix recovery from unsynced metadata
Bolt stores the two latest transactions' metadata, but previously did
not recover from validation failures in the latest by using the second
latest. Fix this by correctly handling validation failures in db.go, as
well as returning the metadata with highest txid which is also valid in
DB.meta().

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-04-20 08:17:28 +10:00
Chris Hines 5816124570 Wait to clear db.path until just before db.close returns.
The Windows version of funlock needs the db.path to delete the
corresponding .lock file.
2016-04-07 10:21:00 -04:00
Ben Johnson 220b61e988 move to separate lock file on windows 2016-03-01 08:15:25 -07:00
Alexander Morozov e1ffca3629 Use sync.Pool for small pages in db.allocate
Benchmark results:
benchmark                          old ns/op     new ns/op     delta
BenchmarkDBBatchAutomatic-4        2552625       2485200       -2.64%
BenchmarkDBBatchSingle-4           59632698      50757603      -14.88%
BenchmarkDBBatchManual10x100-4     2564789       2452735       -4.37%

benchmark                          old allocs     new allocs     delta
BenchmarkDBBatchAutomatic-4        10199          10202          +0.03%
BenchmarkDBBatchSingle-4           56642          56653          +0.02%
BenchmarkDBBatchManual10x100-4     5986           5995           +0.15%

benchmark                          old bytes     new bytes     delta
BenchmarkDBBatchAutomatic-4        433587        382462        -11.79%
BenchmarkDBBatchSingle-4           32504533      16308931      -49.83%
BenchmarkDBBatchManual10x100-4     1362370       881765        -35.28%

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2016-01-28 09:51:51 -08:00
Ben Johnson 02c43da2b0 Merge pull request #481 from gyuho/boltdb_typo
*: fixes minor typos
2016-01-11 15:59:14 -07:00
Ben Johnson a122e1c02b add AllocSize, minor grow() refactor
This commit moves `overAllocation` to a configurable `DB.AllocSize`
field and performs minor cosmetic clean up.
2016-01-11 15:40:23 -07:00
Ben Johnson 694a82a959 Merge branch 'grow' of https://github.com/xiang90/bolt into xiang90-grow 2016-01-11 14:47:01 -07:00
Gyu-Ho Lee cf93cb8694 *: fixes minor typos 2016-01-07 23:33:40 -08:00
Ben Johnson 8b08bd4a80 test suite refactoring
This commit refactors the test suite to make it cleaner and to use the
standard testing library better. The `assert()`, `equals()`, and `ok()`
functions have been removed and some test names have been changed for
clarity.

No functionality has been changed.
2016-01-02 21:30:31 -07:00
Ben Johnson f1153131c9 Merge pull request #471 from rhcarvalho/patch-1
Update min mmap size in godoc
2015-12-30 08:34:08 -07:00
Gyu-Ho Lee 082efcc23e Introduce InitialMmapSize to prevent deadlock
InitialMmapSize is the initial mmap size of the database in bytes.
Read transaction won't block write transaction if InitialMmapSize
is large enough to handle mmap size.

Copied from https://github.com/boltdb/bolt/pull/432.
2015-12-21 15:36:00 -08:00
Rodolfo Carvalho b766067f68 Update min mmap size in godoc 2015-12-17 00:19:41 +01:00
Rodolfo Carvalho 058a7ab347 Make bolt.Open return the documented errors
- ErrInvalid is returned when a data file is not a Bolt-formatted
  database.
- ErrVersionMismatch is returned when the data file was created with a
  different version of Bolt.
- ErrChecksum is returned when either meta page checksum does not match.

Also:
- Do not wrap errors from os.Stat, so that a caller could handle os.Stat
  errors just like it can handle errors from os.Open that bolt.Open
  might return.
- Name tests consistently, following the pattern "TestOpen_*".
- Remove deferred calls to `os.Remove(path)`.
  The calls are not only unnecessary, but also in all cases `os.Remove`
  returns an error that is ignored. All those calls are meant to remove
  a file that was already removed by `tmpfile()`.
- Combine "bad path" tests and use filepath.Join to build the path.
2015-12-10 18:39:03 +01:00
Gyu-Ho Lee d97579c399 Add MmapFlags option for MAP_POPULATE (unix)
This adds MmapFlags to DB.Options in case we need syscall.MAP_POPULATE
flag in Linux 2.6.23+ to do the sequential read-ahead, as discussed in [1].

---

[1]: https://github.com/coreos/etcd/issues/3786
2015-11-08 18:07:10 -08:00
Xiang Li e67705ed63 do not grow dbsize agressively
Only grow the database size when the high watermark increases.
We also grows the database size a little bit aggressively to
save a few ftruncates.

I have tested this on various environments. The performance impact
is ignorable with 16MB over allocation. Without over allocation,
the performance might decrease 100% when each Tx.Commit needs a new
page on a very slow disk (seek time dominates the total write).
2015-11-06 09:39:17 -08:00
Ben Johnson a03d52a9dd Add docs for dependent transactions.
This commit adds documentation to clarify that read-only and read-write
transactions should not be mixed in the same goroutine as it can cause
deadlocks during remapping.

See: https://github.com/boltdb/bolt/issues/378
2015-05-21 09:50:13 -06:00
Ben Johnson e929eba364 Wait for pending tx on close.
This commit fixes the DB.Close() function so that it waits for any
open transactions to finish before closing.
2015-05-20 16:10:07 -06:00
Ben Johnson d4363a9208 Merge branch 'ro' 2015-05-18 13:45:09 -06:00
Ben Johnson df52bd0803 Add test case inline documentation. 2015-05-18 13:45:02 -06:00
sasha-s aa13f7f94f make ignoring Truncate() explicit
https://github.com/boltdb/bolt/pull/371#issuecomment-103176330
2015-05-18 12:00:40 -07:00
sasha-s fda75748b5 use a shared lock in read-only mode
https://github.com/boltdb/bolt/pull/371#issuecomment-103119486
2015-05-18 11:07:19 -07:00
Ben Johnson a450f843ee Change min mmap size from 1MB to 32KB.
This commit adjusts the minimum mmap size from 1MB to 32KB. The
previous limit was arbitrary and causes wasted space for very small
databases.

Thanks to @mcuadros for submitting the original pull request:

  https://github.com/boltdb/bolt/pull/351
2015-05-18 10:37:47 -06:00
sasha-s 019bf5b010 open read-only databases in read-only mode 2015-05-14 15:43:13 -07:00
Ben Johnson e5aaa976ba Add DB.Sync().
This commit adds DB.Sync() for users who set DB.NoSync to true.
2015-05-08 13:11:15 -06:00
Ben Johnson b107b35f19 Add DB.NoGrowSync flag.
This commit adds the DB.NoGrowSync flag to optionally revert mmap()
calls to how they were implemented before the ext3/ext4 fix. When
NoGrowSync is true, remapping the data file will not force the file
system to resize it immediately. This works for non-ext3/4 file
systems.

The default value of NoGrowSync is false so it is still safe for
ext3/ext4 file systems by default.

See also: https://github.com/boltdb/bolt/issues/284
2015-05-06 09:23:32 -06:00
funkygao 6d043164a9 add comment: db.dataref is readonly 2015-03-25 22:05:58 +08:00
funkygao 20852b29c4 fix comment bug: minium db mmapSize is 1MB instead of 4MB 2015-03-25 22:04:41 +08:00
Tommi Virtanen adbb1a19c1 Add transaction batching
DB.Batch makes it easy to make lots of small transactions with
significantly better performance. Batch combines multiple concurrent
Update calls into a single disk transaction, managing errors smartly.
2015-02-18 12:26:45 -08:00
Ben Johnson e7f5c931e2 Fix large mmap resize.
This commit fixes an issue where large databases were being resized to
larger sizes on every open.
2015-02-16 15:23:48 -07:00
Ben Johnson ac1149a3f5 Persist sequence-only changes.
This commit fixes a bug where only calling NextSequence() on a Bucket does not cause the Bucket to be
peristed. The simple fix is to simply materialize the root node so that the bucket is flushed out
during commit.

Thanks to Matthew Dawson (@MJDSys) for reporting.

https://github.com/boltdb/bolt/issues/296
2015-02-02 08:27:34 -07:00
Ben Johnson b4d00c394a Expand assertion statements.
This commit expands calls to _assert() that use variadic arguments. These calls require conversion to interface{} so there
was a large number of calls to Go's internal convT2E() function. In some profiling this was taking over 20% of total runtime.
I don't remember seeing this before Go 1.4 so perhaps something has changed.
2015-01-30 14:15:49 -05:00
Ben Johnson 338d8e78e2 Fix max mmap check for 32-bit arch. 2015-01-28 16:27:06 -05:00
Ben Johnson dacc1873d1 Fix mmap step & max size check.
This commit adds fixes suggested by @tv42 for the mmap step fix in 834b38e:

* Check max size before calculating the new the mmap size.
* Fix mmap step loop to go to 1GB instead of 512MB.
2015-01-28 13:03:30 -05:00
Ben Johnson 834b38e3e7 Fix mmap resize calculation.
This commit fixes an issue where the database would grow whenever it was opened. This was caused by
a recent change that performed a truncation when the database grew. Now there are fixed growth sizes
for the database (1MB, 2MB, 4MB, 8MB, etc) up to 1GB and then the database will grow by 1GB when it
resizes.

See also: 6bb25854a1
2015-01-28 11:29:27 -05:00
pmcgrath 2110587fdd Removed redundant duplicate line of code 2015-01-22 12:15:40 +00:00
Ben Johnson 8374d6adc5 Add check for max mmap size.
The max mmap size was previous unchecked which resulted in a panic once
the maximum size was reached. This commit adds a check for the max size
when re-mapping and returns an error if the new map will exceed the size.

Thanks to Tamás Gulácsi for testing out the change on i386.
2015-01-12 08:06:42 -07:00
Josh Rickmar a2cbaa05f9 Fix bolt on OpenBSD.
OpenBSD does not include a UBC kernel and writes must be synchronized
with the msync(2) syscall.  In addition, the NoSync field of the DB
struct should be ignored on OpenBSD, since unlike other platforms,
missing msyncs will result in data corruption.

Depends on PR #258.

Fixes #257.
2014-09-18 18:14:50 -05:00
Ben Johnson ba6badc57f Move tests to a test package. 2014-07-26 15:11:47 -06:00
Ben Johnson c3400efefd Change fill percent to be per-bucket.
This commit moves the DB.FillPercent field to Bucket.FillPercent. This
allows the fill percentage to be specified per-bucket, per-tx. This
value is not persisted and should be set whenever using it.
2014-07-24 10:36:09 -06:00
Ben Johnson 048d3f19b2 Add DB.NoSync option for bulk loading.
This commit adds the DB.NoSync flag to skip fsync() calls on each commit. This should only
be used for bulk loading as it can corrupt your database in the event of a system failure.

Initial tests show it can provide a 2x speed up for sequential inserts.
2014-07-15 07:37:46 -06:00
Ben Johnson ac4838472d Recover from panics appropriately.
This commit adds a defer handler to ensure that transactions are always closed out - even
in the event of a panic within user code. It's recommended that applications always fail
in the event of a panic but some packages such as net/http will automatically recover
which is a problem (IHMO).
2014-07-11 09:54:10 -06:00
Ben Johnson cc8004c980 Merge branch 'master' of https://github.com/boltdb/bolt into free-cache 2014-07-10 14:00:32 -06:00
Ben Johnson e903703e61 Fix Windows mmap sizing.
This commit fixes an issue on Windows where the database was doubling
when it was re-opened. This occurred because Windows has to truncate the
file to the mmap size and the mmap resizing code was doubling the size
whenever the DB size was at the next threshold. This has been changed so
that the DB size will double only when the DB size is above the next
threshold.
2014-07-10 07:11:01 -06:00
Ben Johnson def455554b Add freelist cache.
This commit adds a cache to the freelist which combines the available free pages and pending free pages in
a single map. This was added to improve performance where freelist.isFree() was consuming 70% of CPU time
for large freelists.
2014-06-30 08:01:41 -06:00