use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class GarbageCollector method doCleanFiles.
private boolean doCleanFiles(@NotNull final Iterator<Long> fragmentedFiles) {
// if there are no more files then even don't start a txn
if (!fragmentedFiles.hasNext()) {
return true;
}
final LongSet cleanedFiles = new PackedLongHashSet();
final ReadWriteTransaction txn;
try {
final TransactionBase tx = useRegularTxn ? env.beginTransaction() : env.beginGCTransaction();
// tx can be read-only, so we should manually finish it (see XD-667)
if (tx.isReadonly()) {
tx.abort();
return false;
}
txn = (ReadWriteTransaction) tx;
} catch (TransactionAcquireTimeoutException ignore) {
return false;
}
final boolean isTxnExclusive = txn.isExclusive();
try {
final OOMGuard guard = new OOMGuard();
final long started = System.currentTimeMillis();
while (fragmentedFiles.hasNext()) {
final long fileAddress = fragmentedFiles.next();
cleanSingleFile(fileAddress, txn);
cleanedFiles.add(fileAddress);
if (!isTxnExclusive) {
// do not process more than one file in a non-exclusive txn
break;
}
if (started + ec.getGcTransactionTimeout() < System.currentTimeMillis()) {
// break by timeout
break;
}
if (guard.isItCloseToOOM()) {
// break because of the risk of OutOfMemoryError
break;
}
}
if (!txn.forceFlush()) {
// paranoiac check
if (isTxnExclusive) {
throw new ExodusException("Can't be: exclusive txn should be successfully flushed");
}
return false;
}
} catch (Throwable e) {
throw ExodusException.toExodusException(e);
} finally {
txn.abort();
}
if (!cleanedFiles.isEmpty()) {
for (final Long file : cleanedFiles) {
pendingFilesToDelete.add(file);
utilizationProfile.removeFile(file);
}
utilizationProfile.estimateTotalBytes();
env.executeTransactionSafeTask(new Runnable() {
@Override
public void run() {
final int filesDeletionDelay = ec.getGcFilesDeletionDelay();
if (filesDeletionDelay == 0) {
for (final Long file : cleanedFiles) {
deletionQueue.offer(file);
}
} else {
DeferredIO.getJobProcessor().queueIn(new Job() {
@Override
protected void execute() {
for (final Long file : cleanedFiles) {
deletionQueue.offer(file);
}
}
}, filesDeletionDelay);
}
}
});
}
return true;
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class FileDataReader method removeBlock.
@Override
public void removeBlock(long blockAddress, @NotNull final RemoveBlockType rbt) {
final File file = new File(dir, LogUtil.getLogFilename(blockAddress));
removeFileFromFileCache(file);
setWritable(file);
final boolean deleted = rbt == RemoveBlockType.Delete ? file.delete() : renameFile(file);
if (!deleted) {
throw new ExodusException("Failed to delete " + file.getAbsolutePath());
} else if (logger.isInfoEnabled()) {
logger.info("Deleted file " + file.getAbsolutePath());
}
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class FileDataWriter method forceSync.
private static void forceSync(@NotNull final RandomAccessFile file) {
try {
final FileChannel channel = file.getChannel();
channel.force(false);
} catch (ClosedChannelException e) {
// ignore
} catch (IOException ioe) {
if (file.getChannel().isOpen()) {
throw new ExodusException(ioe);
}
}
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class Memory method dump.
public void dump(@NotNull final File location) {
location.mkdirs();
final ObjectProcedure<Map.Entry<Long, Block>> saver = new ObjectProcedure<Map.Entry<Long, Block>>() {
@Override
public boolean execute(Map.Entry<Long, Block> object) {
try {
final File dest = new File(location, LogUtil.getLogFilename(object.getKey()));
final RandomAccessFile output = new RandomAccessFile(dest, "rw");
final Block block = object.getValue();
output.write(block.getData(), 0, block.getSize());
output.close();
// output.getChannel().force(false);
} catch (IOException e) {
throw new ExodusException(e);
}
return true;
}
};
synchronized (data) {
data.forEachEntry(saver);
removedBlocks.forEachEntry(saver);
}
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class EnvironmentLockTest method openConcurrentEnvironment.
private void openConcurrentEnvironment() {
processor.start();
new Job(processor) {
@Override
protected void execute() throws Throwable {
final File dir = getEnvDirectory();
try {
env = newEnvironmentInstance(LogConfig.create(new FileDataReader(dir, 16), new FileDataWriter(dir, LOCK_ID)), new EnvironmentConfig().setLogLockTimeout(5000));
wasOpened[0] = true;
} catch (ExodusException e) {
Assert.assertTrue(e.getMessage().contains(LOCK_ID));
wasOpened[0] = false;
}
}
};
}
Aggregations