Reputation: 21
If we are trying to host corda node database in a SQL server can we host all of them in a single database? If yes how to do it and what will be its impact.
Can the built in H2 database which gets generated while a node is deployed be stored locally in a system such that data becomes permanent and is not lost in the next build?
Upvotes: 1
Views: 666
Reputation: 23140
Sharing an H2 database
As of Corda 3, each node spins up its own H2 database by default.
However, you can point multiple nodes to a single, stand-alone H2 database as follows:
java -jar ./h2/bin/h2-1.4.196.jar -webAllowOthers -tcpAllowOthers
)node.conf
node configuration file, set dataSource.url = "jdbc:h2:tcp://localhost:9092/~/nodeUniqueDatabaseName"
, where nodeUniqueDatabaseName
is unique to that nodeFor each nodeUniqueDatabaseName
, H2 will create a file nodeUniqueDatabaseName.mv.db
in the user's home directory.
You can also set a specific absolute path as well (e.g. dataSource.url = "jdbc:h2:tcp://localhost:9092/~/Users/szymonsztuka/IdeaProjects/corda3/nodeUniqueDatabaseName"
). This will create a database file under Users/szymonsztuka/IdeaProjects/corda3/
.
Note that this approach is not secure since the h2 server is started with -webAllowOthers -tcpAllowOthers
, meaning that anyone can log in and modify the database.
Maintaining data across node builds
The H2 database is discarded when re-running deployNodes
, because you are considered to be creating an entirely new set of nodes. If you only want to make changes to the installed CorDapps, you can shut down the node, update its CorDapps (by creating the new CorDapp JARs as described here and copying the CorDapp JARs into its cordapps
folder) and restart the node. The new CorDapps will be installed, but the old node data will still be present.
Upvotes: 2