Skip to content

Commit

Permalink
Fix multiGet corruption test and implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhubner committed Aug 29, 2024
1 parent 6cabf2c commit b06d612
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions java/rocksjni/jni_multiget_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,16 @@ jobjectArray MultiGetJNIValues::byteArrays(
}

env->DeleteLocalRef(jentry_value);
} else if (s[i].code() == ROCKSDB_NAMESPACE::Status::Code::kCorruption) {
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
return nullptr;
} else if (s[i].code() != ROCKSDB_NAMESPACE::Status::Code::kNotFound) {
// The only way to return an error for a single key is to exception the
// entire multiGet() Previous behaviour was to return a nullptr value for
// this case and potentially succesfully return values for other keys; we
// retain this behaviour. To change it, we need to do the following:
// ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
// return nullptr;
} else if (s[i].code() == ROCKSDB_NAMESPACE::Status::Code::kCorruption) {
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
return nullptr;
}
}
return jresults;
Expand Down
19 changes: 16 additions & 3 deletions java/src/test/java/org/rocksdb/MultiGetCorruptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -47,11 +49,22 @@ public void multiGetKeyException() throws RocksDBException, IOException {
createCorruptedDatabase();
try (Options options = new Options().setCreateIfMissing(true).setParanoidChecks(true);
RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
// exception.expect(RocksDBException.class);
exception.expect(RocksDBException.class);
exception.expect(new TypeSafeMatcher<RocksDBException>() {
@Override
protected boolean matchesSafely(RocksDBException e) {
return e.getStatus().getCode() == Status.Code.Corruption;
}

@Override
public void describeTo(Description description) {
description.appendText("Status.Code is not equal to Corruption");
}
});

List<byte[]> keys = new ArrayList<>();
keys.add(KEY);
List<byte[]> result = db.multiGetAsList(keys);
assertThat(result).isNotNull();
db.multiGetAsList(keys);
}
}

Expand Down

0 comments on commit b06d612

Please sign in to comment.