Search in sources :

Example 21 with LogEntry

use of herddb.log.LogEntry in project herddb by diennea.

the class FileCommitLogTest method testDiskFullLogBrokenEntry.

@Test
public void testDiskFullLogBrokenEntry() throws Exception {
    try (FileCommitLogManager manager = new FileCommitLogManager(folder.newFolder().toPath(), 64 * 1024 * 1024)) {
        int writeCount = 0;
        final long _startWrite = System.currentTimeMillis();
        try (CommitLog log = manager.createCommitLog("tt")) {
            log.startWriting();
            for (int i = 0; i < 100; i++) {
                log.log(LogEntryFactory.beginTransaction(0), false);
                writeCount++;
            }
            FileCommitLog fileCommitLog = (FileCommitLog) log;
            // simulate end of disk
            byte[] dummyEntry = LogEntryFactory.beginTransaction(0).serialize();
            // header
            fileCommitLog.getWriter().out.write(ENTRY_START);
            fileCommitLog.getWriter().out.writeLong(0);
            // just half entry
            fileCommitLog.getWriter().out.write(dummyEntry, 0, dummyEntry.length / 2);
            // missing entry footer
            fileCommitLog.getWriter().out.flush();
        }
        final long _endWrite = System.currentTimeMillis();
        AtomicInteger readCount = new AtomicInteger();
        try (CommitLog log = manager.createCommitLog("tt")) {
            log.recovery(LogSequenceNumber.START_OF_TIME, new BiConsumer<LogSequenceNumber, LogEntry>() {

                @Override
                public void accept(LogSequenceNumber t, LogEntry u) {
                    readCount.incrementAndGet();
                }
            }, true);
        }
        final long _endRead = System.currentTimeMillis();
        assertEquals(writeCount, readCount.get());
        System.out.println("Write time: " + (_endWrite - _startWrite) + " ms");
        System.out.println("Read time: " + (_endRead - _endWrite) + " ms");
        // must be able to read twice
        AtomicInteger readCount2 = new AtomicInteger();
        try (CommitLog log = manager.createCommitLog("tt")) {
            log.recovery(LogSequenceNumber.START_OF_TIME, new BiConsumer<LogSequenceNumber, LogEntry>() {

                @Override
                public void accept(LogSequenceNumber t, LogEntry u) {
                    readCount2.incrementAndGet();
                }
            }, true);
        }
        assertEquals(writeCount, readCount.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogSequenceNumber(herddb.log.LogSequenceNumber) CommitLog(herddb.log.CommitLog) LogEntry(herddb.log.LogEntry) Test(org.junit.Test)

Example 22 with LogEntry

use of herddb.log.LogEntry in project herddb by diennea.

the class FileCommitLogTest method testLogMultiFiles.

@Test
public void testLogMultiFiles() throws Exception {
    FileCommitLogManager manager = new FileCommitLogManager(folder.newFolder().toPath(), 1024);
    int writeCount = 0;
    final long _startWrite = System.currentTimeMillis();
    try (FileCommitLog log = manager.createCommitLog("tt")) {
        log.startWriting();
        for (int i = 0; i < 10_000; i++) {
            log.log(LogEntryFactory.beginTransaction(0), false);
            writeCount++;
        }
    }
    final long _endWrite = System.currentTimeMillis();
    AtomicInteger readCount = new AtomicInteger();
    try (CommitLog log = manager.createCommitLog("tt")) {
        log.recovery(LogSequenceNumber.START_OF_TIME, new BiConsumer<LogSequenceNumber, LogEntry>() {

            @Override
            public void accept(LogSequenceNumber t, LogEntry u) {
                readCount.incrementAndGet();
            }
        }, true);
    }
    final long _endRead = System.currentTimeMillis();
    assertEquals(writeCount, readCount.get());
    System.out.println("Write time: " + (_endWrite - _startWrite) + " ms");
    System.out.println("Read time: " + (_endRead - _endWrite) + " ms");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogSequenceNumber(herddb.log.LogSequenceNumber) CommitLog(herddb.log.CommitLog) LogEntry(herddb.log.LogEntry) Test(org.junit.Test)

Aggregations

LogEntry (herddb.log.LogEntry)22 CommitLogResult (herddb.log.CommitLogResult)14 LogNotAvailableException (herddb.log.LogNotAvailableException)14 StatementExecutionException (herddb.model.StatementExecutionException)12 DataStorageManagerException (herddb.storage.DataStorageManagerException)11 DumpedLogEntry (herddb.backup.DumpedLogEntry)10 LogSequenceNumber (herddb.log.LogSequenceNumber)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommitLog (herddb.log.CommitLog)6 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)6 EOFException (java.io.EOFException)6 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)5 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)5 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)5 TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)5 TableDoesNotExistException (herddb.model.TableDoesNotExistException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Test (org.junit.Test)5 ClientSideMetadataProviderException (herddb.client.ClientSideMetadataProviderException)4 HDBException (herddb.client.HDBException)4