Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void recoverFromHalfConstraintAppliedBeforeCrash(System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI,java.util.List<org.neo4j.kernel.impl.transaction.TransactionRepresentation>> applier, System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI> constraintCreator, boolean composite) throws Exception
        private void RecoverFromHalfConstraintAppliedBeforeCrash(System.Action <GraphDatabaseAPI, IList <TransactionRepresentation> > applier, System.Action <GraphDatabaseAPI> constraintCreator, bool composite)
        {
            // GIVEN
            IList <TransactionRepresentation> transactions = CreateTransactionsForCreatingConstraint(constraintCreator);
            GraphDatabaseAPI db = NewDb();
            EphemeralFileSystemAbstraction crashSnapshot;

            try
            {
                Apply(db, transactions.subList(0, transactions.Count - 1));
                FlushStores(db);
                crashSnapshot = Fs.snapshot();
            }
            finally
            {
                Db.shutdown();
            }

            // WHEN
            db = ( GraphDatabaseAPI )(new TestEnterpriseGraphDatabaseFactory()).setFileSystem(crashSnapshot).newImpermanentDatabase();
            try
            {
                applier(db, transactions);

                // THEN
                using (Transaction tx = Db.beginTx())
                {
                    ConstraintDefinition constraint = single(Db.schema().getConstraints(LABEL));
                    assertEquals(LABEL.Name(), constraint.Label.name());
                    if (composite)
                    {
                        assertEquals(Arrays.asList(KEY, KEY2), Iterables.asList(constraint.PropertyKeys));
                    }
                    else
                    {
                        assertEquals(KEY, single(constraint.PropertyKeys));
                    }
                    IndexDefinition index = single(Db.schema().getIndexes(LABEL));
                    assertEquals(LABEL.Name(), single(index.Labels).name());
                    if (composite)
                    {
                        assertEquals(Arrays.asList(KEY, KEY2), Iterables.asList(index.PropertyKeys));
                    }
                    else
                    {
                        assertEquals(KEY, single(index.PropertyKeys));
                    }
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") private void crashAndRestart() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        private void CrashAndRestart()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db1 = db;
            GraphDatabaseService  db1       = _db;
            FileSystemAbstraction uncleanFs = FsRule.snapshot(db1.shutdown);

            _db = ( GraphDatabaseAPI )DatabaseFactory(uncleanFs).newImpermanentDatabase();
        }
Exemplo n.º 3
0
        /*
         * Starts a JVM, executes a tx that fails on prepare and rollbacks,
         * triggering a bug where an extra start entry for that tx is written
         * in the xa log.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testStartEntryWrittenOnceOnRollback() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestStartEntryWrittenOnceOnRollback()
        {
            File storeDir = _testDirectory.databaseDir();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db = new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase(storeDir);
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(_fs.get()).newImpermanentDatabase(storeDir);

            CreateSomeTransactions(db);
            EphemeralFileSystemAbstraction snapshot = _fs.snapshot(Db.shutdown);

            (new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabase(storeDir).shutdown();
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createGraphDbAndKillIt(org.neo4j.kernel.configuration.Config config) throws Exception
        private void CreateGraphDbAndKillIt(Config config)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db = new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(testDirectory.databaseDir()).setConfig(config.getRaw()).newGraphDatabase();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(_fs.get()).newImpermanentDatabaseBuilder(_testDirectory.databaseDir()).setConfig(config.Raw).newGraphDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode(label("FOO"));
                Db.createNode(label("BAR"));
                tx.Success();
            }

            _fs.snapshot(Db.shutdown);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void crashAndRestart() throws Exception
        private void CrashAndRestart()
        {
            FsRule.snapshot(_db.shutdown);
            _db = NewDb();
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CrashAndRebuildSlowWithDynamicStringDeletions()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(testDir.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            GraphDatabaseAPI           db                 = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(Fs.get()).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            IList <long>               deletedNodeIds     = ProduceNonCleanDefraggedStringStore(db);
            IDictionary <IdType, long> highIdsBeforeCrash = GetHighIds(db);

            // Make sure all of our changes are actually written to the files, since any background flushing could
            // mess up the check-sums in non-deterministic ways
            Db.DependencyResolver.resolveDependency(typeof(PageCache)).flushAndForce();

            long checksumBefore  = Fs.get().checksum();
            long checksumBefore2 = Fs.get().checksum();

            assertThat(checksumBefore, Matchers.equalTo(checksumBefore2));

            EphemeralFileSystemAbstraction snapshot = Fs.snapshot(Db.shutdown);

            long snapshotChecksum = snapshot.Checksum();

            if (snapshotChecksum != checksumBefore)
            {
                using (Stream @out = new FileStream(TestDir.file("snapshot.zip"), FileMode.Create, FileAccess.Write))
                {
                    snapshot.DumpZip(@out);
                }
                using (Stream @out = new FileStream(TestDir.file("fs.zip"), FileMode.Create, FileAccess.Write))
                {
                    Fs.get().dumpZip(@out);
                }
            }
            assertThat(snapshotChecksum, equalTo(checksumBefore));

            // Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false
            AssertNumberOfFreeIdsEquals(TestDir.databaseDir(), snapshot, 0);
            GraphDatabaseAPI           newDb             = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase();
            IDictionary <IdType, long> highIdsAfterCrash = GetHighIds(newDb);

            assertEquals(highIdsBeforeCrash, highIdsAfterCrash);

            try
            {
                using (Transaction tx = newDb.BeginTx())
                {
                    // Verify that the data we didn't delete is still around
                    int nameCount = 0;
                    int relCount  = 0;
                    foreach (Node node in newDb.AllNodes)
                    {
                        nameCount++;
                        assertThat(node, inTx(newDb, hasProperty("name"), true));
                        relCount += ( int )Iterables.count(node.GetRelationships(Direction.OUTGOING));
                    }

                    assertEquals(16, nameCount);
                    assertEquals(12, relCount);

                    // Verify that the ids of the nodes we deleted are reused
                    IList <long> newIds = new List <long>();
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    assertThat(newIds, @is(deletedNodeIds));
                    tx.Success();
                }
            }
            finally
            {
                newDb.Shutdown();
                snapshot.Dispose();
            }
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doShouldRecoverFromAnything(boolean replayRecoveryExactlyFromCheckpoint) throws Exception
        private void DoShouldRecoverFromAnything(bool replayRecoveryExactlyFromCheckpoint)
        {
            AssertInitialized();
            // GIVEN
            // a tree which has had random updates and checkpoints in it, load generated with specific seed
            File           file                = _directory.file("index");
            IList <Action> load                = GenerateLoad();
            IList <Action> shuffledLoad        = RandomCausalAwareShuffle(load);
            int            lastCheckPointIndex = IndexOfLastCheckpoint(load);

            {
                // _,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_
                //                                                 ^             ^
                //                                                 |             |------------ crash flush index
                //                                                 |-------------------------- last checkpoint index
                //

                PageCache            pageCache = CreatePageCache();
                GBPTree <KEY, VALUE> index     = CreateIndex(pageCache, file);
                // Execute all actions up to and including last checkpoint ...
                Execute(shuffledLoad.subList(0, lastCheckPointIndex + 1), index);
                // ... a random amount of the remaining "unsafe" actions ...
                int numberOfRemainingActions = shuffledLoad.Count - lastCheckPointIndex - 1;
                int crashFlushIndex          = lastCheckPointIndex + _random.Next(numberOfRemainingActions) + 1;
                Execute(shuffledLoad.subList(lastCheckPointIndex + 1, crashFlushIndex), index);
                // ... flush ...
                pageCache.FlushAndForce();
                // ... execute the remaining actions
                Execute(shuffledLoad.subList(crashFlushIndex, shuffledLoad.Count), index);
                // ... and finally crash
                _fs.snapshot(throwing(() =>
                {
                    index.Dispose();
                    pageCache.Close();
                }));
            }

            // WHEN doing recovery
            IList <Action> recoveryActions;

            if (replayRecoveryExactlyFromCheckpoint)
            {
                recoveryActions = recoveryActions(load, lastCheckPointIndex + 1);
            }
            else
            {
                recoveryActions = recoveryActions(load, _random.Next(lastCheckPointIndex + 1));
            }

            // first crashing during recovery
            int numberOfCrashesDuringRecovery = _random.intBetween(0, 3);

            for (int i = 0; i < numberOfCrashesDuringRecovery; i++)
            {
                using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
                {
                    int numberOfActionsToRecoverBeforeCrashing = _random.intBetween(1, recoveryActions.Count);
                    Recover(recoveryActions.subList(0, numberOfActionsToRecoverBeforeCrashing), index);
                    // ... crash
                }
            }

            // to finally apply all actions after last checkpoint and verify tree
            using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
            {
                Recover(recoveryActions, index);

                // THEN
                // we should end up with a consistent index containing all the stuff load says
                index.ConsistencyCheck();
                long[] aggregate = ExpectedSortedAggregatedDataFromGeneratedLoad(load);
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(long.MinValue), Key(long.MaxValue)))
                {
                    for (int i = 0; i < aggregate.Length;)
                    {
                        assertTrue(cursor.Next());
                        Hit <KEY, VALUE> hit = cursor.get();
                        AssertEqualsKey(Key(aggregate[i++]), hit.Key());
                        AssertEqualsValue(Value(aggregate[i++]), hit.Value());
                    }
                    assertFalse(cursor.Next());
                }
            }
        }