示例#1
0
        public override ICollection <DynamicRecord> Remove(long labelId, NodeStore nodeStore)
        {
            nodeStore.EnsureHeavy(_node, firstDynamicLabelRecordId(_node.LabelField));
            long[] existingLabelIds = GetDynamicLabelsArray(_node.UsedDynamicLabelRecords, nodeStore.DynamicLabelStore);
            long[] newLabelIds      = filter(existingLabelIds, labelId);
            ICollection <DynamicRecord> existingRecords = _node.DynamicLabelRecords;

            if (InlineNodeLabels.TryInlineInNodeRecord(_node, newLabelIds, existingRecords))
            {
                NotInUse = existingRecords;
            }
            else
            {
                ICollection <DynamicRecord> newRecords = AllocateRecordsForDynamicLabels(_node.Id, newLabelIds, new ReusableRecordsCompositeAllocator(existingRecords, nodeStore.DynamicLabelStore));
                _node.setLabelField(DynamicPointer(newRecords), existingRecords);
                if (!newRecords.Equals(existingRecords))
                {                         // One less dynamic record, mark that one as not in use
                    foreach (DynamicRecord record in existingRecords)
                    {
                        if (!newRecords.Contains(record))
                        {
                            record.InUse = false;
                        }
                    }
                }
            }
            return(existingRecords);
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCombineProperFiveByteLabelField() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCombineProperFiveByteLabelField()
        {
            // GIVEN
            // -- a store
            EphemeralFileSystemAbstraction fs = _efs.get();

            _nodeStore = NewNodeStore(fs);

            // -- a record with the msb carrying a negative value
            long       nodeId = 0;
            long       labels = 0x8000000001L;
            NodeRecord record = new NodeRecord(nodeId, false, NO_NEXT_RELATIONSHIP.intValue(), NO_NEXT_PROPERTY.intValue());

            record.InUse = true;
            record.SetLabelField(labels, Collections.emptyList());
            _nodeStore.updateRecord(record);

            // WHEN
            // -- reading that record back
            NodeRecord readRecord = _nodeStore.getRecord(nodeId, _nodeStore.newRecord(), NORMAL);

            // THEN
            // -- the label field must be the same
            assertEquals(labels, readRecord.LabelField);
        }
示例#3
0
        public override ICollection <DynamicRecord> Remove(long labelId, NodeStore nodeStore)
        {
            long[] newLabelIds = filter(ParseInlined(_node.LabelField), labelId);
            bool   inlined     = TryInlineInNodeRecord(_node, newLabelIds, _node.DynamicLabelRecords);

            Debug.Assert(inlined);
            return(Collections.emptyList());
        }
示例#4
0
 public static long[] Get(NodeRecord node, NodeStore nodeStore)
 {
     if (node.Light)
     {
         nodeStore.EnsureHeavy(node, firstDynamicLabelRecordId(node.LabelField));
     }
     return(GetDynamicLabelsArray(node.UsedDynamicLabelRecords, nodeStore.DynamicLabelStore));
 }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private NodeStore newNodeStore(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException
        private NodeStore NewNodeStore(FileSystemAbstraction fs, PageCache pageCache)
        {
            _idGeneratorFactory = spy(new DefaultIdGeneratorFactoryAnonymousInnerClass(this, fs));
            StoreFactory factory = new StoreFactory(_testDirectory.databaseLayout("new"), Config.defaults(), _idGeneratorFactory, pageCache, fs, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            _neoStores = factory.OpenAllNeoStores(true);
            _nodeStore = _neoStores.NodeStore;
            return(_nodeStore);
        }
示例#6
0
 public CountsComputer(long lastCommittedTransactionId, NodeStore nodes, RelationshipStore relationships, int highLabelId, int highRelationshipTypeId, NumberArrayFactory numberArrayFactory, ProgressReporter progressMonitor)
 {
     this._lastCommittedTransactionId = lastCommittedTransactionId;
     this._nodes                  = nodes;
     this._relationships          = relationships;
     this._highLabelId            = highLabelId;
     this._highRelationshipTypeId = highRelationshipTypeId;
     this._numberArrayFactory     = numberArrayFactory;
     this._progressMonitor        = progressMonitor;
 }
示例#7
0
        public override ICollection <DynamicRecord> Add(long labelId, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            nodeStore.EnsureHeavy(_node, firstDynamicLabelRecordId(_node.LabelField));
            long[] existingLabelIds = GetDynamicLabelsArray(_node.UsedDynamicLabelRecords, nodeStore.DynamicLabelStore);
            long[] newLabelIds      = LabelIdArray.ConcatAndSort(existingLabelIds, labelId);
            ICollection <DynamicRecord> existingRecords       = _node.DynamicLabelRecords;
            ICollection <DynamicRecord> changedDynamicRecords = AllocateRecordsForDynamicLabels(_node.Id, newLabelIds, new ReusableRecordsCompositeAllocator(existingRecords, allocator));

            _node.setLabelField(DynamicPointer(changedDynamicRecords), changedDynamicRecords);
            return(changedDynamicRecords);
        }
示例#8
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();
        }
示例#9
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();
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void scanningRecordsShouldVisitEachInUseRecordOnce() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ScanningRecordsShouldVisitEachInUseRecordOnce()
        {
            // GIVEN we have a NodeStore with data that spans several pages...
            EphemeralFileSystemAbstraction fs = _efs.get();

            _nodeStore = NewNodeStore(fs);

            ThreadLocalRandom rng = ThreadLocalRandom.current();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet nextRelSet = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet nextRelSet = new LongHashSet();

            for (int i = 0; i < 10_000; i++)
            {
                // Enough records to span several pages
                int nextRelCandidate = rng.Next(0, int.MaxValue);
                if (nextRelSet.add(nextRelCandidate))
                {
                    long       nodeId = _nodeStore.nextId();
                    NodeRecord record = new NodeRecord(nodeId, false, nextRelCandidate, 20, true);
                    _nodeStore.updateRecord(record);
                    if (rng.Next(0, 10) < 3)
                    {
                        nextRelSet.remove(nextRelCandidate);
                        record.InUse = false;
                        _nodeStore.updateRecord(record);
                    }
                }
            }

            // ...WHEN we now have an interesting set of node records, and we
            // visit each and remove that node from our nextRelSet...

            Visitor <NodeRecord, IOException> scanner = record =>
            {
                // ...THEN we should observe that no nextRel is ever removed twice...
                assertTrue(nextRelSet.remove(record.NextRel));
                return(false);
            };

            _nodeStore.scanAllRecords(scanner);

            // ...NOR do we have anything left in the set afterwards.
            assertTrue(nextRelSet.Empty);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGrowAFileWhileContinuingToMemoryMapNewRegions()
        public virtual void ShouldGrowAFileWhileContinuingToMemoryMapNewRegions()
        {
            // don't run on windows because memory mapping doesn't work properly there
            assumeTrue(!SystemUtils.IS_OS_WINDOWS);

            // given
            const int numberOfRecords = 1000000;

            Config config = Config.defaults(pagecache_memory, MmapSize(numberOfRecords, NodeRecordFormat.RECORD_SIZE));
            FileSystemAbstraction     fileSystemAbstraction = _fileSystemRule.get();
            DefaultIdGeneratorFactory idGeneratorFactory    = new DefaultIdGeneratorFactory(fileSystemAbstraction);
            PageCache    pageCache    = _pageCacheRule.getPageCache(fileSystemAbstraction, config);
            StoreFactory storeFactory = new StoreFactory(_testDirectory.databaseLayout(), config, idGeneratorFactory, pageCache, fileSystemAbstraction, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            NeoStores neoStores = storeFactory.OpenAllNeoStores(true);
            NodeStore nodeStore = neoStores.NodeStore;

            // when
            int  iterations = 2 * numberOfRecords;
            long startingId = nodeStore.NextId();
            long nodeId     = startingId;

            for (int i = 0; i < iterations; i++)
            {
                NodeRecord record = new NodeRecord(nodeId, false, i, 0);
                record.InUse = true;
                nodeStore.UpdateRecord(record);
                nodeId = nodeStore.NextId();
            }

            // then
            NodeRecord record = new NodeRecord(0, false, 0, 0);

            for (int i = 0; i < iterations; i++)
            {
                record.Id = startingId + i;
                nodeStore.GetRecord(i, record, NORMAL);
                assertTrue("record[" + i + "] should be in use", record.InUse());
                assertThat("record[" + i + "] should have nextRelId of " + i, record.NextRel, @is(( long )i));
            }

            neoStores.Close();
        }
示例#12
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());
                }
            }
        }
示例#13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTellNodeInUse() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTellNodeInUse()
        {
            // Given
            EphemeralFileSystemAbstraction fs = _efs.get();
            NodeStore store = NewNodeStore(fs);

            long exists = store.NextId();

            store.UpdateRecord(new NodeRecord(exists, false, 10, 20, true));

            long deleted = store.NextId();

            store.UpdateRecord(new NodeRecord(deleted, false, 10, 20, true));
            store.UpdateRecord(new NodeRecord(deleted, false, 10, 20, false));

            // When & then
            assertTrue(store.IsInUse(exists));
            assertFalse(store.IsInUse(deleted));
            assertFalse(store.IsInUse(_nodeStore.recordFormat.MaxId));
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFreeSecondaryUnitIdOfShrunkRecord() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFreeSecondaryUnitIdOfShrunkRecord()
        {
            // GIVEN
            EphemeralFileSystemAbstraction fs = _efs.get();

            _nodeStore = NewNodeStore(fs);
            NodeRecord record = new NodeRecord(5L);

            record.RequiresSecondaryUnit = true;
            record.SecondaryUnitId       = 10L;
            record.InUse = true;
            _nodeStore.updateRecord(record);
            _nodeStore.HighestPossibleIdInUse = 10L;

            // WHEN
            record.RequiresSecondaryUnit = false;
            _nodeStore.updateRecord(record);

            // THEN
            IdGenerator idGenerator = _idGeneratorFactory.get(IdType.NODE);

            verify(idGenerator, never()).freeId(5L);
            verify(idGenerator).freeId(10L);
        }
示例#15
0
 private CountsComputer(long lastCommittedTransactionId, NodeStore nodes, RelationshipStore relationships, int highLabelId, int highRelationshipTypeId, NumberArrayFactory numberArrayFactory) : this(lastCommittedTransactionId, nodes, relationships, highLabelId, highRelationshipTypeId, numberArrayFactory, SilentProgressReporter.INSTANCE)
 {
 }
示例#16
0
        internal static ICollection <DynamicRecord> PutSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            long existingLabelsField = node.LabelField;
            long existingLabelsBits  = parseLabelsBody(existingLabelsField);

            ICollection <DynamicRecord> changedDynamicRecords = node.DynamicLabelRecords;

            long labelField = node.LabelField;

            if (fieldPointsToDynamicRecordOfLabels(labelField))
            {
                // There are existing dynamic label records, get them
                nodeStore.EnsureHeavy(node, existingLabelsBits);
                changedDynamicRecords = node.DynamicLabelRecords;
                NotInUse = changedDynamicRecords;
            }

            if (!InlineNodeLabels.TryInlineInNodeRecord(node, labelIds, changedDynamicRecords))
            {
                IEnumerator <DynamicRecord> recycledRecords  = changedDynamicRecords.GetEnumerator();
                ICollection <DynamicRecord> allocatedRecords = AllocateRecordsForDynamicLabels(node.Id, labelIds, new ReusableRecordsCompositeAllocator(recycledRecords, allocator));
                // Set the rest of the previously set dynamic records as !inUse
                while (recycledRecords.MoveNext())
                {
                    DynamicRecord removedRecord = recycledRecords.Current;
                    removedRecord.InUse = false;
                    allocatedRecords.Add(removedRecord);
                }
                node.SetLabelField(DynamicPointer(allocatedRecords), allocatedRecords);
                changedDynamicRecords = allocatedRecords;
            }

            return(changedDynamicRecords);
        }
示例#17
0
 public static long[] Get(NodeRecord node, NodeStore nodeStore)
 {
     return(FieldPointsToDynamicRecordOfLabels(node.LabelField) ? DynamicNodeLabels.Get(node, nodeStore) : InlineNodeLabels.Get(node));
 }
示例#18
0
        public NodeFirstGroupStage(Configuration config, RecordStore <RelationshipGroupRecord> groupStore, NodeStore nodeStore, ByteArray cache) : base(NAME, null, config, 0)
        {
            Add(new BatchFeedStep(Control(), config, allIn(groupStore, config), groupStore.RecordSize));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: add(new org.neo4j.unsafe.impl.batchimport.staging.ReadRecordsStep<>(control(), config, true, groupStore));
            Add(new ReadRecordsStep <object>(Control(), config, true, groupStore));
            Add(new NodeSetFirstGroupStep(Control(), config, nodeStore, cache));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: add(new UpdateRecordsStep<>(control(), config, nodeStore, new org.neo4j.unsafe.impl.batchimport.store.StorePrepareIdSequence()));
            Add(new UpdateRecordsStep <object>(Control(), config, nodeStore, new StorePrepareIdSequence()));
        }
示例#19
0
        public override ICollection <DynamicRecord> Add(long labelId, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            long[] augmentedLabelIds = LabelCount(_node.LabelField) == 0 ? new long[] { labelId } : concatAndSort(ParseInlined(_node.LabelField), labelId);

            return(PutSorted(_node, augmentedLabelIds, nodeStore, allocator));
        }
示例#20
0
        public static ICollection <DynamicRecord> PutSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            if (TryInlineInNodeRecord(node, labelIds, node.DynamicLabelRecords))
            {
                return(Collections.emptyList());
            }

            return(DynamicNodeLabels.PutSorted(node, labelIds, nodeStore, allocator));
        }
示例#21
0
 public override ICollection <DynamicRecord> Put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
 {
     Arrays.sort(labelIds);
     return(PutSorted(_node, labelIds, nodeStore, allocator));
 }
示例#22
0
 public override long[] Get(NodeStore nodeStore)
 {
     return(Get(_node));
 }
示例#23
0
 public StoreScanAsInputIteratorAnonymousInnerClass2(Org.Neo4j.Kernel.impl.store.NodeStore getNodeStore, NeoStores legacyStore, bool requiresPropertyMigration) : base(getNodeStore)
 {
     this._legacyStore = legacyStore;
     this._requiresPropertyMigration = requiresPropertyMigration;
 }