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.
This avoids a case where writes can be reordered so meta page is
written before a page it refers to, potentially causing a corrupt
database after a power loss or kernel crash.
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.
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.
@tv42 reported that creating a cursor on an empty bucket and then calling
Cursor.Last() causes an index out of range error and panics. This commit
adds a check for the page's item count being greater than zero.
Fixes#63.
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.
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.
Per the suggestion of @tv42 and @cespare, this commit adds a package level
function to create and initialize a database at a given path. This is
a common interface for database packages.
Add an reference to the RWTransaction onto Transaction so that calls to
Transaction.Bucket() and Transaction.Buckets() return writable buckets
when attached to a writabe transaction.