use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class BTreeMutable method put.
@Override
public void put(@NotNull INode ln) {
final ByteIterable value = ln.getValue();
if (value == null) {
throw new ExodusException("Value can't be null");
}
put(ln.getKey(), value);
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class EnvironmentImpl method truncateStore.
@Override
public void truncateStore(@NotNull final String storeName, @NotNull final Transaction txn) {
final ReadWriteTransaction t = throwIfReadonly(txn, "Can't truncate a store in read-only transaction");
StoreImpl store = openStore(storeName, StoreConfig.USE_EXISTING, t, false);
if (store == null) {
throw new ExodusException("Attempt to truncate unknown store '" + storeName + '\'');
}
t.storeRemoved(store);
final TreeMetaInfo metaInfoCloned = store.getMetaInfo().clone(allocateStructureId());
store = new StoreImpl(this, storeName, metaInfoCloned);
t.storeCreated(store);
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class ReentrantTransactionDispatcher method tryAcquireExclusiveTransaction.
/**
* Wait for exclusive permit during a timeout in milliseconds.
*
* @return number of acquired permits if > 0
*/
private int tryAcquireExclusiveTransaction(@NotNull final Thread thread, final int timeout) {
long nanos = TimeUnit.MILLISECONDS.toNanos(timeout);
try (CriticalSection ignored = criticalSection.enter()) {
if (getThreadPermits(thread) > 0) {
throw new ExodusException("Exclusive transaction can't be nested");
}
final Condition condition = criticalSection.newCondition();
final long currentOrder = acquireOrder++;
regularQueue.put(currentOrder, condition);
while (acquiredPermits > 0 || regularQueue.firstKey() != currentOrder) {
try {
nanos = condition.awaitNanos(nanos);
if (nanos < 0) {
break;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
if (acquiredPermits == 0 && regularQueue.firstKey() == currentOrder) {
regularQueue.pollFirstEntry();
acquiredPermits = availablePermits;
threadPermits.put(thread, availablePermits);
return availablePermits;
}
regularQueue.remove(currentOrder);
notifyNextWaiters();
}
return 0;
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class FileDataReader method truncateBlock.
@Override
public void truncateBlock(long blockAddress, long length) {
final FileBlock file = getBlock(blockAddress);
removeFileFromFileCache(file);
setWritable(file);
try {
try (SharedRandomAccessFile f = new SharedRandomAccessFile(file, "rw")) {
f.setLength(length);
}
if (logger.isInfoEnabled()) {
logger.info("Truncated file " + file.getAbsolutePath() + " to length = " + length);
}
} catch (IOException e) {
throw new ExodusException("Failed to truncate file " + file.getAbsolutePath(), e);
}
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class FileDataWriter method openOrCreateBlockImpl.
@Override
protected void openOrCreateBlockImpl(final long address, final long length) {
try {
final RandomAccessFile result = new RandomAccessFile(new File(dir, LogUtil.getLogFilename(address)), "rw");
result.seek(length);
if (length != result.length()) {
result.setLength(length);
forceSync(result);
}
file = result;
} catch (IOException ioe) {
throw new ExodusException(ioe);
}
}
Aggregations