Search in sources :

Example 51 with NeoStores

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

the class ImportToolTest method shouldRespectDbConfig.

@Test
public void shouldRespectDbConfig() throws Exception {
    // GIVEN
    int arrayBlockSize = 10;
    int stringBlockSize = 12;
    File dbConfig = file("neo4j.properties");
    store(stringMap(GraphDatabaseSettings.array_block_size.name(), String.valueOf(arrayBlockSize), GraphDatabaseSettings.string_block_size.name(), String.valueOf(stringBlockSize)), dbConfig);
    List<String> nodeIds = nodeIds();
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--db-config", dbConfig.getAbsolutePath(), "--nodes", nodeData(true, Configuration.COMMAS, nodeIds, (value) -> true).getAbsolutePath());
    // THEN
    NeoStores stores = dbRule.getGraphDatabaseAPI().getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    int headerSize = Standard.LATEST_RECORD_FORMATS.dynamic().getRecordHeaderSize();
    assertEquals(arrayBlockSize + headerSize, stores.getPropertyStore().getArrayStore().getRecordSize());
    assertEquals(stringBlockSize + headerSize, stores.getPropertyStore().getStringStore().getRecordSize());
}
Also used : RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 52 with NeoStores

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

the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.

@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
    // GIVEN
    LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
    FileSystemAbstraction fs = fsRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
        // skip 7 to emulate the fact we have an hole in the committed tx ids list
        final long expectedTxId = 8L;
        store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
        ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
        // WHEN
        Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
        // THEN
        assertTrue(response instanceof TransactionObligationResponse);
        ((TransactionObligationResponse) response).accept(new Response.Handler() {

            @Override
            public void obligation(long txId) throws IOException {
                assertEquals(expectedTxId, txId);
            }

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
                throw new UnsupportedOperationException("not expected");
            }
        });
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Visitor(org.neo4j.helpers.collection.Visitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) IOException(java.io.IOException) Response(org.neo4j.com.Response) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) RequestContext(org.neo4j.com.RequestContext) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 53 with NeoStores

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

the class CoreBootstrapper method bootstrap.

public CoreSnapshot bootstrap(Set<MemberId> members) throws IOException {
    StoreFactory factory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, logProvider);
    NeoStores neoStores = factory.openAllNeoStores(true);
    neoStores.close();
    CoreSnapshot coreSnapshot = new CoreSnapshot(FIRST_INDEX, FIRST_TERM);
    coreSnapshot.add(CoreStateType.ID_ALLOCATION, deriveIdAllocationState(storeDir));
    coreSnapshot.add(CoreStateType.LOCK_TOKEN, new ReplicatedLockTokenState());
    coreSnapshot.add(CoreStateType.RAFT_CORE_STATE, new RaftCoreState(new MembershipEntry(FIRST_INDEX, members)));
    coreSnapshot.add(CoreStateType.SESSION_TRACKER, new GlobalSessionTrackerState());
    appendNullTransactionLogEntryToSetRaftIndexToMinusOne();
    return coreSnapshot;
}
Also used : CoreSnapshot(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot) MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) ReplicatedLockTokenState(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenState) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) GlobalSessionTrackerState(org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState)

Example 54 with NeoStores

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

the class StoreMigratorFrom20IT method shouldMigrate.

@Test
public void shouldMigrate() throws IOException, ConsistencyCheckIncompleteException {
    // WHEN
    StoreMigrator storeMigrator = new StoreMigrator(fs, pageCache, getConfig(), NullLogService.getInstance(), schemaIndexProvider);
    SchemaIndexMigrator indexMigrator = new SchemaIndexMigrator(fs, schemaIndexProvider, labelScanStoreProvider);
    upgrader(indexMigrator, storeMigrator).migrateIfNeeded(find20FormatStoreDirectory(storeDir.directory()));
    // THEN
    assertEquals(2, monitor.progresses().size());
    assertTrue(monitor.isStarted());
    assertTrue(monitor.isFinished());
    GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir.absolutePath()).newGraphDatabase();
    try {
        verifyDatabaseContents(database);
    } finally {
        // CLEANUP
        database.shutdown();
    }
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(storeDir.directory(), pageCache, fs, logProvider);
    try (NeoStores neoStores = storeFactory.openAllNeoStores(true)) {
        verifyNeoStore(neoStores);
    }
    assertConsistentStore(storeDir.directory());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NullLogProvider(org.neo4j.logging.NullLogProvider) LogProvider(org.neo4j.logging.LogProvider) EnterpriseGraphDatabaseFactory(org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreMigrator(org.neo4j.kernel.impl.storemigration.participant.StoreMigrator) SchemaIndexMigrator(org.neo4j.kernel.impl.storemigration.participant.SchemaIndexMigrator) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Test(org.junit.Test)

Example 55 with NeoStores

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

the class HighIdTransactionApplierTest method shouldTrackSecondaryUnitIdsAsWell.

@Test
public void shouldTrackSecondaryUnitIdsAsWell() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
    NodeRecord node = new NodeRecord(5).initialize(true, 123, true, 456, 0);
    node.setSecondaryUnitId(6);
    node.setRequiresSecondaryUnit(true);
    RelationshipRecord relationship = new RelationshipRecord(10).initialize(true, 1, 2, 3, 4, 5, 6, 7, 8, true, true);
    relationship.setSecondaryUnitId(12);
    relationship.setRequiresSecondaryUnit(true);
    RelationshipGroupRecord relationshipGroup = new RelationshipGroupRecord(8).initialize(true, 0, 1, 2, 3, 4, 5);
    relationshipGroup.setSecondaryUnitId(20);
    relationshipGroup.setRequiresSecondaryUnit(true);
    // WHEN
    tracker.visitNodeCommand(new NodeCommand(new NodeRecord(node.getId()), node));
    tracker.visitRelationshipCommand(new RelationshipCommand(new RelationshipRecord(relationship.getId()), relationship));
    tracker.visitRelationshipGroupCommand(new RelationshipGroupCommand(new RelationshipGroupRecord(relationshipGroup.getId()), relationshipGroup));
    tracker.close();
    // THEN
    assertEquals(node.getSecondaryUnitId() + 1, neoStores.getNodeStore().getHighId());
    assertEquals(relationship.getSecondaryUnitId() + 1, neoStores.getRelationshipStore().getHighId());
    assertEquals(relationshipGroup.getSecondaryUnitId() + 1, neoStores.getRelationshipGroupStore().getHighId());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)77 Test (org.junit.Test)48 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)17 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)14 NodeStore (org.neo4j.kernel.impl.store.NodeStore)12 File (java.io.File)11 Transaction (org.neo4j.graphdb.Transaction)11 ArrayList (java.util.ArrayList)9 PageCache (org.neo4j.io.pagecache.PageCache)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 Node (org.neo4j.graphdb.Node)8 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)8 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)7 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)6 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)5 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)5