Search in sources :

Example 1 with IndexStatisticsKey

use of org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey in project neo4j by neo4j.

the class CountsSnapshotSerializer method serialize.

public static void serialize(FlushableChannel channel, CountsSnapshot countsSnapshot) throws IOException {
    channel.putLong(countsSnapshot.getTxId());
    channel.putInt(countsSnapshot.getMap().size());
    for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
        CountsKey key = pair.getKey();
        long[] value = pair.getValue();
        switch(key.recordType()) {
            case ENTITY_NODE:
                if (value.length != 1) {
                    throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
                }
                NodeKey nodeKey = (NodeKey) key;
                channel.put(ENTITY_NODE.code);
                channel.putInt(nodeKey.getLabelId());
                channel.putLong(value[0]);
                break;
            case ENTITY_RELATIONSHIP:
                if (value.length != 1) {
                    throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
                }
                RelationshipKey relationshipKey = (RelationshipKey) key;
                channel.put(ENTITY_RELATIONSHIP.code);
                channel.putInt(relationshipKey.getStartLabelId());
                channel.putInt(relationshipKey.getTypeId());
                channel.putInt(relationshipKey.getEndLabelId());
                channel.putLong(value[0]);
                break;
            case INDEX_SAMPLE:
                if (value.length != 2) {
                    throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
                }
                IndexSampleKey indexSampleKey = (IndexSampleKey) key;
                channel.put(INDEX_SAMPLE.code);
                channel.putLong(indexSampleKey.indexId());
                channel.putLong(value[0]);
                channel.putLong(value[1]);
                break;
            case INDEX_STATISTICS:
                if (value.length != 2) {
                    throw new IllegalArgumentException("CountsKey of type " + key.recordType() + " has an unexpected value.");
                }
                IndexStatisticsKey indexStatisticsKey = (IndexStatisticsKey) key;
                channel.put(INDEX_STATISTICS.code);
                channel.putLong(indexStatisticsKey.indexId());
                channel.putLong(value[0]);
                channel.putLong(value[1]);
                break;
            case EMPTY:
                throw new IllegalArgumentException("CountsKey of type EMPTY cannot be serialized.");
            default:
                throw new IllegalArgumentException("The read CountsKey has an unknown type.");
        }
    }
}
Also used : IndexSampleKey(org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey) IndexStatisticsKey(org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) RelationshipKey(org.neo4j.kernel.impl.store.counts.keys.RelationshipKey) Map(java.util.Map) NodeKey(org.neo4j.kernel.impl.store.counts.keys.NodeKey)

Example 2 with IndexStatisticsKey

use of org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey in project neo4j by neo4j.

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeIndexStatistics.

@Test
public void correctlyDeserializeIndexStatistics() throws IOException {
    //GIVEN
    long indexId = 1;
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    writeSimpleHeader(logChannel);
    logChannel.put(INDEX_STATISTICS.code);
    logChannel.putLong(indexId);
    logChannel.putLong(1);
    logChannel.putLong(1);
    //WHEN
    IndexStatisticsKey expectedNode = CountsKeyFactory.indexStatisticsKey(indexId);
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    //THEN
    assertNotNull(countsSnapshot.getMap().get(expectedNode));
    assertArrayEquals(new long[] { 1, 1 }, countsSnapshot.getMap().get(expectedNode));
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) IndexStatisticsKey(org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey) Test(org.junit.Test)

Example 3 with IndexStatisticsKey

use of org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey in project neo4j by neo4j.

the class IndexSamplingIntegrationTest method fetchIndexSizeValues.

private DoubleLongRegister fetchIndexSizeValues(GraphDatabaseService db) throws IndexNotFoundKernelException {
    try {
        // Then
        db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
        @SuppressWarnings("deprecation") GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        CountsTracker countsTracker = api.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
        IndexStatisticsKey key = CountsKeyFactory.indexStatisticsKey(indexId(api));
        return countsTracker.get(key, Registers.newDoubleLongRegister());
    } finally {
        if (db != null) {
            db.shutdown();
        }
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) IndexStatisticsKey(org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker)

Aggregations

IndexStatisticsKey (org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey)3 Map (java.util.Map)1 Test (org.junit.Test)1 CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)1 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)1 IndexSampleKey (org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey)1 NodeKey (org.neo4j.kernel.impl.store.counts.keys.NodeKey)1 RelationshipKey (org.neo4j.kernel.impl.store.counts.keys.RelationshipKey)1 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1