Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadACommandLogEntry() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadACommandLogEntry()
        {
            // given
            LogEntryVersion version = LogEntryVersion.CURRENT;

            Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(11), new NodeRecord(11));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
            LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel();
            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            channel.Put(version.byteCode());
            channel.Put(LogEntryByteCodes.Command);
            nodeCommand.Serialize(channel);

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogEntry logEntry = logEntryReader.readLogEntry(channel);
            LogEntry logEntry = _logEntryReader.readLogEntry(channel);

            // then
            assertEquals(command, logEntry);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContainFedNodeUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldContainFedNodeUpdate()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            int        nodeId        = 0;
            NodeRecord inUse         = GetNode(nodeId, true);
            Value      propertyValue = Values.of("hej");
            long       propertyId    = CreateNodeProperty(inUse, propertyValue, 1);
            NodeRecord notInUse      = GetNode(nodeId, false);

            _nodeStore.updateRecord(inUse);

            Command.NodeCommand nodeCommand    = new Command.NodeCommand(inUse, notInUse);
            PropertyRecord      propertyBlocks = new PropertyRecord(propertyId);

            propertyBlocks.NodeId = nodeId;
            Command.PropertyCommand propertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);

            StoreIndexDescriptor indexDescriptor = forSchema(multiToken(_entityTokens, NODE, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);

            _indexingService.createIndexes(indexDescriptor);
            _indexingService.getIndexProxy(indexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(nodeCommand, propertyCommand), RelationshipGroup(null));
            assertTrue(onlineIndexUpdates.HasUpdates());
            IEnumerator <IndexEntryUpdate <SchemaDescriptor> > iterator = onlineIndexUpdates.GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(iterator.next(), IndexEntryUpdate.remove(nodeId, indexDescriptor, propertyValue, null, null));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(iterator.hasNext());
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertSerializationWorksFor(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand cmd) throws java.io.IOException
        private void AssertSerializationWorksFor(Command.NodeCommand cmd)
        {
            _channel.reset();
            cmd.Serialize(_channel);
            Command.NodeCommand result = (Command.NodeCommand)_commandReader.read(_channel);
            // Then
            assertThat(result, equalTo(cmd));
            assertThat(result.Mode, equalTo(cmd.Mode));
            assertThat(result.Before, equalTo(cmd.Before));
            assertThat(result.After, equalTo(cmd.After));
            // And created and dense flags should be the same
            assertThat(result.Before.Created, equalTo(cmd.Before.Created));
            assertThat(result.After.Created, equalTo(cmd.After.Created));
            assertThat(result.Before.Dense, equalTo(cmd.Before.Dense));
            assertThat(result.After.Dense, equalTo(cmd.After.Dense));
            // And labels should be the same
            assertThat(Labels(result.Before), equalTo(Labels(cmd.Before)));
            assertThat(Labels(result.After), equalTo(Labels(cmd.After)));
            // And dynamic records should be the same
            assertThat(result.Before.DynamicLabelRecords, equalTo(cmd.Before.DynamicLabelRecords));
            assertThat(result.After.DynamicLabelRecords, equalTo(cmd.After.DynamicLabelRecords));
            // And the secondary unit information should be the same
            // Before
            assertThat(result.Before.requiresSecondaryUnit(), equalTo(cmd.Before.requiresSecondaryUnit()));
            assertThat(result.Before.hasSecondaryUnitId(), equalTo(cmd.Before.hasSecondaryUnitId()));
            assertThat(result.Before.SecondaryUnitId, equalTo(cmd.Before.SecondaryUnitId));
            // and after
            assertThat(result.After.requiresSecondaryUnit(), equalTo(cmd.After.requiresSecondaryUnit()));
            assertThat(result.After.hasSecondaryUnitId(), equalTo(cmd.After.hasSecondaryUnitId()));
            assertThat(result.After.SecondaryUnitId, equalTo(cmd.After.SecondaryUnitId));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeDynamicRecordsRemoved() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeDynamicRecordsRemoved()
        {
            _channel.reset();
            // Given
            NodeRecord before = new NodeRecord(12, false, 1, 2);

            before.InUse = true;
            IList <DynamicRecord> beforeDyn = singletonList(dynamicRecord(0, true, true, -1L, LONG.intValue(), new sbyte[] { 1, 2, 3, 4, 5, 6, 7, 8 }));

            before.SetLabelField(dynamicPointer(beforeDyn), beforeDyn);
            NodeRecord after = new NodeRecord(12, false, 2, 1);

            after.InUse = true;
            IList <DynamicRecord> dynamicRecords = singletonList(dynamicRecord(0, false, true, -1L, LONG.intValue(), new sbyte[] { 1, 2, 3, 4, 5, 6, 7, 8 }));

            after.SetLabelField(dynamicPointer(dynamicRecords), dynamicRecords);
            // When
            Command.NodeCommand cmd = new Command.NodeCommand(before, after);
            cmd.Serialize(_channel);
            Command.NodeCommand result = (Command.NodeCommand)_commandReader.read(_channel);
            // Then
            assertThat(result, equalTo(cmd));
            assertThat(result.Mode, equalTo(cmd.Mode));
            assertThat(result.Before, equalTo(cmd.Before));
            assertThat(result.After, equalTo(cmd.After));
            // And dynamic records should be the same
            assertThat(result.Before.DynamicLabelRecords, equalTo(cmd.Before.DynamicLabelRecords));
            assertThat(result.After.DynamicLabelRecords, equalTo(cmd.After.DynamicLabelRecords));
        }
Exemplo n.º 5
0
            public override bool VisitNodeCommand(Command.NodeCommand command)
            {
                if (!NodeVisited)
                {
                    Updated = false;
                    Deleted = false;
                }
                NodeVisited = true;

                switch (command.Mode)
                {
                case CREATE:
                    assertFalse(Updated);
                    assertFalse(Deleted);
                    break;

                case UPDATE:
                    Updated = true;
                    assertFalse(Deleted);
                    break;

                case DELETE:
                    Deleted = true;
                    break;

                default:
                    throw new System.InvalidOperationException("Unknown command mode: " + command.Mode);
                }
                return(false);
            }
        protected internal virtual TransactionToApply Tx()
        {
            NodeRecord before = new NodeRecord(0);
            NodeRecord after  = new NodeRecord(0);

            after.InUse = true;
            Command.NodeCommand nodeCommand      = new Command.NodeCommand(before, after);
            PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(singletonList(nodeCommand));

            tx.SetHeader(new sbyte[0], 0, 0, 0, 0, 0, 0);
            return(new TransactionToApply(tx));
        }
Exemplo n.º 7
0
        private void GatherUpdatesFor(long nodeId, Command.NodeCommand nodeCommand, EntityCommandGrouper <Command.NodeCommand> .Cursor propertyCommands)
        {
            EntityUpdates.Builder nodePropertyUpdate = GatherUpdatesFromCommandsForNode(nodeId, nodeCommand, propertyCommands);

            EntityUpdates entityUpdates = nodePropertyUpdate.Build();

            // we need to materialize the IndexEntryUpdates here, because when we
            // consume (later in separate thread) the store might have changed.
            foreach (IndexEntryUpdate <SchemaDescriptor> update in _updateService.convertToIndexUpdates(entityUpdates, EntityType.NODE))
            {
                _updates.Add(update);
            }
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDifferentiateNodesAndRelationships() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDifferentiateNodesAndRelationships()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            int        nodeId            = 0;
            NodeRecord inUseNode         = GetNode(nodeId, true);
            Value      nodePropertyValue = Values.of("hej");
            long       nodePropertyId    = CreateNodeProperty(inUseNode, nodePropertyValue, 1);
            NodeRecord notInUseNode      = GetNode(nodeId, false);

            _nodeStore.updateRecord(inUseNode);

            Command.NodeCommand nodeCommand        = new Command.NodeCommand(inUseNode, notInUseNode);
            PropertyRecord      nodePropertyBlocks = new PropertyRecord(nodePropertyId);

            nodePropertyBlocks.NodeId = nodeId;
            Command.PropertyCommand nodePropertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(nodePropertyId).forReadingData(), nodePropertyBlocks);

            StoreIndexDescriptor nodeIndexDescriptor = forSchema(multiToken(_entityTokens, NODE, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);

            _indexingService.createIndexes(nodeIndexDescriptor);
            _indexingService.getIndexProxy(nodeIndexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            long relId = 0;
            RelationshipRecord inUse        = GetRelationship(relId, true, ENTITY_TOKEN);
            Value relationshipPropertyValue = Values.of("da");
            long  propertyId            = CreateRelationshipProperty(inUse, relationshipPropertyValue, 1);
            RelationshipRecord notInUse = GetRelationship(relId, false, ENTITY_TOKEN);

            _relationshipStore.updateRecord(inUse);

            Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
            PropertyRecord relationshipPropertyBlocks       = new PropertyRecord(propertyId);

            relationshipPropertyBlocks.RelId = relId;
            Command.PropertyCommand relationshipPropertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), relationshipPropertyBlocks);

            StoreIndexDescriptor relationshipIndexDescriptor = forSchema(multiToken(_entityTokens, RELATIONSHIP, 1, 4, 6), EMPTY.ProviderDescriptor).withId(1);

            _indexingService.createIndexes(relationshipIndexDescriptor);
            _indexingService.getIndexProxy(relationshipIndexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(nodeCommand, nodePropertyCommand), RelationshipGroup(relationshipCommand, relationshipPropertyCommand));
            assertTrue(onlineIndexUpdates.HasUpdates());
            assertThat(onlineIndexUpdates, containsInAnyOrder(IndexEntryUpdate.remove(relId, relationshipIndexDescriptor, relationshipPropertyValue, null, null), IndexEntryUpdate.remove(nodeId, nodeIndexDescriptor, nodePropertyValue, null, null)));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeSecondaryUnitUsage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeSecondaryUnitUsage()
        {
            // Given
            // a record that is changed to include a secondary unit
            NodeRecord before = new NodeRecord(13, false, 1, 2);

            before.InUse = true;
            before.RequiresSecondaryUnit = false;
            before.SecondaryUnitId       = NO_ID;         // this and the previous line set the defaults, they are here for clarity
            NodeRecord after = new NodeRecord(13, false, 1, 2);

            after.InUse = true;
            after.RequiresSecondaryUnit = true;
            after.SecondaryUnitId       = 14L;

            Command.NodeCommand command = new Command.NodeCommand(before, after);

            // Then
            AssertSerializationWorksFor(command);
        }
Exemplo n.º 10
0
        private EntityUpdates.Builder GatherUpdatesFromCommandsForNode(long nodeId, Command.NodeCommand nodeChanges, EntityCommandGrouper <Command.NodeCommand> .Cursor propertyCommandsForNode)
        {
            long[] nodeLabelsBefore;
            long[] nodeLabelsAfter;
            if (nodeChanges != null)
            {
                nodeLabelsBefore = parseLabelsField(nodeChanges.Before).get(_nodeStore);
                nodeLabelsAfter  = parseLabelsField(nodeChanges.After).get(_nodeStore);
            }
            else
            {
                /* If the node doesn't exist here then we've most likely encountered this scenario:
                 * - TX1: Node N exists and has property record P
                 * - rotate log
                 * - TX2: P gets changed
                 * - TX3: N gets deleted (also P, but that's irrelevant for this scenario)
                 * - N is persisted to disk for some reason
                 * - crash
                 * - recover
                 * - TX2: P has changed and updates to indexes are gathered. As part of that it tries to read
                 *        the labels of N (which does not exist a.t.m.).
                 *
                 * We can actually (if we disregard any potential inconsistencies) just assume that
                 * if this happens and we're in recovery mode that the node in question will be deleted
                 * in an upcoming transaction, so just skip this update.
                 */
                NodeRecord nodeRecord = LoadNode(nodeId);
                nodeLabelsBefore = nodeLabelsAfter = parseLabelsField(nodeRecord).get(_nodeStore);
            }

            // First get possible Label changes
            bool complete = ProvidesCompleteListOfProperties(nodeChanges);

            EntityUpdates.Builder nodePropertyUpdates = EntityUpdates.forEntity(nodeId, complete).withTokens(nodeLabelsBefore).withTokensAfter(nodeLabelsAfter);

            // Then look for property changes
            _converter.convertPropertyRecord(propertyCommandsForNode, nodePropertyUpdates);
            return(nodePropertyUpdates);
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void extractCommands(java.util.Collection<org.neo4j.storageengine.api.StorageCommand> commands) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        public override void ExtractCommands(ICollection <StorageCommand> commands)
        {
            Debug.Assert(!_prepared, "Transaction has already been prepared");

            _integrityValidator.validateTransactionStartKnowledge(_lastCommittedTxWhenTransactionStarted);

            int noOfCommands = _recordChangeSet.changeSize() + (_neoStoreRecord != null ? _neoStoreRecord.changeSize() : 0);

            foreach (RecordAccess_RecordProxy <LabelTokenRecord, Void> record in _recordChangeSet.LabelTokenChanges.changes())
            {
                commands.Add(new Command.LabelTokenCommand(record.Before, record.ForReadingLinkage()));
            }
            foreach (RecordAccess_RecordProxy <RelationshipTypeTokenRecord, Void> record in _recordChangeSet.RelationshipTypeTokenChanges.changes())
            {
                commands.Add(new Command.RelationshipTypeTokenCommand(record.Before, record.ForReadingLinkage()));
            }
            foreach (RecordAccess_RecordProxy <PropertyKeyTokenRecord, Void> record in _recordChangeSet.PropertyKeyTokenChanges.changes())
            {
                commands.Add(new Command.PropertyKeyTokenCommand(record.Before, record.ForReadingLinkage()));
            }

            // Collect nodes, relationships, properties
            Command[] nodeCommands    = _emptyCommands;
            int       skippedCommands = 0;

            if (_recordChangeSet.NodeRecords.changeSize() > 0)
            {
                nodeCommands = new Command[_recordChangeSet.NodeRecords.changeSize()];
                int i = 0;
                foreach (RecordAccess_RecordProxy <NodeRecord, Void> change in _recordChangeSet.NodeRecords.changes())
                {
                    NodeRecord record = Prepared(change, _nodeStore);
                    _integrityValidator.validateNodeRecord(record);
                    nodeCommands[i++] = new Command.NodeCommand(change.Before, record);
                }
                Arrays.sort(nodeCommands, _commandComparator);
            }

            Command[] relCommands = _emptyCommands;
            if (_recordChangeSet.RelRecords.changeSize() > 0)
            {
                relCommands = new Command[_recordChangeSet.RelRecords.changeSize()];
                int i = 0;
                foreach (RecordAccess_RecordProxy <RelationshipRecord, Void> change in _recordChangeSet.RelRecords.changes())
                {
                    relCommands[i++] = new Command.RelationshipCommand(change.Before, Prepared(change, _relationshipStore));
                }
                Arrays.sort(relCommands, _commandComparator);
            }

            Command[] propCommands = _emptyCommands;
            if (_recordChangeSet.PropertyRecords.changeSize() > 0)
            {
                propCommands = new Command[_recordChangeSet.PropertyRecords.changeSize()];
                int i = 0;
                foreach (RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> change in _recordChangeSet.PropertyRecords.changes())
                {
                    propCommands[i++] = new Command.PropertyCommand(change.Before, Prepared(change, _propertyStore));
                }
                Arrays.sort(propCommands, _commandComparator);
            }

            Command[] relGroupCommands = _emptyCommands;
            if (_recordChangeSet.RelGroupRecords.changeSize() > 0)
            {
                relGroupCommands = new Command[_recordChangeSet.RelGroupRecords.changeSize()];
                int i = 0;
                foreach (RecordAccess_RecordProxy <RelationshipGroupRecord, int> change in _recordChangeSet.RelGroupRecords.changes())
                {
                    if (change.Created && !change.ForReadingLinkage().inUse())
                    {
                        /*
                         * This is an edge case that may come up and which we must handle properly. Relationship groups are
                         * not managed by the tx state, since they are created as side effects rather than through
                         * direct calls. However, they differ from say, dynamic records, in that their management can happen
                         * through separate code paths. What we are interested in here is the following scenario.
                         * 0. A node has one less relationship that is required to transition to dense node. The relationships
                         *    it has belong to at least two different types
                         * 1. In the same tx, a relationship is added making the node dense and all the relationships of a type
                         *    are removed from that node. Regardless of the order these operations happen, the creation of the
                         *    relationship (and the transition of the node to dense) will happen first.
                         * 2. A relationship group will be created because of the transition to dense and then deleted because
                         *    all the relationships it would hold are no longer there. This results in a relationship group
                         *    command that appears in the tx as not in use. Depending on the final order of operations, this
                         *    can end up using an id that is higher than the highest id seen so far. This may not be a problem
                         *    for a single instance, but it can result in errors in cases where transactions are applied
                         *    externally, such as backup or HA.
                         *
                         * The way we deal with this issue here is by not issuing a command for that offending record. This is
                         * safe, since the record is not in use and never was, so the high id is not necessary to change and
                         * the store remains consistent.
                         */
                        skippedCommands++;
                        continue;
                    }
                    relGroupCommands[i++] = new Command.RelationshipGroupCommand(change.Before, Prepared(change, _relationshipGroupStore));
                }
                relGroupCommands = i < relGroupCommands.Length ? Arrays.copyOf(relGroupCommands, i) : relGroupCommands;
                Arrays.sort(relGroupCommands, _commandComparator);
            }

            AddFiltered(commands, Command.Mode.CREATE, propCommands, relCommands, relGroupCommands, nodeCommands);
            AddFiltered(commands, Command.Mode.UPDATE, propCommands, relCommands, relGroupCommands, nodeCommands);
            AddFiltered(commands, Command.Mode.DELETE, propCommands, relCommands, relGroupCommands, nodeCommands);

            if (_neoStoreRecord != null)
            {
                foreach (RecordAccess_RecordProxy <NeoStoreRecord, Void> change in _neoStoreRecord.changes())
                {
                    commands.Add(new Command.NeoStoreCommand(change.Before, change.ForReadingData()));
                }
            }
            //noinspection unchecked
            IList <Command>[] schemaChangeByMode = new System.Collections.IList[Command.Mode.values().length];
            for (int i = 0; i < schemaChangeByMode.Length; i++)
            {
                schemaChangeByMode[i] = new List <Command>();
            }
            foreach (RecordAccess_RecordProxy <SchemaRecord, SchemaRule> change in _recordChangeSet.SchemaRuleChanges.changes())
            {
                if (change.ForReadingLinkage().inUse())
                {
                    _integrityValidator.validateSchemaRule(change.AdditionalData);
                }
                Command.SchemaRuleCommand cmd = new Command.SchemaRuleCommand(change.Before, change.ForChangingData(), change.AdditionalData);
                schemaChangeByMode[cmd.Mode.ordinal()].Add(cmd);
            }
            commands.addAll(schemaChangeByMode[Command.Mode.DELETE.ordinal()]);
            commands.addAll(schemaChangeByMode[Command.Mode.CREATE.ordinal()]);
            commands.addAll(schemaChangeByMode[Command.Mode.UPDATE.ordinal()]);
            Debug.Assert(commands.Count == noOfCommands - skippedCommands, format("Expected %d final commands, got %d " + "instead, with %d skipped", noOfCommands, commands.Count, skippedCommands));

            _prepared = true;
        }
Exemplo n.º 12
0
 private EntityCommandGrouper <Command.NodeCommand> .Cursor NodeGroup(Command.NodeCommand nodeCommand, params Command.PropertyCommand[] propertyCommands)
 {
     return(Group(nodeCommand, typeof(Command.NodeCommand), propertyCommands));
 }