Search in sources :

Example 1 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.

private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
    PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
    long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
    db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
    db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
    ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
    final AtomicBoolean success = new AtomicBoolean(false);
    try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
        List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
        boolean startFound = false;
        while (cursor.next()) {
            LogEntry entry = cursor.get();
            if (entry instanceof LogEntryStart) {
                if (startFound) {
                    throw new IllegalArgumentException("More than one start entry");
                }
                startFound = true;
            }
            if (startFound && entry instanceof LogEntryCommand) {
                commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
            }
            if (entry instanceof LogEntryCommit) {
                // The first COMMIT
                assertTrue(startFound);
                assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
                List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
                assertEquals(1, createCommands.size());
                success.set(true);
                break;
            }
        }
    }
    assertTrue("Didn't find any commit record in log " + version, success.get());
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Iterators(org.neo4j.helpers.collection.Iterators) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOCursor(org.neo4j.cursor.IOCursor) Node(org.neo4j.graphdb.Node) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ArrayList(java.util.ArrayList) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) After(org.junit.After) Transaction(org.neo4j.graphdb.Transaction) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Assert.assertFalse(org.junit.Assert.assertFalse) FilteringIterator(org.neo4j.helpers.collection.FilteringIterator) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Assert.assertEquals(org.junit.Assert.assertEquals) Index(org.neo4j.graphdb.index.Index) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 2 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class PhysicalLogCommandReaderV3_0 method visitIndexDefineCommand.

private Command visitIndexDefineCommand(ReadableChannel channel) throws IOException {
    readIndexCommandHeader(channel);
    Map<String, Integer> indexNames = readMap(channel);
    Map<String, Integer> keys = readMap(channel);
    IndexDefineCommand command = new IndexDefineCommand();
    command.init(indexNames, keys);
    return command;
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IoPrimitiveUtils.read3bLengthAndString(org.neo4j.kernel.impl.util.IoPrimitiveUtils.read3bLengthAndString) IoPrimitiveUtils.read2bLengthAndString(org.neo4j.kernel.impl.util.IoPrimitiveUtils.read2bLengthAndString)

Example 3 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_2_4 method visitIndexDefineCommand.

private Command visitIndexDefineCommand(ReadableChannel channel) throws IOException {
    readIndexCommandHeader(channel);
    Map<String, Integer> indexNames = readMap(channel);
    Map<String, Integer> keys = readMap(channel);
    IndexDefineCommand command = new IndexDefineCommand();
    command.init(indexNames, keys);
    return command;
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IoPrimitiveUtils.read3bLengthAndString(org.neo4j.kernel.impl.util.IoPrimitiveUtils.read3bLengthAndString) IoPrimitiveUtils.read2bLengthAndString(org.neo4j.kernel.impl.util.IoPrimitiveUtils.read2bLengthAndString)

Example 4 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LegacyBatchIndexApplierTest method shouldOnlyCreateOneApplierPerProvider.

@Test
public void shouldOnlyCreateOneApplierPerProvider() throws Exception {
    // GIVEN
    Map<String, Integer> names = MapUtil.genericMap("first", 0, "second", 1);
    Map<String, Integer> keys = MapUtil.genericMap("key", 0);
    String applierName = "test-applier";
    Commitment commitment = mock(Commitment.class);
    when(commitment.hasLegacyIndexChanges()).thenReturn(true);
    IndexConfigStore config = newIndexConfigStore(names, applierName);
    LegacyIndexApplierLookup applierLookup = mock(LegacyIndexApplierLookup.class);
    when(applierLookup.newApplier(anyString(), anyBoolean())).thenReturn(mock(TransactionApplier.class));
    try (LegacyBatchIndexApplier applier = new LegacyBatchIndexApplier(config, applierLookup, BYPASS, INTERNAL)) {
        TransactionToApply tx = new TransactionToApply(null, 2);
        tx.commitment(commitment, 2);
        try (TransactionApplier txApplier = applier.startTx(tx)) {
            // WHEN
            IndexDefineCommand definitions = definitions(names, keys);
            txApplier.visitIndexDefineCommand(definitions);
            txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "first"));
            txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "second"));
            txApplier.visitIndexAddRelationshipCommand(addRelationshipToIndex(definitions, "second"));
        }
    }
    // THEN
    verify(applierLookup, times(1)).newApplier(eq(applierName), anyBoolean());
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString) Commitment(org.neo4j.kernel.impl.transaction.log.Commitment) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) Test(org.junit.Test)

Example 5 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class TransactionApplierFacadeTest method testVisitIndexDefineCommand.

@Test
public void testVisitIndexDefineCommand() throws Exception {
    IndexDefineCommand cmd = mock(IndexDefineCommand.class);
    when(cmd.handle(any(CommandVisitor.class))).thenCallRealMethod();
    // WHEN
    boolean result = facade.visitIndexDefineCommand(cmd);
    // THEN
    InOrder inOrder = inOrder(txApplier1, txApplier2, txApplier3);
    inOrder.verify(txApplier1).visitIndexDefineCommand(cmd);
    inOrder.verify(txApplier2).visitIndexDefineCommand(cmd);
    inOrder.verify(txApplier3).visitIndexDefineCommand(cmd);
    inOrder.verifyNoMoreInteractions();
    assertFalse(result);
}
Also used : InOrder(org.mockito.InOrder) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) Test(org.junit.Test)

Aggregations

IndexDefineCommand (org.neo4j.kernel.impl.index.IndexDefineCommand)18 Test (org.junit.Test)11 StorageCommand (org.neo4j.storageengine.api.StorageCommand)7 HashSet (java.util.HashSet)6 IndexCommand (org.neo4j.kernel.impl.index.IndexCommand)6 Command (org.neo4j.kernel.impl.transaction.command.Command)6 IoPrimitiveUtils.read2bLengthAndString (org.neo4j.kernel.impl.util.IoPrimitiveUtils.read2bLengthAndString)5 IoPrimitiveUtils.read3bLengthAndString (org.neo4j.kernel.impl.util.IoPrimitiveUtils.read3bLengthAndString)5 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newCachedThreadPool (java.util.concurrent.Executors.newCachedThreadPool)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1