From 10ad00566d1d192bcb55f4ade968f7d76b372247 Mon Sep 17 00:00:00 2001 From: Stefano Scafiti Date: Mon, 22 Jul 2024 15:03:53 +0200 Subject: [PATCH] Prohibite changing transiency of keys --- embedded/store/immustore.go | 1 + embedded/store/ongoing_tx.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/embedded/store/immustore.go b/embedded/store/immustore.go index e7ad6a04c3..64970c4f27 100644 --- a/embedded/store/immustore.go +++ b/embedded/store/immustore.go @@ -61,6 +61,7 @@ var ErrMaxKeyLenExceeded = errors.New("max key length exceeded") var ErrMaxValueLenExceeded = errors.New("max value length exceeded") var ErrPreconditionFailed = errors.New("precondition failed") var ErrDuplicatedKey = errors.New("duplicated key") +var ErrCannotUpdateKeyTransiency = errors.New("cannot change a non-transient key to transient or vice versa") var ErrMaxActiveTransactionsLimitExceeded = errors.New("max active transactions limit exceeded") var ErrMVCCReadSetLimitExceeded = errors.New("MVCC read-set limit exceeded") var ErrMaxConcurrencyLimitExceeded = errors.New("max concurrency limit exceeded") diff --git a/embedded/store/ongoing_tx.go b/embedded/store/ongoing_tx.go index b4a1b6d041..08c983ccfc 100644 --- a/embedded/store/ongoing_tx.go +++ b/embedded/store/ongoing_tx.go @@ -262,11 +262,17 @@ func (tx *OngoingTx) set(key []byte, md *KVMetadata, value []byte, hashValue [sh kid := sha256.Sum256(key) keyRef, isKeyUpdate := tx.entriesByKey[kid] - if !isKeyUpdate && len(tx.entries) > tx.st.maxTxEntries { return ErrMaxTxEntriesLimitExceeded } + _, wasTransient := tx.transientEntries[keyRef] + if isKeyUpdate { + if wasTransient != isTransient { + return ErrCannotUpdateKeyTransiency + } + } + e := &EntrySpec{ Key: key, Metadata: md, @@ -343,7 +349,6 @@ func (tx *OngoingTx) set(key []byte, md *KVMetadata, value []byte, hashValue [sh tx.entries[keyRef] = e } } else { - if isTransient { tx.transientEntries[len(tx.entriesByKey)] = e tx.entriesByKey[kid] = len(tx.entriesByKey)