Commit Graph

85 Commits (0329b03f58799ab8e51e7567f836c80c24258a16)

Author SHA1 Message Date
Ben Johnson defdb743cd Fix deadlock on remmap.
This commit fixes a deadlock situation that can occur when Bolt's database size crosses a threshold
and requires remapping the mmap.
2014-06-13 12:07:37 -06:00
Ben Johnson 1c97a490dd Add Windows support.
This commit adds Windows support to Bolt. Windows memory maps return an address instead of a byte
slice so the DB.data field had to be refactored to be a pointer to a large byte array.
2014-06-12 09:23:30 -06:00
Ben Johnson c2577db1c2 Add Windows support. 2014-06-11 11:11:21 -06:00
Ben Johnson b789691976 Add streaming check.
This commit changes Tx.Check() to return a channel through which check errors are returned. This allows
errors to be found before checking the entire data file.
2014-05-28 10:31:22 -06:00
Ben Johnson 92a9f2e200 Remove DB.Check(). Allow read-only Tx.Check().
This commit removes the DB.Check() function and instead makes the user decide
whether a transaction should be writable or read-only. Tx.Check() is not safe
to use concurrently on a read-only transaction, however, it significantly
improves the performance of it.
2014-05-27 11:31:55 -06:00
Ben Johnson 7432bc341f Merge pull request #169 from benbjohnson/allocation
Fix freelist allocation direction.
2014-05-21 13:46:12 -06:00
Martin Kobetic 519d65228e move Copy and CopyFile from DB to Tx 2014-05-21 15:08:37 +00:00
Ben Johnson 782ead0dbf Fix freelist allocation direction.
This commit fixes the freelist so that it frees from the beginning of the data file
instead of the end. It also adds a fast path for pages which can be allocated from
the first free pages and it includes read transaction stats.
2014-05-19 12:08:33 -06:00
Ben Johnson 6840e4f3dc Change verbiage, fix node test. 2014-05-15 14:21:17 -06:00
Ben Johnson a1873dd6f6 Add option to adjust fill percentage.
This commit adds the ability to adjust the fill percentage for splitting nodes. This
works by setting a threshold that is a percentage of a total page size. When that
threshold is crossed during a split then a new node is created.

This is primarily beneficial for append-only workloads.

Fixes #163.
2014-05-15 14:04:57 -06:00
Ben Johnson 1f5fb0208b Add strict mode. 2014-05-14 18:08:55 -06:00
Martin Kobetic d279ea44ce add asserts for detecting pgid high watermark overflow 2014-05-09 13:35:00 +00:00
Ben Johnson 55e71b0902 Add inline bucket support.
This commit adds support for writing small buckets directly inline to their value in
their parent's leaf node. Previously, subbuckets would simply have a bucket header
stored in their parent bucket which pointed to the root page. This required that
every bucket use at least a single page. This has a high overhead for buckets with
only one or two small items.

Inline buckets checks subbuckets to see if they only have a small amount of data
(about 1kb) and no subbuckets. If these conditions are met then the bucket's root
node is written to a fake page which is simply a pointer to the end of the bucket's
header.

Fixes #124.
2014-05-05 16:39:55 -06:00
Ben Johnson c3903d38a1 Consolidate code for clarity.
This commit consolidates some of the smaller files into some of the larger files.
The smaller files cluttered the file tree and made it harder to see the logical
groupings of structs.
2014-05-05 07:56:54 -06:00
Steven Normore 32937280c3 wip 2014-04-16 15:00:26 +00:00
Steven Normore b178373351 build c/cursor and running tests 2014-04-16 13:29:52 +00:00
Ben Johnson 698b07b074 Add nested buckets.
This commit adds the ability to create buckets inside of other buckets.
It also replaces the buckets page with a root bucket.

Fixes #56.
2014-04-11 12:36:54 -06:00
Ben Johnson 12204df0b5 Rename internal local Tx variables.
This commit changes the local Tx variables from "t" to "tx". This is partly
for consistency with external documentation but also because it just
annoys me for some reason.
2014-04-04 12:03:04 -06:00
Ben Johnson ca83d17125 Add meta page checksums.
This commit adds checksums to the meta pages on every write. When the
database loads, it verifies the checksums on the meta pages and returns
an error if either one is corrupt.

In the future, it should fallback to the previous meta page but for right
now it just hard fails. This is at least preferable to opening the database
and getting a random error or further corruption.

Fixes #25.
2014-04-02 16:56:16 -06:00
Ben Johnson 686b6a3341 Add performance counters.
This commit adds performance counters for each transaction which are rolled
up to the database level on each commit/rollback. Counters are meant to be
a very fast way to track what is going on in the database. A few timers are
also added in areas where the time.Now() overhead is not noticible.

The DB.Stat() function is now deprecated since the `bolt` CLI now performs
similar functions.

Fixes #108.
2014-04-02 16:03:03 -06:00
Ben Johnson 1eacfa9489 Add advisory file locking.
This commit adds advisory locking via flock() to the database file. This ensures that two separate
processes cannot both open the same data file which would cause corruption.

Fixes #110.
2014-04-02 14:05:24 -06:00
Ben Johnson 4ef19124d1 Consolidate file and metafile descriptors.
Previously, a two file descriptors were used for the database: file & metafile. The "file" file
descriptor was used for async writes while the "metafile" file descriptor was used with O_SYNC
writes. This commit changes that so that there's only one file descriptor and it uses fdatasync()
to synchronize writes.
2014-04-02 13:50:03 -06:00
Ben Johnson 8dafb2312b Remove DB.Open() and only allow bolt.Open().
Per @tv42's suggestion, this commit removes the ability to reopen an
instance of DB. All open calls go through bolt.Open().

Fixes #103.
2014-03-31 11:22:27 -06:00
Ben Johnson 440b89418f Write freelist after each commit.
Well, this is embarassing. Somehow the freelist was never getting written after each commit.
This commit fixes that and fixes a small reporting issue with "bolt pages".
2014-03-31 08:52:19 -06:00
Ben Johnson 7f2de9f17a Add DB.Check(). 2014-03-29 14:22:32 -06:00
Ben Johnson f45f1ed8d4 Fix DB.Copy() meta lock and partial write checks. 2014-03-26 10:11:31 -06:00
Ben Johnson f8ad21bad3 Make DB/Tx API more consistent.
I consolidated the DB.Tx() and DB.RWTx() calls into a single
DB.Begin(writable bool) call. This is more consistent with the
database/sql library.

I also changed the DB.Do() and DB.With() call to DB.Update() and
DB.View(), respectively. This is more intuitive and more inline with
other database verbiage.
2014-03-24 11:43:06 -06:00
Ben Johnson 59fde2f664 Error refactoring.
Fixed up a few error issues and refactored out the Error type.
2014-03-24 08:31:15 -06:00
Tommi Virtanen e9b2cab0fa Re-add tests for write failures
Commit d2173f5f0e removed the complete
os & syscall mocking layer as overly complex. This commit adds back
the simplest possible thing: hooks to control the database file
writes.

Missing tests: TestDBOpenMetaFileError, TestDBMmapStatError.
These are harder to test without more extensive mocking.

Conflicts:
	db_test.go
2014-03-24 07:47:33 -06:00
Ben Johnson 3c1ecb925e Resolve remaining errcheck warnings. 2014-03-24 07:38:27 -06:00
Tommi Virtanen e0a6f5b2af Check errors from file close in DB.CopyFile
Write errors are often delayed and reported only by the close.

The extra close in defer on success is harmless, (*os.File).Close
protects itself against multiple closes, and this way it's immediately
obvious there is no code path that would leak open files.
2014-03-23 13:27:37 -07:00
Ben Johnson 76f6ead6b0 Mark Do()/With() transaction as managed.
Transaction created from Do() and With() are now considered "managed".
Managed transactions cannot be manually committed or rolled back since
the Do() and With() functions provide that functionally automatically.
Previously, a Tx could be manually committed and then any changes after
that would be lost.
2014-03-23 10:34:53 -06:00
Ben Johnson d2173f5f0e Fix db.munmap() to return an error.
Changes munmap to return an error and the DB now implements io.Closer.
I also removed all the OS and Syscall mocking because it's causing issues.
Corrupt file tests need to be recreated but directly using the file system
instead.
2014-03-21 13:21:33 -06:00
Ben Johnson 3cc959fb1a Remove ease-of-use functions from the DB type.
Functions such as DB.Put(), DB.Get(), and DB.Delete() were originally
added to be easy to use, however, after implementing Bolt in multiple
projects I have found these ease-of-use functions useless. Nearly
every use case requires multiple calls in a single transaction.

Using the DB ease of use functions turned out to be an antipattern.
2014-03-21 09:52:01 -06:00
Ben Johnson c551e45a47 Consolidate Tx and RWTx. 2014-03-08 20:40:48 -07:00
Ben Johnson 57376f0905 Rename Transaction to Tx.
I changed the Transaction/RWTransaction types to Tx/RWTx, respectively. This makes the naming
more consistent with other packages such as database/sql. The txnid is changed to txid as well.
2014-03-08 17:04:02 -07:00
Ben Johnson 3a1b152562 Ignore multiple transaction commit/rollback/close. 2014-03-01 12:53:05 -07:00
Ben Johnson a1f43f4d60 Allow reads of unflushed nodes.
This commit allows cursors to read updated values from within the
RWTransaction.
2014-03-01 09:13:59 -07:00
Ben Johnson 0477c1e0ce Fix the mmap resize to use the correct size.
Fixes #54. Previously the DB was calculating a minimum mmap size but
using the wrong variable after it calculated the size. This commit
changes the DB to use the correct variable.
2014-02-27 14:33:31 -07:00
Ben Johnson a544249dd8 Refactor Bucket. 2014-02-23 08:32:53 -07:00
Ben Johnson 3b2fd8f2d3 Revert "Refactor Transaction/Bucket API."
This reverts commit 1ad2b99f28.
2014-02-22 22:54:54 -07:00
Ben Johnson 1ad2b99f28 Refactor Transaction/Bucket API. 2014-02-21 22:57:50 -07:00
Ben Johnson 9827df70e0 Add DB.Stat(). 2014-02-21 09:49:15 -07:00
Ben Johnson 459b8eb4ab Read-only transactional block. 2014-02-16 15:43:35 -07:00
Ben Johnson b22480fd32 Add Transaction.ForEach(). 2014-02-16 13:59:07 -07:00
Ben Johnson 63e8e474d7 Add CreateBucketIfNotExists(). 2014-02-16 12:36:37 -07:00
Ben Johnson 149afc8c9b Rename errors. 2014-02-16 12:18:44 -07:00
Ben Johnson 6a7be8879b Add Stringer support. 2014-02-16 12:11:10 -07:00
Ben Johnson d1952237ed Improve test coverage. 2014-02-15 23:45:17 -07:00
Ben Johnson 72b799480f Fix DB.opened flag. 2014-02-15 22:34:21 -07:00