Commit Graph

171 Commits (7ee3ded59d4835e10f3e7d0f7603c42aa5e83820)

Author SHA1 Message Date
John Howard 7ee3ded59d Fix Windows flock/funlock race (#122)
Signed-off-by: John Howard <jhoward@microsoft.com>
2018-09-12 13:56:54 -07:00
Gyuho Lee 76a4670663 *: update import paths "go.etcd.io/bbolt"
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
2018-08-28 08:15:54 -07:00
Paul e06ec0a754 Fix Close() to also wait for view transactions and fix tests as well (#91)
* Fix testDB_Close_PendingTx to do something with the writable arg and stop it from closing twice

* Fix Close() to wait for view transactions by getting a full lock on mmaplock

* Fix the TestTx_Check_ReadOnly to close the view transaction

* Fix the TestTx_Commit_ErrTxNotWritable to close the view transaction
2018-08-27 19:56:38 -07:00
Gyuho Lee 3130a60889 db.go: clean up file descriptor on db.file.ReadAt fail
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-03-17 17:00:29 -07:00
CJ DiMaggio 818c231b78 Clean up file descriptors on failed database initialization
Fixes an issue where failing to open a non-existent database in ReadOnly
mode would make you unable to properly initialize it in ReadWrite mode
afterwards due to a hanging lock.
2018-03-17 14:51:58 -07:00
Rodrigo Coelho 584b1a3dba
Breaking the long line 2018-02-14 10:06:29 -02:00
Rodrigo Coelho fafe4b70b5
Close waits for the transactions to finish
DB.Close() actually waits for the transactions to finish now, since the PR 377.
https://github.com/boltdb/bolt/pull/377
2018-02-13 20:02:24 -02:00
Tommi Virtanen bcfcdab742 Remove unnecessary if in batch handling
This is safe, as the only place that creates call values always
explicitly sets err. It's a leftover from an earlier iteration of the
code.
2017-11-26 15:02:34 -08:00
Anthony Romano bdfe4158f8 tx: load freelist on Check()
Otherwise, nil dereference on ReadOnly DB

Fixes #45
2017-09-21 16:38:29 -07:00
lorneli ea18f34f9d db: return t.Rollback directly in the end of View function
Make return line of db.View corresponding with db.Update.
2017-09-12 21:40:59 +08:00
Raphael Geronimi 3a49aacce1 Added support for no timeout locks on db files (#35)
No longer unconditionally sleeps if file lock is already held
2017-09-06 14:24:56 -07:00
Tyler Treat 69fa13f2f1 Add NoSync field to Options
This allows enabling NoSync when you only have access to the Options
passed into Open() and not the returned DB (as is frequently the case
with libraries).
2017-08-24 09:35:24 -07:00
Anthony Romano a6c45c18c3 Merge pull request #16 from heyitsanthony/config-page-size
Options.PageSize
2017-08-11 10:43:09 -07:00
Anthony Romano 2fe83be160 Merge pull request #19 from heyitsanthony/skip-freelist-read
do not read freelist if database opened readonly
2017-08-11 10:11:03 -07:00
Sokolov Yura aka funny_falcon ec37ce8e9b do not read freelist if database opened readonly 2017-08-10 22:30:40 -07:00
Anthony Romano 32c9f9e929 pass unused 2017-08-10 22:07:25 -07:00
Anthony Romano 012f88489b add PageSize to Option struct
Configure the db page size at runtime. Makes cross-arch debugging a bit easier.
2017-08-10 20:46:08 -07:00
Anthony Romano 78ca4fde00 get rid of os.Getpagesize() calls where appropriate 2017-08-10 20:46:08 -07:00
Anthony Romano 05bfb3bd9a rebuild freelist when opening with FreelistSync after NoFreelistSync
Writes pgidNoFreelist to the meta freelist page to detect when freelists
haven't been synced down.

Fixes #5
2017-07-25 08:01:43 -07:00
Xiang Li ad39960eb4 Merge pull request #3 from heyitsanthony/range-gc
Garbage collect pages allocated after minimum txid
2017-06-23 18:19:54 -07:00
Xiang 7149270521 *: add option to skip freelist sync
When the database has a lot of freepages, the cost to sync all
freepages down to disk is high. If the total database size is
small (<10GB), and the application can tolerate ~10 seconds
recovery time, then it is reasonable to simply not sync freelist
and rescan the db to rebuild freelist on recovery.
2017-06-22 12:46:56 -07:00
Anthony Romano 78d099ed1f Garbage collect pages allocated after minimum txid
Read txns would lock pages allocated after the txn, keeping those pages
off the free list until closing the read txn. Instead, track allocating
txid to compute page lifetime, freeing pages if all txns between
page allocation and page free are closed.
2017-06-05 16:07:55 -07:00
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