From b9f8691902b0abb2c13cecaa255d41cee9083468 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 9 Sep 2011 11:43:44 +0200 Subject: [PATCH] LocalHistory: some assertions are removed due to bug fix in RandomAccessDataFile --- .../history/core/ChangeListStorageImpl.java | 68 ++----------------- .../history/core/LocalHistoryStorage.java | 5 -- 2 files changed, 5 insertions(+), 68 deletions(-) diff --git a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java index 9e0dcd8fe3c4..3daced89af04 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java @@ -25,7 +25,6 @@ import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.newvfs.ManagingFS; @@ -37,10 +36,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.event.HyperlinkEvent; -import java.io.*; +import java.io.DataInputStream; +import java.io.File; +import java.io.IOException; import java.text.DateFormat; import java.text.MessageFormat; -import java.util.Arrays; public class ChangeListStorageImpl implements ChangeListStorage { private static final int VERSION = 5; @@ -207,76 +207,21 @@ public class ChangeListStorageImpl implements ChangeListStorage { if (isCompletelyBroken) return; try { - int id = myStorage.createNextRecord(); - byte[] writtenBytes = changeSetToBytes(changeSet); - assertCorrectlyWritten(writtenBytes); - - AbstractStorage.StorageDataOutput out = myStorage.writeStream(id, true); + AbstractStorage.StorageDataOutput out = myStorage.writeStream(myStorage.createNextRecord(), true); try { - out.write(writtenBytes); + changeSet.write(out); } finally { out.close(); } myStorage.setLastId(myLastId); myStorage.force(); - - // todo remove this when bug is found - Pair os = myStorage.getOffsetAndSize(id); - String message = - "Block was written: " + id + " offset: " + os.first + " size: " + os.second + " real bytes size: " + writtenBytes.length; - LocalHistoryLog.LOG - .info(message); - if (os.second != writtenBytes.length) throw new IOException("wrong space was allocated for the record!\n" + message); - - // todo remove this when bug is found - if (ApplicationManagerEx.getApplicationEx().isInternal()) { - try { - byte[] readBytes = myStorage.readBytes(id); - assertCorrectlyWritten(readBytes); - } - catch (IOException e) { - handleError(e, "failed to check the just-written block: " + id); - } - } } catch (IOException e) { handleError(e, null); } } - private byte[] changeSetToBytes(ChangeSet changeSet) throws IOException { - ByteArrayOutputStream byteOS = new ByteArrayOutputStream(); - DataOutputStream dataOS = new DataOutputStream(byteOS); - try { - changeSet.write(dataOS); - } - finally { - dataOS.close(); - } - return byteOS.toByteArray(); - } - - private void assertCorrectlyWritten(byte[] writtenBytes) throws IOException { - ChangeSet read; - DataInputStream in = new DataInputStream(new ByteArrayInputStream(writtenBytes)); - try { - read = new ChangeSet(in); - } - finally { - in.close(); - } - byte[] readBytes = changeSetToBytes(read); - assertBytes(writtenBytes, readBytes); - } - - private void assertBytes(byte[] writtenBytes, byte[] readBytes) throws IOException { - if (!Arrays.equals(writtenBytes, readBytes)) { - throw new IOException("bytes was written incorrectly. written: " + writtenBytes.length - + " read: " + readBytes.length); - } - } - public synchronized void purge(long period, int intervalBetweenActivities, Consumer processor) { if (isCompletelyBroken) return; @@ -290,9 +235,6 @@ public class ChangeListStorageImpl implements ChangeListStorage { while (eachBlockId != 0) { processor.consume(doReadBlock(eachBlockId).changeSet); - // todo remove this when bug is found - Pair os = myStorage.getOffsetAndSize(eachBlockId); - LocalHistoryLog.LOG.info("Block was deleted: " + eachBlockId + " offset: " + os.first + " size: " + os.second); eachBlockId = doReadPrevSafely(eachBlockId, recursionGuard); } myStorage.deleteRecordsUpTo(firstObsoleteId); diff --git a/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryStorage.java b/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryStorage.java index feaf72b54de5..d9565154ec99 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryStorage.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryStorage.java @@ -147,9 +147,4 @@ public class LocalHistoryStorage extends AbstractStorage { } } } - - @Override - public byte[] readBytes(int record) throws IOException { - return super.readBytes(record); - } }