Search in sources :

Example 16 with ExodusException

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);
}
Also used : CompoundByteIterable(jetbrains.exodus.CompoundByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ExodusException(jetbrains.exodus.ExodusException)

Example 17 with ExodusException

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);
}
Also used : TreeMetaInfo(jetbrains.exodus.tree.TreeMetaInfo) ExodusException(jetbrains.exodus.ExodusException)

Example 18 with ExodusException

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;
}
Also used : CriticalSection(jetbrains.exodus.core.execution.locks.CriticalSection) Condition(java.util.concurrent.locks.Condition) ExodusException(jetbrains.exodus.ExodusException)

Example 19 with ExodusException

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);
    }
}
Also used : SharedRandomAccessFile(jetbrains.exodus.util.SharedRandomAccessFile) IOException(java.io.IOException) ExodusException(jetbrains.exodus.ExodusException)

Example 20 with ExodusException

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);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ExodusException(jetbrains.exodus.ExodusException)

Aggregations

ExodusException (jetbrains.exodus.ExodusException)21 File (java.io.File)6 IOException (java.io.IOException)6 RandomAccessFile (java.io.RandomAccessFile)3 CriticalSection (jetbrains.exodus.core.execution.locks.CriticalSection)3 ByteIterable (jetbrains.exodus.ByteIterable)2 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)2 Job (jetbrains.exodus.core.execution.Job)2 EnvironmentImpl (jetbrains.exodus.env.EnvironmentImpl)2 FileDataReader (jetbrains.exodus.io.FileDataReader)2 FileDataWriter (jetbrains.exodus.io.FileDataWriter)2 SharedRandomAccessFile (jetbrains.exodus.util.SharedRandomAccessFile)2 UncheckedIOException (java.io.UncheckedIOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 FileChannel (java.nio.channels.FileChannel)1 Map (java.util.Map)1 Condition (java.util.concurrent.locks.Condition)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)1