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());
}
}
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");
}
Aggregations