I am confused to understand what is read and write set in fabric 1.0, Kindly someone explain by taking example if possible.
2 Answers
Read set and write sets are related to a transaction.
Suppose you have a transaction, read key a1 (suppose a1's value = value_a1, version = version_a1), and key a2(suppose a2's value = value_a2, version = version_a2), suppose we want a1's value to be decremented, and a2's value incremented;
So this transaction's read set is :
{a1, value_a1, version_a1; a2, value_a2, version_a2};
i.e., the related key, its value, its version list;
This transaction's write set is:
{a1, (value_a1 -1); a2, (value_a2 +1)};
i.e., the updated key and its new value list.
Read set and write set are used for transaction endorsement and commit (update world state) at committer.

- 134
- 1
- 2
-
1you can read more about read/write sets here http://hyperledger-fabric.readthedocs.io/en/latest/readwrite.html – christo4ferris Jul 21 '17 at 12:02
-
Why is version_a1 and version_a2 included in the set, even though it's not being modified in the write set? – Boon Nov 05 '18 at 23:26
-
@Boon: This information is used by committer to validate transaction. The versions of the keys are recorded only in the read set; the write set just contains the list of unique keys and their latest values set by the transaction. – Shahid Hussain Feb 12 '19 at 02:30
-
@timon-fay, are you sure about read set contains the value of an asset, as far as I know, read set contains only key and version of the asset whereas write set contains all three key, value, and version of the asset – PAVAN Jan 29 '20 at 17:23
Read and write set is generated by Endorser and used by committer to validate the transaction.
Data in fabric word-state is stored in key-value pair. Whenever committer commit(insert/update/delete) a transaction in world-state , it also generates a version of this key-value pair and insert. Example :
key="K1", value="V1, version="111"
key="K2", value="V2, version="112"
In current fabric version, height of the transaction is used as the latest version for all the keys modified by the transaction.
Endorser Generate read-write sets. Read-set contain the key=,value=,version= of the pair which are going to be affected by current transaction (Before committing). write-set contains the new value(s) for above key(s) (without version as version is generated by committer).
Committer before committing the transaction , uses the read set portion of the read-write set for checking the validity of a transaction and the write set portion of the read-write set for updating the values of the affected keys and also generates a new version for this key-value-pair.

- 1,599
- 1
- 20
- 24