DB: Include docs on how to recreate the database

This commit is contained in:
Braydon Fuller 2016-01-28 13:47:26 -05:00
parent 98bd8ee560
commit 995b4b57d4
2 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,15 @@
# Database Service
This service synchronizes a leveldb database with the [Bitcoin Service](bitcoind.md) block chain by connecting and disconnecting blocks to build new indexes that can be queried. Other services can extend the data that is indexed by implementing a `blockHandler` method, similar to the built-in [Address Service](address.md).
## How to Reindex
If you need to be able to recreate the database from historical transactions in blocks:
- Shutdown your node
- Remove the `bitcore-node.db` directory in the data directory (e.g. `~/.bitcore/bitcore-node.db`)
- Start your node again
The database will then ask bitcoind for all the blocks again and recreate the database. This is sometimes required during upgrading as the format of the keys and values has changed. For "livenet" this can take half a day or more, for "testnet" this can take around an hour.
## Adding Indexes
For a service to include additional block data, it can implement a `blockHandler` method that will be run to when there are new blocks added or removed.

View File

@ -120,10 +120,12 @@ DB.prototype._checkVersion = function(callback) {
version = buffer.readUInt32BE();
}
if (self.version !== version) {
var helpUrl = 'https://github.com/bitpay/bitcore-node/blob/master/docs/services/db.md#how-to-reindex';
return callback(new Error(
'The version of the database "' + version + '" does not match the expected version "' +
self.version + '". A reindex (can take several hours) is required or to switch ' +
'versions of software to match.'
self.version + '". A recreation of "' + self.dataPath + '" (can take several hours) is ' +
'required or to switch versions of software to match. Please see ' + helpUrl +
' for more information.'
));
}
callback();