Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void verifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        public virtual void VerifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain a number of records ...
            NodeRecord record = new NodeRecord(0);

            record.InUse = true;
            int highestId = 50;

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some have been deleted
            long?[] idsToFree = new long?[] { 2L, 3L, 5L, 7L };
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // 2
            nextIds.Add(store.NextId());                 // 3
            nextIds.Add(store.NextId());                 // 5
            nextIds.Add(store.NextId());                 // 7
            nextIds.Add(store.NextId());                 // 51
            assertThat(nextIds, contains(2L, 3L, 5L, 7L, 50L));
            store.Close();
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        public virtual void RebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain enough records to fill several file pages ...
            int        recordsPerPage = store.RecordsPerPage;
            NodeRecord record         = new NodeRecord(0);

            record.InUse = true;
            int highestId = recordsPerPage * 3;               // 3 pages worth of records

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some records at the end of a page have been deleted
            long?[] idsToFree = new long?[] { recordsPerPage - 2L, recordsPerPage - 1L };               // id's are zero based, hence -2 and -1
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // recordsPerPage - 2
            nextIds.Add(store.NextId());                 // recordsPerPage - 1
            nextIds.Add(store.NextId());                 // recordsPerPage * 3 (we didn't use this id in the create-look above)
            assertThat(nextIds, contains(recordsPerPage - 2L, recordsPerPage - 1L, recordsPerPage * 3L));
            store.Close();
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCompletelyRebuildIdGeneratorsAfterCrash()
        public virtual void ShouldCompletelyRebuildIdGeneratorsAfterCrash()
        {
            // GIVEN
            DatabaseLayout databaseLayout = _directory.databaseLayout();
            StoreFactory   storeFactory   = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(_fileSystemRule.get()), _pageCacheRule.getPageCache(_fileSystemRule.get()), _fileSystemRule.get(), NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);
            long           highId;

            using (NeoStores stores = storeFactory.OpenAllNeoStores(true))
            {
                // a node store with a "high" node
                NodeStore nodeStore = stores.NodeStore;
                nodeStore.HighId = 20;
                nodeStore.UpdateRecord(Node(nodeStore.NextId()));
                highId = nodeStore.HighId;
            }

            // populating its .id file with a bunch of ids
            File nodeIdFile = databaseLayout.IdNodeStore();

            using (IdGeneratorImpl idGenerator = new IdGeneratorImpl(_fileSystemRule.get(), nodeIdFile, 10, 10_000, false, IdType.NODE, () => highId))
            {
                for (long id = 0; id < 15; id++)
                {
                    idGenerator.FreeId(id);
                }

                // WHEN
                using (NeoStores stores = storeFactory.OpenAllNeoStores(true))
                {
                    NodeStore nodeStore = stores.NodeStore;
                    assertFalse(nodeStore.StoreOk);

                    // simulating what recovery does
                    nodeStore.DeleteIdGenerator();
                    // recovery happens here...
                    nodeStore.MakeStoreOk();

                    // THEN
                    assertEquals(highId, nodeStore.NextId());
                }
            }
        }