MVCC Optimization
Hyperledger Fabric databases use multi-version concurrency control (MVCC) to avoid double-spending and data inconsistency.
When the same state is updated, a new version of the record overwrites the old version. If there are concurrent requests to update the same key in a block, an MVCC_READ_CONFLICT error might be generated.
To reduce MVCC errors for transfer, mint, burn, and hold operations, you can enable the MVCC optimization for token chaincode. This optimization works on Oracle Blockchain Platform only. By default, the optimization is disabled. To enable the optimization, complete the applicable following step.
- CLI: Specify the Boolean
-m
or--enable_mvcc_optimization
parameter with theochain init
command. By default, the parameter is set tofalse
. To enable the optimization, add-m true
to theochain init
command line. - Visual Studio Code: When you create a chaincode, select Enable MVCC optimization on the Create Chaincode window.
To use the optimization with chaincode created in previous versions of Blockchain App Builder, complete the following steps:
- After you install the latest version of Blockchain App Builder, upgrade the chaincode as described in Upgrading Chaincode Projects in the CLI and Upgrading Chaincode Projects in Visual Studio Code.
- Edit the
.ochain.json
file in the root folder of the chaincode to setenableMvccOptimization
totrue
. - Synchronize the chaincode, which adds the optimization and creates two
new folders in the root folder of the the chaincode:
statedb
andtokens
. For more information about synchronization, see Synchronize Specification File Changes With Generated Source Code and Synchronize Specification File Changes With Generated Source Code.
Other methods to work around MVCC_READ_CONFLICT errors including having the client application retry requests when this error is generated, or using a queue to capture concurrent requests before they are sent to the blockchain network. For more information, see Read-Write set semantics in the Hyperledger Fabric documentation.
Note:
The MVCC optimization does not work on hybrid networks that include both Oracle Blockchain Platform and Hyperledger Fabric peers, or for testing on a local Hyperledger Fabric network. Do not enable the MVCC optimization on hybrid networks, as this might lead to inconsistencies between peers.