Search in sources :

Example 36 with LabelTokenRecord

use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.

the class NodeRecordCheckTest method shouldReportDynamicLabelsNotInUse.

@Test
public void shouldReportDynamicLabelsNotInUse() throws Exception {
    // given
    long[] labelIds = createLabels(100);
    LabelTokenRecord labelRecordNotInUse = notInUse(new LabelTokenRecord(labelIds.length));
    add(labelRecordNotInUse);
    NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
    add(node);
    DynamicRecord labelsRecord1 = inUse(array(new DynamicRecord(1)));
    DynamicRecord labelsRecord2 = inUse(array(new DynamicRecord(2)));
    Collection<DynamicRecord> labelRecords = asList(labelsRecord1, labelsRecord2);
    labelIds[12] = labelIds.length;
    DynamicArrayStore.allocateFromNumbers(new ArrayList<>(), labelIds, new ReusableRecordsAllocator(52, labelRecords));
    assertDynamicRecordChain(labelsRecord1, labelsRecord2);
    node.setLabelField(DynamicNodeLabels.dynamicPointer(labelRecords), labelRecords);
    addNodeDynamicLabels(labelsRecord1);
    addNodeDynamicLabels(labelsRecord2);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelNotInUse(labelRecordNotInUse);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 37 with LabelTokenRecord

use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.

the class NodeRecordCheckTest method shouldProperlyReportOutOfOrderLabelsThatAreFarAway.

@Test
public void shouldProperlyReportOutOfOrderLabelsThatAreFarAway() throws Exception {
    // given
    final NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
    // We need to do this override so we can put the labels unsorted, since InlineNodeLabels always sorts on insert
    new InlineNodeLabels(node) {

        @Override
        public Collection<DynamicRecord> put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
            return putSorted(node, labelIds, nodeStore, allocator);
        }
    }.put(new long[] { 1, 18, 13, 14, 15, 16, 12 }, null, null);
    LabelTokenRecord label1 = inUse(new LabelTokenRecord(1));
    LabelTokenRecord label12 = inUse(new LabelTokenRecord(12));
    LabelTokenRecord label13 = inUse(new LabelTokenRecord(13));
    LabelTokenRecord label14 = inUse(new LabelTokenRecord(14));
    LabelTokenRecord label15 = inUse(new LabelTokenRecord(15));
    LabelTokenRecord label16 = inUse(new LabelTokenRecord(16));
    LabelTokenRecord label18 = inUse(new LabelTokenRecord(18));
    add(label1);
    add(label12);
    add(label13);
    add(label14);
    add(label15);
    add(label16);
    add(label18);
    add(node);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelsOutOfOrder(18, 13);
    verify(report).labelsOutOfOrder(16, 12);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) Collection(java.util.Collection) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 38 with LabelTokenRecord

use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.

the class ReplicatedTokenHolderTest method mockedStorageEngine.

@SuppressWarnings("unchecked")
private StorageEngine mockedStorageEngine() throws Exception {
    StorageEngine storageEngine = mock(StorageEngine.class);
    doAnswer(invocation -> {
        Collection<StorageCommand> target = invocation.getArgumentAt(0, Collection.class);
        ReadableTransactionState txState = invocation.getArgumentAt(1, ReadableTransactionState.class);
        txState.accept(new TxStateVisitor.Adapter() {

            @Override
            public void visitCreatedLabelToken(String name, int id) {
                LabelTokenRecord before = new LabelTokenRecord(id);
                LabelTokenRecord after = before.clone();
                after.setInUse(true);
                target.add(new Command.LabelTokenCommand(before, after));
            }
        });
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    StoreReadLayer readLayer = mock(StoreReadLayer.class);
    when(readLayer.newStatement()).thenReturn(mock(StorageStatement.class));
    when(storageEngine.storeReadLayer()).thenReturn(readLayer);
    return storageEngine;
}
Also used : TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) StorageStatement(org.neo4j.storageengine.api.StorageStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.storageengine.api.lock.ResourceLocker) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord)

Example 39 with LabelTokenRecord

use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.

the class CoreReplicatedContentMarshalTest method shouldMarshalTokenRequest.

@Test
public void shouldMarshalTokenRequest() throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ArrayList<StorageCommand> commands = new ArrayList<>();
    LabelTokenRecord before = new LabelTokenRecord(0);
    LabelTokenRecord after = new LabelTokenRecord(0);
    after.setInUse(true);
    after.setCreated();
    after.setNameId(3232);
    commands.add(new Command.LabelTokenCommand(before, after));
    ReplicatedContent message = new ReplicatedTokenRequest(TokenType.LABEL, "theLabel", ReplicatedTokenRequestSerializer.commandBytes(commands));
    assertMarshalingEquality(buffer, message);
}
Also used : ReplicatedTokenRequest(org.neo4j.causalclustering.core.state.machines.token.ReplicatedTokenRequest) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) Test(org.junit.Test)

Example 40 with LabelTokenRecord

use of org.neo4j.kernel.impl.store.record.LabelTokenRecord in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyLabelTokenCommandToTheStoreInRecovery.

@Test
public void shouldApplyLabelTokenCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final LabelTokenRecord before = new LabelTokenRecord(42);
    final LabelTokenRecord after = new LabelTokenRecord(42);
    after.setInUse(true);
    after.setNameId(323);
    final Command.LabelTokenCommand command = new Command.LabelTokenCommand(before, after);
    final Token token = new Token("token", 21);
    when(labelTokenStore.getToken((int) command.getKey())).thenReturn(token);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(labelTokenStore, times(1)).setHighestPossibleIdInUse(after.getId());
    verify(labelTokenStore, times(1)).updateRecord(after);
    verify(cacheAccess, times(1)).addLabelToken(token);
}
Also used : LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) Token(org.neo4j.storageengine.api.Token) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) Test(org.junit.Test)

Aggregations

LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)43 Test (org.junit.Test)26 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)23 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)20 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)14 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)8 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)8 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)8 IOException (java.io.IOException)7 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)7 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)5 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)5 InlineNodeLabels (org.neo4j.kernel.impl.store.InlineNodeLabels)4 StorageCommand (org.neo4j.storageengine.api.StorageCommand)4 NodeStore (org.neo4j.kernel.impl.store.NodeStore)3 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)3 Command (org.neo4j.kernel.impl.transaction.command.Command)3 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)3 Collection (java.util.Collection)2