diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java index a3351969a2c..e39649fca85 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java @@ -197,18 +197,30 @@ public List backup(OutputStream out, Map options, final } catch (Exception e) { OLogManager.instance().error(this, "Error on callback invocation during backup", e); } + OLogSequenceNumber freezeLSN = null; + if (writeAheadLog != null) { + freezeLSN = writeAheadLog.begin(); + writeAheadLog.addCutTillLimit(freezeLSN); + } - final OutputStream bo = bufferSize > 0 ? new BufferedOutputStream(out, bufferSize) : out; try { - return OZIPCompressionUtil - .compressDirectory(getStoragePath().toString(), bo, new String[] { ".fl", O2QCache.CACHE_STATISTIC_FILE_EXTENSION }, - iOutput, compressionLevel); + final OutputStream bo = bufferSize > 0 ? new BufferedOutputStream(out, bufferSize) : out; + try { + return OZIPCompressionUtil + .compressDirectory(getStoragePath().toString(), bo, new String[] { ".fl", O2QCache.CACHE_STATISTIC_FILE_EXTENSION }, + iOutput, compressionLevel); + } finally { + if (bufferSize > 0) { + bo.flush(); + bo.close(); + } + } } finally { - if (bufferSize > 0) { - bo.flush(); - bo.close(); + if (freezeLSN != null) { + writeAheadLog.removeCutTillLimit(freezeLSN); } } + } finally { release(); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/wal/ODiskWriteAheadLog.java b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/wal/ODiskWriteAheadLog.java index 05405c94214..c906d67578a 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/wal/ODiskWriteAheadLog.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/wal/ODiskWriteAheadLog.java @@ -981,21 +981,13 @@ public void addCutTillLimit(OLogSequenceNumber lsn) { if (lsn == null) throw new NullPointerException(); - while (true) { - final Integer oldCounter = cutTillLimits.get(lsn); - - final Integer newCounter; + syncObject.lock(); + try { - if (oldCounter == null) { - if (cutTillLimits.putIfAbsent(lsn, 1) == null) - break; - } else { - newCounter = oldCounter + 1; + cutTillLimits.merge(lsn, 1, (a, b) -> a + b); - if (cutTillLimits.replace(lsn, oldCounter, newCounter)) { - break; - } - } + } finally { + syncObject.unlock(); } } @@ -1004,23 +996,23 @@ public void removeCutTillLimit(OLogSequenceNumber lsn) { if (lsn == null) throw new NullPointerException(); - while (true) { + syncObject.lock(); + try { final Integer oldCounter = cutTillLimits.get(lsn); - if (oldCounter == null) throw new IllegalArgumentException(String.format("Limit %s is going to be removed but it was not added", lsn)); final Integer newCounter = oldCounter - 1; - if (cutTillLimits.replace(lsn, oldCounter, newCounter)) { - if (newCounter == 0) { - cutTillLimits.remove(lsn, newCounter); - } - break; + if (newCounter == 0) { + cutTillLimits.remove(lsn); + } else { + cutTillLimits.put(lsn, newCounter); } + } finally { + syncObject.unlock(); } } - private OLogSegment removeHeadSegmentFromList() { if (logSegments.size() < 2) return null;