Search in sources :

Example 1 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class HighIdTransactionApplierTest method shouldUpdateHighIdsOnExternalTransaction.

@Test
public void shouldUpdateHighIdsOnExternalTransaction() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
    // WHEN
    // Nodes
    tracker.visitNodeCommand(Commands.createNode(10, 2, 3));
    tracker.visitNodeCommand(Commands.createNode(20, 4, 5));
    // Relationships
    tracker.visitRelationshipCommand(Commands.createRelationship(4, 10, 20, 0));
    tracker.visitRelationshipCommand(Commands.createRelationship(45, 10, 20, 1));
    // Label tokens
    tracker.visitLabelTokenCommand(Commands.createLabelToken(3, 0));
    tracker.visitLabelTokenCommand(Commands.createLabelToken(5, 1));
    // Property tokens
    tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(3, 0));
    tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(5, 1));
    // Relationship type tokens
    tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(3, 0));
    tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(5, 1));
    // Relationship groups
    tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(10, 1));
    tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(20, 2));
    // Schema rules
    tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 10, new NodePropertyDescriptor(0, 1)));
    tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 20, new NodePropertyDescriptor(1, 2)));
    // Properties
    tracker.visitPropertyCommand(Commands.createProperty(10, PropertyType.STRING, 0, 6, 7));
    tracker.visitPropertyCommand(Commands.createProperty(20, PropertyType.ARRAY, 1, 8, 9));
    tracker.close();
    // THEN
    assertEquals("NodeStore", 20 + 1, neoStores.getNodeStore().getHighId());
    assertEquals("DynamicNodeLabelStore", 5 + 1, neoStores.getNodeStore().getDynamicLabelStore().getHighId());
    assertEquals("RelationshipStore", 45 + 1, neoStores.getRelationshipStore().getHighId());
    assertEquals("RelationshipTypeStore", 5 + 1, neoStores.getRelationshipTypeTokenStore().getHighId());
    assertEquals("RelationshipType NameStore", 1 + 1, neoStores.getRelationshipTypeTokenStore().getNameStore().getHighId());
    assertEquals("PropertyKeyStore", 5 + 1, neoStores.getPropertyKeyTokenStore().getHighId());
    assertEquals("PropertyKey NameStore", 1 + 1, neoStores.getPropertyKeyTokenStore().getNameStore().getHighId());
    assertEquals("LabelStore", 5 + 1, neoStores.getLabelTokenStore().getHighId());
    assertEquals("Label NameStore", 1 + 1, neoStores.getLabelTokenStore().getNameStore().getHighId());
    assertEquals("PropertyStore", 20 + 1, neoStores.getPropertyStore().getHighId());
    assertEquals("PropertyStore DynamicStringStore", 7 + 1, neoStores.getPropertyStore().getStringStore().getHighId());
    assertEquals("PropertyStore DynamicArrayStore", 9 + 1, neoStores.getPropertyStore().getArrayStore().getHighId());
    assertEquals("SchemaStore", 20 + 1, neoStores.getSchemaStore().getHighId());
}
Also used : NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 2 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class DuplicatePropertyRemoverTest method setUp.

@BeforeClass
public static void setUp() {
    GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
    api = (GraphDatabaseAPI) db;
    Label nodeLabel = Label.label("Label");
    propertyNames = new ArrayList<>();
    try (Transaction transaction = db.beginTx()) {
        node = db.createNode(nodeLabel);
        nodeId = node.getId();
        for (int i = 0; i < PROPERTY_COUNT; i++) {
            String propKey = "key" + i;
            propertyNames.add(propKey);
            String propValue = "value" + i;
            boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
            if (isBigProp) {
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
            }
            node.setProperty(propKey, propValue);
        }
        transaction.success();
    }
    Collections.shuffle(propertyNames);
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
    propertyStore = neoStores.getPropertyStore();
    remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class IndexConsultedPropertyBlockSweeperTest method setUp.

@Before
public void setUp() throws IOException {
    api = dbRule.getGraphDatabaseAPI();
    nonIndexedPropKey = "notIndexed";
    indexedPropKey = "indexed";
    Label usedLabel = Label.label("UsedLabel");
    try (Transaction transaction = api.beginTx()) {
        api.schema().indexFor(usedLabel).on(indexedPropKey).create();
        transaction.success();
    }
    try (Transaction transaction = api.beginTx()) {
        indexedValue = "value1";
        nonIndexedValue = "value2";
        Node nodeA = api.createNode(usedLabel);
        nodeA.setProperty(indexedPropKey, indexedValue);
        nodeA.setProperty(nonIndexedPropKey, nonIndexedValue);
        nodeId = nodeA.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    propertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
    propertyStore = neoStores.getPropertyStore();
    nodeRecord = getRecord(nodeStore, nodeId);
    propertyId = nodeRecord.getNextProp();
    indexMock = mock(IndexLookup.Index.class);
    when(indexMock.contains(nodeId, indexedValue)).thenReturn(true);
    propertyRemoverMock = mock(DuplicatePropertyRemover.class);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

Example 4 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class IndexLookupTest method setUp.

@BeforeClass
public static void setUp() {
    api = dbRule.getGraphDatabaseAPI();
    String notUsedIndexPropKey = "notUsed";
    String usedIndexPropKey = "used";
    Label usedLabel = Label.label("UsedLabel");
    Label notUsedLabel = Label.label("NotUsedLabel");
    try (Transaction transaction = api.beginTx()) {
        api.schema().indexFor(usedLabel).on(usedIndexPropKey).create();
        transaction.success();
    }
    try (Transaction transaction = api.beginTx()) {
        api.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
        indexedNodePropertyValue = "value1";
        notIndexedNodePropertyValue = "value2";
        Node nodeA = api.createNode(usedLabel);
        nodeA.setProperty(usedIndexPropKey, indexedNodePropertyValue);
        nodeA.setProperty(notUsedIndexPropKey, notIndexedNodePropertyValue);
        indexedNode = nodeA.getId();
        Node nodeB = api.createNode(notUsedLabel);
        nodeB.setProperty(usedIndexPropKey, notIndexedNodePropertyValue);
        nodeB.setProperty(notUsedIndexPropKey, indexedNodePropertyValue);
        notIndexedNode = nodeB.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    SchemaStore schemaStore = neoStores.getSchemaStore();
    SchemaIndexProvider schemaIndexProvider = resolver.resolveDependency(SchemaIndexProvider.class);
    indexLookup = new IndexLookup(schemaStore, schemaIndexProvider);
    LabelTokenStore labelTokenStore = neoStores.getLabelTokenStore();
    notUsedLabelId = findTokenFor(labelTokenStore, notUsedLabel.name()).id();
    usedLabelId = findTokenFor(labelTokenStore, usedLabel.name()).id();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    notUsedPropertyId = findTokenFor(propertyKeyTokenStore, notUsedIndexPropKey).id();
    usedPropertyId = findTokenFor(propertyKeyTokenStore, usedIndexPropKey).id();
}
Also used : LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Transaction(org.neo4j.graphdb.Transaction) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) BeforeClass(org.junit.BeforeClass)

Example 5 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class DumpStore method dumpFile.

private static void dumpFile(Function<File, StoreFactory> createStoreFactory, String fileName) throws Exception {
    File file = new File(fileName);
    // null means all possible ids
    long[] ids = null;
    if (file.isFile()) {
    /* If file exists, even with : in its path, then accept it straight off. */
    } else if (!file.isDirectory() && file.getName().indexOf(':') != -1) {
        /* Now we know that it is not a directory either, and that the last component
                   of the path contains a colon, thus it is very likely an attempt to use the
                   id-specifying syntax. */
        int idStart = fileName.lastIndexOf(':');
        String[] idStrings = fileName.substring(idStart + 1).split(",");
        ids = new long[idStrings.length];
        for (int i = 0; i < ids.length; i++) {
            ids[i] = Long.parseLong(idStrings[i]);
        }
        file = new File(fileName.substring(0, idStart));
        if (!file.isFile()) {
            throw new IllegalArgumentException("No such file: " + fileName);
        }
    }
    StoreType storeType = StoreType.typeOf(file.getName()).orElseThrow(() -> new IllegalArgumentException("Not a store file: " + fileName));
    try (NeoStores neoStores = createStoreFactory.apply(file).openNeoStores(storeType)) {
        switch(storeType) {
            case META_DATA:
                dumpMetaDataStore(neoStores);
                break;
            case NODE:
                dumpNodeStore(neoStores, ids);
                break;
            case RELATIONSHIP:
                dumpRelationshipStore(neoStores, ids);
                break;
            case PROPERTY:
                dumpPropertyStore(neoStores, ids);
                break;
            case SCHEMA:
                dumpSchemaStore(neoStores, ids);
                break;
            case PROPERTY_KEY_TOKEN:
                dumpPropertyKeys(neoStores, ids);
                break;
            case LABEL_TOKEN:
                dumpLabels(neoStores, ids);
                break;
            case RELATIONSHIP_TYPE_TOKEN:
                dumpRelationshipTypes(neoStores, ids);
                break;
            case RELATIONSHIP_GROUP:
                dumpRelationshipGroups(neoStores, ids);
                break;
            default:
                throw new IllegalArgumentException("Unsupported store type: " + storeType);
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)122 Test (org.junit.Test)46 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)32 Test (org.junit.jupiter.api.Test)25 ArrayList (java.util.ArrayList)17 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)16 PageCache (org.neo4j.io.pagecache.PageCache)16 NodeStore (org.neo4j.kernel.impl.store.NodeStore)15 Transaction (org.neo4j.graphdb.Transaction)14 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)13 File (java.io.File)11 IOException (java.io.IOException)11 Node (org.neo4j.graphdb.Node)11 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)11 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)9 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9