Search in sources :

Example 1 with OWriteCacheException

use of com.orientechnologies.orient.core.exception.OWriteCacheException in project orientdb by orientechnologies.

the class OWOWCache method close.

public long[] close() throws IOException {
    flush();
    if (!commitExecutor.isShutdown()) {
        commitExecutor.shutdown();
        try {
            if (!commitExecutor.awaitTermination(5, TimeUnit.MINUTES))
                throw new OWriteCacheException("Background data flush task cannot be stopped.");
        } catch (InterruptedException e) {
            OLogManager.instance().error(this, "Data flush thread was interrupted");
            Thread.currentThread().interrupt();
            throw OException.wrapException(new OWriteCacheException("Data flush thread was interrupted"), e);
        }
    }
    final List<Long> result = new ArrayList<Long>();
    filesLock.acquireWriteLock();
    try {
        final Collection<Integer> intIds = nameIdMap.values();
        for (Integer intId : intIds) {
            if (intId < 0)
                continue;
            final long fileId = composeFileId(id, intId);
            // we remove files because when we reopen storage we will reload them
            final OFileClassic fileClassic = files.remove(fileId);
            fileClassic.close();
            result.add(fileId);
        }
        if (nameIdMapHolder != null) {
            nameIdMapHolder.setLength(0);
            for (Map.Entry<String, Integer> entry : nameIdMap.entrySet()) {
                writeNameIdEntry(new NameFileIdEntry(entry.getKey(), entry.getValue()), false);
            }
            nameIdMapHolder.getFD().sync();
            nameIdMapHolder.close();
        }
        nameIdMap.clear();
        final long[] ds = new long[result.size()];
        int counter = 0;
        for (long id : result) {
            ds[counter] = id;
            counter++;
        }
        return ds;
    } finally {
        filesLock.releaseWriteLock();
    }
}
Also used : OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic) OWriteCacheException(com.orientechnologies.orient.core.exception.OWriteCacheException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with OWriteCacheException

use of com.orientechnologies.orient.core.exception.OWriteCacheException in project orientdb by orientechnologies.

the class OWOWCache method delete.

public long[] delete() throws IOException {
    final List<Long> result = new ArrayList<Long>();
    filesLock.acquireWriteLock();
    try {
        for (int intId : nameIdMap.values()) {
            if (intId < 0)
                continue;
            final long externalId = composeFileId(id, intId);
            doDeleteFile(externalId);
            result.add(externalId);
        }
        if (nameIdMapHolderFile != null) {
            if (nameIdMapHolderFile.exists()) {
                nameIdMapHolder.close();
                if (!nameIdMapHolderFile.delete())
                    throw new OStorageException("Cannot delete disk cache file which contains name-id mapping.");
            }
            nameIdMapHolder = null;
            nameIdMapHolderFile = null;
        }
    } finally {
        filesLock.releaseWriteLock();
    }
    if (!commitExecutor.isShutdown()) {
        commitExecutor.shutdown();
        try {
            if (!commitExecutor.awaitTermination(5, TimeUnit.MINUTES))
                throw new OWriteCacheException("Background data flush task cannot be stopped.");
        } catch (InterruptedException e) {
            OLogManager.instance().error(this, "Data flush thread was interrupted");
            throw new OInterruptedException("Data flush thread was interrupted");
        }
    }
    final long[] ids = new long[result.size()];
    int counter = 0;
    for (long id : result) {
        ids[counter] = id;
        counter++;
    }
    return ids;
}
Also used : OWriteCacheException(com.orientechnologies.orient.core.exception.OWriteCacheException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

OWriteCacheException (com.orientechnologies.orient.core.exception.OWriteCacheException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)1 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)1