Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mvcc log warnings #2649

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions core/ledger/kvledger/txmgmt/validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,23 @@ func (v *validator) validateReadSet(ns string, kvReads []*kvrwset.KVRead, update
// i.e., it checks whether a key/version combination is already updated in the statedb (by an already committed block)
// or in the updates (by a preceding valid transaction in the current block)
func (v *validator) validateKVRead(ns string, kvRead *kvrwset.KVRead, updates *privacyenabledstate.PubUpdateBatch) (bool, error) {
readVersion := rwsetutil.NewVersion(kvRead.Version)
if updates.Exists(ns, kvRead.Key) {
logger.Warnw("Transaction invalidation due to version mismatch, key in readset has been updated in a prior transaction in this block",
"namespace", ns, "key", kvRead.Key, "readVersion", readVersion)
return false, nil
}
committedVersion, err := v.db.GetVersion(ns, kvRead.Key)
if err != nil {
return false, err
}

logger.Debugf("Comparing versions for key [%s]: committed version=%#v and read version=%#v",
kvRead.Key, committedVersion, rwsetutil.NewVersion(kvRead.Version))
if !version.AreSame(committedVersion, rwsetutil.NewVersion(kvRead.Version)) {
logger.Debugf("Version mismatch for key [%s:%s]. Committed version = [%#v], Version in readSet [%#v]",
ns, kvRead.Key, committedVersion, kvRead.Version)
logger.Debugw("Comparing readset version to committed version",
"namespace", ns, "key", kvRead.Key, "readVersion", readVersion, "committedVersion", committedVersion)

if !version.AreSame(committedVersion, readVersion) {
logger.Warnw("Transaction invalidation due to version mismatch, readset version does not match committed version",
"namespace", ns, "key", kvRead.Key, "readVersion", readVersion, "committedVersion", committedVersion)
return false, nil
}
return true, nil
Expand Down Expand Up @@ -260,19 +264,24 @@ func (v *validator) validateCollHashedReadSet(ns, coll string, kvReadHashes []*k
// validateKVReadHash performs mvcc check for a hash of a key that is present in the private data space
// i.e., it checks whether a key/version combination is already updated in the statedb (by an already committed block)
// or in the updates (by a preceding valid transaction in the current block)
func (v *validator) validateKVReadHash(ns, coll string, kvReadHash *kvrwset.KVReadHash,
updates *privacyenabledstate.HashedUpdateBatch) (bool, error) {
func (v *validator) validateKVReadHash(ns, coll string, kvReadHash *kvrwset.KVReadHash, updates *privacyenabledstate.HashedUpdateBatch) (bool, error) {
readHashVersion := rwsetutil.NewVersion(kvReadHash.Version)
if updates.Contains(ns, coll, kvReadHash.KeyHash) {
logger.Warnw("Transaction invalidation due to hash version mismatch, hash key in readset has been updated in a prior transaction in this block",
"namespace", ns, "collection", coll, "keyHash", kvReadHash.KeyHash, "readHashVersion", readHashVersion)
return false, nil
}
committedVersion, err := v.db.GetKeyHashVersion(ns, coll, kvReadHash.KeyHash)
if err != nil {
return false, err
}

if !version.AreSame(committedVersion, rwsetutil.NewVersion(kvReadHash.Version)) {
logger.Debugf("Version mismatch for key hash [%s:%s:%#v]. Committed version = [%s], Version in hashedReadSet [%s]",
ns, coll, kvReadHash.KeyHash, committedVersion, kvReadHash.Version)
logger.Debugw("Comparing hash readset version to committed version",
"namespace", ns, "collection", coll, "keyHash", kvReadHash.KeyHash, "readVersion", readHashVersion, "committedVersion", committedVersion)

if !version.AreSame(committedVersion, readHashVersion) {
logger.Warnw("Transaction invalidation due to hash version mismatch, readset version does not match committed version",
"namespace", ns, "collection", coll, "keyHash", kvReadHash.KeyHash, "readVersion", readHashVersion, "committedVersion", committedVersion)
return false, nil
}
return true, nil
Expand Down