Search in sources :

Example 81 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class CoreBootstrapperTest method shouldSetAllCoreState.

@Test
public void shouldSetAllCoreState() throws Exception {
    // given
    int nodeCount = 100;
    FileSystemAbstraction fileSystem = fileSystemRule.get();
    File classicNeo4jStore = RestoreClusterUtils.createClassicNeo4jStore(testDirectory.directory(), fileSystem, nodeCount, Standard.LATEST_NAME);
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    CoreBootstrapper bootstrapper = new CoreBootstrapper(classicNeo4jStore, pageCache, fileSystem, Config.defaults(), NullLogProvider.getInstance());
    // when
    Set<MemberId> membership = asSet(randomMember(), randomMember(), randomMember());
    CoreSnapshot snapshot = bootstrapper.bootstrap(membership);
    // then
    assertEquals(nodeCount, ((IdAllocationState) snapshot.get(CoreStateType.ID_ALLOCATION)).firstUnallocated(IdType.NODE));
    /* Bootstrapped state is created in RAFT land at index -1 and term -1. */
    assertEquals(0, snapshot.prevIndex());
    assertEquals(0, snapshot.prevTerm());
    /* Lock is initially not taken. */
    assertEquals(new ReplicatedLockTokenState(), snapshot.get(CoreStateType.LOCK_TOKEN));
    /* Raft has the bootstrapped set of members initially. */
    assertEquals(membership, ((RaftCoreState) snapshot.get(CoreStateType.RAFT_CORE_STATE)).committed().members());
    /* The session state is initially empty. */
    assertEquals(new GlobalSessionTrackerState(), snapshot.get(CoreStateType.SESSION_TRACKER));
    LastCommittedIndexFinder lastCommittedIndexFinder = new LastCommittedIndexFinder(new ReadOnlyTransactionIdStore(pageCache, classicNeo4jStore), new ReadOnlyTransactionStore(pageCache, fileSystem, classicNeo4jStore, new Monitors()), NullLogProvider.getInstance());
    long lastCommittedIndex = lastCommittedIndexFinder.getLastCommittedIndex();
    assertEquals(-1, lastCommittedIndex);
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LastCommittedIndexFinder(org.neo4j.causalclustering.core.state.machines.tx.LastCommittedIndexFinder) ReadOnlyTransactionStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore) GlobalSessionTrackerState(org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreSnapshot(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) Monitors(org.neo4j.kernel.monitoring.Monitors) ReplicatedLockTokenState(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenState) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 82 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction 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 83 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class SecurityLogTest method shouldRotateLog.

@Test
public void shouldRotateLog() throws IOException {
    SecurityLog securityLog = new SecurityLog(config, fileSystemRule.get(), Runnable::run);
    securityLog.info("line 1");
    securityLog.info("line 2");
    FileSystemAbstraction fs = fileSystemRule.get();
    File activeLogFile = config.get(SecuritySettings.security_log_filename);
    assertThat(fs.fileExists(activeLogFile), equalTo(true));
    assertThat(fs.fileExists(archive(1)), equalTo(true));
    assertThat(fs.fileExists(archive(2)), equalTo(false));
    String[] activeLines = readLogFile(fs, activeLogFile);
    assertThat(activeLines, array(containsString("line 2")));
    String[] archiveLines = readLogFile(fs, archive(1));
    assertThat(archiveLines, array(containsString("line 1")));
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 84 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class RestoreDatabaseCommandTest method forceShouldRespectStoreLock.

@Test
public void forceShouldRespectStoreLock() throws Exception {
    String databaseName = "to";
    Config config = configWith(Config.empty(), databaseName, directory.absolutePath().getAbsolutePath());
    File fromPath = new File(directory.absolutePath(), "from");
    File toPath = config.get(DatabaseManagementSystemSettings.database_path);
    int fromNodeCount = 10;
    int toNodeCount = 20;
    createDbAt(fromPath, fromNodeCount);
    createDbAt(toPath, toNodeCount);
    FileSystemAbstraction fs = fileSystemRule.get();
    try (StoreLocker storeLocker = new StoreLocker(fs)) {
        storeLocker.checkLock(toPath);
        new RestoreDatabaseCommand(fs, fromPath, config, databaseName, true).execute();
        fail("expected exception");
    } catch (Exception e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) StoreLocker(org.neo4j.kernel.internal.StoreLocker) File(java.io.File) Test(org.junit.Test)

Example 85 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class StoreMigrationIT method shouldMigrate.

@Test
public void shouldMigrate() throws Exception {
    File db = testDir.directory(baseDirName(to, from));
    FileSystemAbstraction fs = fileSystemRule.get();
    fs.deleteRecursively(db);
    GraphDatabaseService database = getGraphDatabaseService(db, from.storeVersion());
    database.execute("CREATE INDEX ON :Person(name)");
    database.execute("CREATE INDEX ON :Person(born)");
    database.execute("CREATE CONSTRAINT ON (person:Person) ASSERT exists(person.name)");
    database.execute(CREATE_QUERY);
    long beforeNodes;
    long beforeLabels;
    long beforeKeys;
    long beforeRels;
    long beforeRelTypes;
    long beforeIndexes;
    long beforeConstraints;
    try (Transaction ignore = database.beginTx()) {
        beforeNodes = database.getAllNodes().stream().count();
        beforeLabels = database.getAllLabels().stream().count();
        beforeKeys = database.getAllPropertyKeys().stream().count();
        beforeRels = database.getAllRelationships().stream().count();
        beforeRelTypes = database.getAllRelationshipTypes().stream().count();
        beforeIndexes = stream(database.schema().getIndexes()).count();
        beforeConstraints = stream(database.schema().getConstraints()).count();
    }
    database.shutdown();
    database = getGraphDatabaseService(db, to.storeVersion());
    long afterNodes;
    long afterLabels;
    long afterKeys;
    long afterRels;
    long afterRelTypes;
    long afterIndexes;
    long afterConstraints;
    try (Transaction ignore = database.beginTx()) {
        afterNodes = database.getAllNodes().stream().count();
        afterLabels = database.getAllLabels().stream().count();
        afterKeys = database.getAllPropertyKeys().stream().count();
        afterRels = database.getAllRelationships().stream().count();
        afterRelTypes = database.getAllRelationshipTypes().stream().count();
        afterIndexes = stream(database.schema().getIndexes()).count();
        afterConstraints = stream(database.schema().getConstraints()).count();
    }
    database.shutdown();
    //171
    assertEquals(beforeNodes, afterNodes);
    //2
    assertEquals(beforeLabels, afterLabels);
    //8
    assertEquals(beforeKeys, afterKeys);
    //253
    assertEquals(beforeRels, afterRels);
    //6
    assertEquals(beforeRelTypes, afterRelTypes);
    //2
    assertEquals(beforeIndexes, afterIndexes);
    //1
    assertEquals(beforeConstraints, afterConstraints);
    ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
    ConsistencyCheckService.Result result = runConsistencyChecker(db, fs, consistencyCheckService, to.storeVersion());
    if (!result.isSuccessful()) {
        fail("Database is inconsistent after migration.");
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File) Test(org.junit.Test)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7