Skip to content

Commit

Permalink
fix: prevent getting by deleted key within transaction
Browse files Browse the repository at this point in the history
(cherry picked from commit bf9e1eb)
  • Loading branch information
megglos authored and github-actions[bot] committed Apr 3, 2024
1 parent 432b4c5 commit 45ee368
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void put(final FullyQualifiedKey fullyQualifiedKey, final DbValue value)
public byte[] get(final FullyQualifiedKey fullyQualifiedKey) {
final Bytes key = fullyQualifiedKey.getKeyBytes();

if (deletedKeys.contains(key)) {
return null;
}

final Bytes valueInCache = transactionCache.get(key);

if (valueInCache != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,29 @@ void shouldAllowDeleteAndInsertInTransaction() throws Exception {
assertThat(oneColumnFamily.get(oneKey).getValue()).isEqualTo(twoValue.getValue());
}

@Test
void shouldNotGetByKeyIfDeletedInTransaction() throws Exception {
// given
oneKey.wrapLong(1);
oneValue.wrapLong(-1L);
twoValue.wrapLong(-2L);
oneColumnFamily.insert(oneKey, oneValue);
transactionContext.getCurrentTransaction().commit();

// when
transactionContext.runInTransaction(
() -> {
oneColumnFamily.deleteExisting(oneKey);

if (oneColumnFamily.get(oneKey) != null) {
fail("Should not be able to get deleted key.");
}
});

// then
assertThat(oneColumnFamily.get(oneKey)).isNull();
}

@Test
void shouldNotCommitOnError() {
// given
Expand Down

0 comments on commit 45ee368

Please sign in to comment.