use of jetbrains.exodus.crypto.StreamCipherProvider in project xodus by JetBrains.
the class LogRecoveryTest method cutAndCheckLastLoggableIncomplete.
private void cutAndCheckLastLoggableIncomplete(int cutSize, int max) {
openStoreAutoCommit("new_store", StoreConfig.WITHOUT_DUPLICATES);
/*final Iterator<Loggable> itr = getLog().getLoggablesIterator(0);
while (itr.hasNext()) {
final Loggable next = itr.next();
System.out.println(next.getType() + " @ " + next.getAddress());
}*/
assertLoggableTypes(getLog(), 0, seq);
env.close();
final StreamCipherProvider cipherProvider = env.getCipherProvider();
final byte[] cipherKey = env.getCipherKey();
final long cipherBasicIV = env.getCipherBasicIV();
env = null;
final long size = reader.getBlock(0).length();
writer.openOrCreateBlock(0, size - cutSize);
writer.close();
// only 'max' first loggables should remain
final LogConfig config = LogConfig.create(reader, writer).setCipherProvider(cipherProvider).setCipherKey(cipherKey).setCipherBasicIV(cipherBasicIV);
final Log newLog = Environments.newLogInstance(config);
newLog.setHighAddress(newLog.getTip(), newLog.getTip().approvedHighAddress);
assertLoggableTypes(max, newLog.getLoggableIterator(0), seq);
}
use of jetbrains.exodus.crypto.StreamCipherProvider in project xodus by JetBrains.
the class Log method readBytes.
@SuppressWarnings("ConstantConditions")
int readBytes(final byte[] output, final long address) {
final long fileAddress = getFileAddress(address);
final LogTip logTip = getTip();
final LongIterator files = logTip.logFileSet.getFilesFrom(fileAddress);
if (files.hasNext()) {
final long leftBound = files.nextLong();
final long fileSize = getFileSize(leftBound, logTip);
if (leftBound == fileAddress && fileAddress + fileSize > address) {
final Block block = reader.getBlock(fileAddress);
final int readBytes = block.read(output, address - fileAddress, output.length);
final StreamCipherProvider cipherProvider = config.getCipherProvider();
if (cipherProvider != null) {
EnvKryptKt.cryptBlocksMutable(cipherProvider, config.getCipherKey(), config.getCipherBasicIV(), address, output, 0, readBytes, LogUtil.LOG_BLOCK_ALIGNMENT);
}
notifyReadBytes(output, readBytes);
return readBytes;
}
if (fileAddress < logTip.logFileSet.getMinimum()) {
BlockNotFoundException.raise("Address is out of log space, underflow", this, address);
}
if (fileAddress >= logTip.logFileSet.getMaximum()) {
BlockNotFoundException.raise("Address is out of log space, overflow", this, address);
}
}
BlockNotFoundException.raise(this, address);
return 0;
}
Aggregations