use of org.neo4j.causalclustering.core.consensus.log.LogPosition in project neo4j by neo4j.
the class SegmentFile method getCursor.
/**
* Channels must be closed when no longer used, so that they are released back to the pool of readers.
*/
IOCursor<EntryRecord> getCursor(long logIndex) throws IOException, DisposedException {
assert logIndex > header.prevIndex();
if (!refCount.increase()) {
throw new DisposedException();
}
/* This is the relative index within the file, starting from zero. */
long offsetIndex = logIndex - (header.prevIndex() + 1);
LogPosition position = positionCache.lookup(offsetIndex);
Reader reader = readerPool.acquire(version, position.byteOffset);
try {
long currentIndex = position.logIndex;
return new EntryRecordCursor(reader, contentMarshal, currentIndex, offsetIndex, this);
} catch (EndOfStreamException e) {
readerPool.release(reader);
refCount.decrease();
return IOCursor.getEmpty();
} catch (IOException e) {
reader.close();
refCount.decrease();
throw e;
}
}
use of org.neo4j.causalclustering.core.consensus.log.LogPosition in project neo4j by neo4j.
the class PositionCacheTest method shouldReturnExactMatch.
@Test
public void shouldReturnExactMatch() throws Exception {
// given
cache.put(pos(4));
cache.put(pos(6));
cache.put(pos(8));
// when
LogPosition lookup = cache.lookup(6);
// then
assertEquals(pos(6), lookup);
}
use of org.neo4j.causalclustering.core.consensus.log.LogPosition in project neo4j by neo4j.
the class PositionCacheTest method shouldReturnBestPosition.
@Test
public void shouldReturnBestPosition() throws Exception {
// given
cache.put(pos(4));
cache.put(pos(6));
// when
LogPosition lookup = cache.lookup(7);
// then
assertEquals(pos(6), lookup);
}
use of org.neo4j.causalclustering.core.consensus.log.LogPosition in project neo4j by neo4j.
the class PositionCacheTest method shouldNotReturnPositionAhead.
@Test
public void shouldNotReturnPositionAhead() throws Exception {
// given
cache.put(pos(4));
cache.put(pos(6));
cache.put(pos(8));
// when
LogPosition lookup = cache.lookup(7);
// then
assertEquals(pos(6), lookup);
}
use of org.neo4j.causalclustering.core.consensus.log.LogPosition in project neo4j by neo4j.
the class PositionCacheTest method shouldReturnSaneDefaultPosition.
@Test
public void shouldReturnSaneDefaultPosition() throws Exception {
// when
LogPosition position = cache.lookup(5);
// then
assertEquals(BEGINNING, position);
}
Aggregations