Skip to content

Commit

Permalink
Prohibite changing transiency of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ostafen committed Jul 24, 2024
1 parent 68c7d59 commit 10ad005
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions embedded/store/immustore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions embedded/store/ongoing_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 10ad005

Please sign in to comment.