Search in sources :

Example 1 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class StaticArrayEntryTest method checkEntry.

private static void checkEntry(Entry e, Map<Integer, Long> entries) {
    ReadBuffer rb = e.asReadBuffer();
    int key = rb.getInt();
    assertEquals(e.getValuePosition(), rb.getPosition());
    assertTrue(e.hasValue());
    long value = rb.getLong();
    assertFalse(rb.hasRemaining());
    assertEquals((long) entries.get(key), value);
    rb = e.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    assertEquals(key, rb.getInt());
    assertFalse(rb.hasRemaining());
    rb = e.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    assertEquals(value, rb.getLong());
    assertFalse(rb.hasRemaining());
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer)

Example 2 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class StaticArrayEntryTest method testInversion.

@Test
public void testInversion() {
    WriteBuffer wb = new WriteByteBuffer(20);
    wb.putInt(1).putInt(2).putInt(3).putInt(4);
    Entry entry = new StaticArrayEntry(wb.getStaticBufferFlipBytes(4, 2 * 4), 3 * 4);
    ReadBuffer rb = entry.asReadBuffer();
    assertEquals(1, rb.getInt());
    assertEquals(2, rb.subrange(4, true).getInt());
    assertEquals(~2, rb.getInt());
    assertEquals(3, rb.getInt());
    assertEquals(4, rb.getInt());
    rb.movePositionTo(entry.getValuePosition());
    assertEquals(4, rb.getInt());
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Test(org.junit.jupiter.api.Test)

Example 3 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class StaticArrayEntryTest method testReadWrite.

@Test
public void testReadWrite() {
    WriteBuffer b = new WriteByteBuffer(10);
    for (int i = 1; i < 4; i++) b.putByte((byte) i);
    for (int i = 1; i < 4; i++) b.putShort((short) i);
    for (int i = 1; i < 4; i++) b.putInt(i);
    for (int i = 1; i < 4; i++) b.putLong(i);
    for (int i = 1; i < 4; i++) b.putFloat(i);
    for (int i = 1; i < 4; i++) b.putDouble(i);
    for (int i = 101; i < 104; i++) b.putChar((char) i);
    ReadBuffer r = b.getStaticBuffer().asReadBuffer();
    assertEquals(1, r.getByte());
    assertArrayEquals(new byte[] { 2, 3 }, r.getBytes(2));
    assertEquals(1, r.getShort());
    assertArrayEquals(new short[] { 2, 3 }, r.getShorts(2));
    assertEquals(1, r.getInt());
    assertEquals(2, r.getInt());
    assertArrayEquals(new int[] { 3 }, r.getInts(1));
    assertEquals(1, r.getLong());
    assertArrayEquals(new long[] { 2, 3 }, r.getLongs(2));
    assertEquals(1.0, r.getFloat(), 0.00001);
    assertArrayEquals(new float[] { 2.0f, 3.0f }, r.getFloats(2));
    assertEquals(1, r.getDouble(), 0.0001);
    assertArrayEquals(new double[] { 2.0, 3.0 }, r.getDoubles(2));
    assertEquals((char) 101, r.getChar());
    assertEquals((char) 102, r.getChar());
    assertArrayEquals(new char[] { (char) 103 }, r.getChars(1));
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class StaticArrayEntryTest method testArrayBuffer.

@Test
public void testArrayBuffer() {
    WriteBuffer wb = new WriteByteBuffer(128);
    wb.putInt(1).putInt(2).putInt(3).putInt(4);
    int valuePos = wb.getPosition();
    wb.putInt(5).putInt(6);
    Entry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
    assertEquals(4 * 4, entry.getValuePosition());
    assertEquals(6 * 4, entry.length());
    assertTrue(entry.hasValue());
    for (int i = 1; i <= 6; i++) assertEquals(i, entry.getInt((i - 1) * 4));
    ReadBuffer rb = entry.asReadBuffer();
    for (int i = 1; i <= 6; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
    assertNull(entry.getCache());
    entry.setCache(cache);
    assertEquals(cache, entry.getCache());
    rb = entry.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    for (int i = 1; i <= 4; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
    rb = entry.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    for (int i = 5; i <= 6; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Test(org.junit.jupiter.api.Test)

Example 5 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class ManagementLogger method read.

@Override
public void read(Message message) {
    ReadBuffer in = message.getContent().asReadBuffer();
    String senderId = message.getSenderId();
    Serializer serializer = graph.getDataSerializer();
    MgmtLogType logType = serializer.readObjectNotNull(in, MgmtLogType.class);
    Preconditions.checkNotNull(logType);
    switch(logType) {
        case CACHED_TYPE_EVICTION:
            {
                long evictionId = VariableLong.readPositive(in);
                long numEvictions = VariableLong.readPositive(in);
                for (int i = 0; i < numEvictions; i++) {
                    long typeId = VariableLong.readPositive(in);
                    schemaCache.expireSchemaElement(typeId);
                    for (JanusGraphTransaction tx : graph.getOpenTransactions()) {
                        tx.expireSchemaElement(typeId);
                    }
                }
                final GraphCacheEvictionAction action = serializer.readObjectNotNull(in, GraphCacheEvictionAction.class);
                Preconditions.checkNotNull(action);
                final Thread ack = new Thread(new SendAckOnTxClose(evictionId, senderId, graph.getOpenTransactions(), action, graph.getGraphName()));
                ack.setDaemon(true);
                ack.start();
                break;
            }
        case CACHED_TYPE_EVICTION_ACK:
            {
                String receiverId = serializer.readObjectNotNull(in, String.class);
                long evictionId = VariableLong.readPositive(in);
                if (receiverId.equals(graph.getConfiguration().getUniqueGraphId())) {
                    // Acknowledgements targeted at this instance
                    EvictionTrigger evictTrigger = evictionTriggerMap.get(evictionId);
                    if (evictTrigger != null) {
                        evictTrigger.receivedAcknowledgement(senderId);
                    } else
                        log.error("Could not find eviction trigger for {} from {}", evictionId, senderId);
                }
                break;
            }
        default:
            assert logType == MgmtLogType.CONFIG_MUTATION;
            break;
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Aggregations

ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)29 Test (org.junit.jupiter.api.Test)19 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)16 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)9 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)7 WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)7 Instant (java.time.Instant)3 Entry (org.janusgraph.diskstorage.Entry)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 TClass2 (org.janusgraph.graphdb.serializer.attributes.TClass2)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Geoshape (org.janusgraph.core.attribute.Geoshape)2 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)2 TClass1 (org.janusgraph.graphdb.serializer.attributes.TClass1)2 TClass1Serializer (org.janusgraph.graphdb.serializer.attributes.TClass1Serializer)2 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)2 LoggerFactory (org.slf4j.LoggerFactory)2 LongObjectHashMap (com.carrotsearch.hppc.LongObjectHashMap)1