@Override protected void openImpl(long lastIndexInSnapshot, Consumer<LogEntryProto> consumer) throws IOException { loadLogSegments(lastIndexInSnapshot, consumer); File openSegmentFile = null; LogSegment openSegment = cache.getOpenSegment(); if (openSegment != null) { openSegmentFile = storage.getStorageDir() .getOpenLogFile(openSegment.getStartIndex()); } fileLogWorker.start(Math.max(cache.getEndIndex(), lastIndexInSnapshot), openSegmentFile); }
@Override public void open(long lastIndexInSnapshot, Consumer<LogEntryProto> consumer) throws IOException { loadLogSegments(lastIndexInSnapshot, consumer); File openSegmentFile = null; LogSegment openSegment = cache.getOpenSegment(); if (openSegment != null) { openSegmentFile = storage.getStorageDir() .getOpenLogFile(openSegment.getStartIndex()); } fileLogWorker.start(Math.max(cache.getEndIndex(), lastIndexInSnapshot), openSegmentFile); super.open(lastIndexInSnapshot, consumer); }
final LogSegment currentOpenSegment = cache.getOpenSegment(); if (currentOpenSegment == null) { cache.addOpenSegment(entry.getIndex());
final LogSegment currentOpenSegment = cache.getOpenSegment(); if (currentOpenSegment == null) { cache.addOpenSegment(entry.getIndex());
@Test public void testAppendEntry() throws Exception { LogSegment closedSegment = prepareLogSegment(0, 99, false); cache.addSegment(closedSegment); final SimpleOperation m = new SimpleOperation("m"); try { LogEntryProto entry = ServerProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, 0); cache.appendEntry(entry); Assert.fail("the open segment is null"); } catch (IllegalStateException ignored) { } LogSegment openSegment = prepareLogSegment(100, 100, true); cache.addSegment(openSegment); for (long index = 101; index < 200; index++) { LogEntryProto entry = ServerProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, index); cache.appendEntry(entry); } Assert.assertNotNull(cache.getOpenSegment()); checkCache(0, 199, 100); }
Assert.assertNotNull(cache.getOpenSegment()); checkCache(1, 300, 100); Assert.assertNotNull(cache.getOpenSegment()); checkCache(1, 300, 100);
@Test public void testAppendEntry() throws Exception { LogSegment closedSegment = prepareLogSegment(0, 99, false); cache.addSegment(closedSegment); final SimpleOperation m = new SimpleOperation("m"); try { LogEntryProto entry = ProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, 0, clientId, callId); cache.appendEntry(entry); Assert.fail("the open segment is null"); } catch (IllegalStateException ignored) { } LogSegment openSegment = prepareLogSegment(100, 100, true); cache.addSegment(openSegment); for (long index = 101; index < 200; index++) { LogEntryProto entry = ProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, index, clientId, callId); cache.appendEntry(entry); } Assert.assertNotNull(cache.getOpenSegment()); checkCache(0, 199, 100); }
Assert.assertNotNull(cache.getOpenSegment()); checkCache(1, 300, 100); Assert.assertNotNull(cache.getOpenSegment()); checkCache(1, 300, 100);
ts = cache.truncate(220); checkCache(0, 219, 100); Assert.assertNull(cache.getOpenSegment()); Assert.assertEquals(0, ts.toDelete.length); Assert.assertTrue(ts.toTruncate.isOpen);
ts = cache.truncate(220); checkCache(0, 219, 100); Assert.assertNull(cache.getOpenSegment()); Assert.assertEquals(0, ts.toDelete.length); Assert.assertTrue(ts.toTruncate.isOpen);