Search in sources :

Example 1 with LogPosition

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;
    }
}
Also used : EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) IOException(java.io.IOException) LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition)

Example 2 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition) Test(org.junit.Test)

Example 3 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition) Test(org.junit.Test)

Example 4 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition) Test(org.junit.Test)

Example 5 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.causalclustering.core.consensus.log.LogPosition) Test(org.junit.Test)

Aggregations

LogPosition (org.neo4j.causalclustering.core.consensus.log.LogPosition)5 Test (org.junit.Test)4 IOException (java.io.IOException)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1