Search in sources :

Example 1 with SubScheduledExecutorService

use of com.orientechnologies.common.concur.executors.SubScheduledExecutorService in project orientdb by orientechnologies.

the class ODiskWriteAheadLog method moveLsnAfter.

@Override
public void moveLsnAfter(OLogSequenceNumber lsn) throws IOException {
    syncObject.lock();
    try {
        if (!activeOperations.isEmpty())
            throw new OStorageException("Can not change end of WAL because there are active atomic operations in the log.");
        if (end() == null)
            throw new OStorageException("Can not change end of WAL because WAL is empty");
        if (end().compareTo(lsn) > 0)
            return;
        OLogSegment last = logSegments.get(logSegments.size() - 1);
        last.stopFlush(true);
        if (last.filledUpTo() == 0) {
            last.delete(false);
            logSegments.remove(logSegments.size() - 1);
        }
        last = new OLogSegment(this, new File(walLocation, getSegmentName(lsn.getSegment() + 1)), fileTTL, maxPagesCacheSize, performanceStatisticManager, new SubScheduledExecutorService(autoFileCloser), new SubScheduledExecutorService(commitExecutor));
        last.init(fileDataBuffer);
        last.startFlush();
        logSegments.add(last);
    } finally {
        syncObject.unlock();
    }
}
Also used : SubScheduledExecutorService(com.orientechnologies.common.concur.executors.SubScheduledExecutorService) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 2 with SubScheduledExecutorService

use of com.orientechnologies.common.concur.executors.SubScheduledExecutorService in project orientdb by orientechnologies.

the class ODiskWriteAheadLog method internalLog.

/**
   * it log a record getting the serialized content as paramenter.
   *
   * @param record
   * @param recordContent
   *
   * @return
   *
   * @throws IOException
   */
private OLogSequenceNumber internalLog(OWALRecord record, byte[] recordContent) throws IOException {
    syncObject.lock();
    try {
        checkForClose();
        if (segmentCreationFlag && record instanceof OOperationUnitRecord && !activeOperations.contains(((OOperationUnitRecord) record).getOperationUnitId())) {
            while (segmentCreationFlag) {
                try {
                    segmentCreationComplete.await();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new OInterruptedException("Segment creation was interrupted");
                }
            }
        }
        OLogSegment last = logSegments.get(logSegments.size() - 1);
        long lastSize = last.filledUpTo();
        final OLogSequenceNumber lsn = last.logRecord(recordContent);
        record.setLsn(lsn);
        if (record.isUpdateMasterRecord()) {
            lastCheckpoint = lsn;
            if (useFirstMasterRecord) {
                firstMasterRecord = lsn;
                writeMasterRecord(0, firstMasterRecord);
                useFirstMasterRecord = false;
            } else {
                secondMasterRecord = lsn;
                writeMasterRecord(1, secondMasterRecord);
                useFirstMasterRecord = true;
            }
        }
        final long sizeDiff = last.filledUpTo() - lastSize;
        logSize += sizeDiff;
        if (last.filledUpTo() >= maxSegmentSize) {
            segmentCreationFlag = true;
            if (record instanceof OAtomicUnitEndRecord && activeOperations.size() == 1 || (!(record instanceof OOperationUnitRecord) && activeOperations.isEmpty())) {
                last.stopFlush(true);
                last = new OLogSegment(this, new File(walLocation, getSegmentName(last.getOrder() + 1)), fileTTL, maxPagesCacheSize, performanceStatisticManager, new SubScheduledExecutorService(autoFileCloser), new SubScheduledExecutorService(commitExecutor));
                last.init(fileDataBuffer);
                last.startFlush();
                logSegments.add(last);
                segmentCreationFlag = false;
                segmentCreationComplete.signalAll();
            }
        }
        if (logSize > walSizeLimit && logSegments.size() > 1) {
            for (WeakReference<OFullCheckpointRequestListener> listenerWeakReference : fullCheckpointListeners) {
                final OFullCheckpointRequestListener listener = listenerWeakReference.get();
                if (listener != null)
                    listener.requestCheckpoint();
            }
        }
        return lsn;
    } finally {
        syncObject.unlock();
    }
}
Also used : SubScheduledExecutorService(com.orientechnologies.common.concur.executors.SubScheduledExecutorService) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OFullCheckpointRequestListener(com.orientechnologies.orient.core.storage.impl.local.OFullCheckpointRequestListener) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException)

Example 3 with SubScheduledExecutorService

use of com.orientechnologies.common.concur.executors.SubScheduledExecutorService in project orientdb by orientechnologies.

the class ODiskWriteAheadLog method newSegment.

@Override
public void newSegment() throws IOException {
    syncObject.lock();
    try {
        if (!activeOperations.isEmpty())
            throw new OStorageException("Can not change end of WAL because there are active atomic operations in the log.");
        OLogSegment last = logSegments.get(logSegments.size() - 1);
        if (last.filledUpTo() == 0) {
            return;
        }
        last.stopFlush(true);
        last = new OLogSegment(this, new File(walLocation, getSegmentName(last.getOrder() + 1)), fileTTL, maxPagesCacheSize, performanceStatisticManager, new SubScheduledExecutorService(autoFileCloser), new SubScheduledExecutorService(commitExecutor));
        last.init(fileDataBuffer);
        last.startFlush();
        logSegments.add(last);
    } finally {
        syncObject.unlock();
    }
}
Also used : SubScheduledExecutorService(com.orientechnologies.common.concur.executors.SubScheduledExecutorService) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Aggregations

SubScheduledExecutorService (com.orientechnologies.common.concur.executors.SubScheduledExecutorService)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)2 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OFullCheckpointRequestListener (com.orientechnologies.orient.core.storage.impl.local.OFullCheckpointRequestListener)1