Search in sources :

Example 6 with LabelScanWriter

use of org.neo4j.kernel.api.labelscan.LabelScanWriter in project neo4j by neo4j.

the class LabelScanStoreTest method prepareIndex.

private void prepareIndex() throws IOException {
    start();
    try (LabelScanWriter labelScanWriter = store.newWriter()) {
        labelScanWriter.write(NodeLabelUpdate.labelChanges(1, new long[] {}, new long[] { 1 }));
    }
    store.shutdown();
}
Also used : LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter)

Example 7 with LabelScanWriter

use of org.neo4j.kernel.api.labelscan.LabelScanWriter in project neo4j by neo4j.

the class NativeLabelScanStoreIT method randomModifications.

private void randomModifications(long[] expected, int count) throws IOException {
    BitSet editedNodes = new BitSet();
    try (LabelScanWriter writer = store.newWriter()) {
        for (int i = 0; i < count; i++) {
            int nodeId = random.nextInt(NODE_COUNT);
            if (editedNodes.get(nodeId)) {
                i--;
                continue;
            }
            int changeSize = random.nextInt(3) + 1;
            long labels = expected[nodeId];
            long[] labelsBefore = getLabels(labels);
            for (int j = 0; j < changeSize; j++) {
                labels = flipRandom(labels, LABEL_COUNT, random.random());
            }
            long[] labelsAfter = getLabels(labels);
            editedNodes.set(nodeId);
            NodeLabelUpdate labelChanges = labelChanges(nodeId, labelsBefore, labelsAfter);
            writer.write(labelChanges);
            expected[nodeId] = labels;
        }
    }
}
Also used : BitSet(java.util.BitSet) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter)

Example 8 with LabelScanWriter

use of org.neo4j.kernel.api.labelscan.LabelScanWriter in project neo4j by neo4j.

the class IndexBatchTransactionApplierTest method shouldProvideLabelScanStoreUpdatesSortedByNodeId.

@Test
public void shouldProvideLabelScanStoreUpdatesSortedByNodeId() throws Exception {
    // GIVEN
    IndexingService indexing = mock(IndexingService.class);
    LabelScanWriter writer = new OrderVerifyingLabelScanWriter(10, 15, 20);
    WorkSync<Supplier<LabelScanWriter>, LabelUpdateWork> labelScanSync = spy(new WorkSync<>(singletonProvider(writer)));
    WorkSync<IndexingService, IndexUpdatesWork> indexUpdatesSync = new WorkSync<>(indexing);
    TransactionToApply tx = mock(TransactionToApply.class);
    PropertyStore propertyStore = mock(PropertyStore.class);
    try (IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier(indexing, labelScanSync, indexUpdatesSync, mock(NodeStore.class), mock(PropertyLoader.class), new PropertyPhysicalToLogicalConverter(propertyStore), TransactionApplicationMode.INTERNAL)) {
        try (TransactionApplier txApplier = applier.startTx(tx)) {
            // WHEN
            txApplier.visitNodeCommand(node(15));
            txApplier.visitNodeCommand(node(20));
            txApplier.visitNodeCommand(node(10));
        }
    }
    // THEN all assertions happen inside the LabelScanWriter#write and #close
    verify(labelScanSync).apply(any());
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) WorkSync(org.neo4j.concurrent.WorkSync) PropertyPhysicalToLogicalConverter(org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) PropertyLoader(org.neo4j.kernel.impl.transaction.state.PropertyLoader) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Supplier(java.util.function.Supplier) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 9 with LabelScanWriter

use of org.neo4j.kernel.api.labelscan.LabelScanWriter in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldRemoveLabelFieldsThatDoesNotRepresentAnyNodes.

@Test
public void shouldRemoveLabelFieldsThatDoesNotRepresentAnyNodes() throws Exception {
    // given
    IndexWriter indexWriter = mock(IndexWriter.class);
    Document doc = document(format.rangeField(0), format.labelField(7, 0x1), format.labelField(8, 0x1));
    WritableIndexPartition partition = newIndexPartitionMock(indexWriter, doc);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(7, 8), labels(8)));
    writer.close();
    // then
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(8, 0x01), format.labelSearchField(8))));
}
Also used : WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 10 with LabelScanWriter

use of org.neo4j.kernel.api.labelscan.LabelScanWriter in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldStoreAnyNodeIdInRange.

@Test
public void shouldStoreAnyNodeIdInRange() throws Exception {
    for (int i = 0, max = 1 << format.bitmapFormat().shift; i < max; i++) {
        // given
        IndexWriter indexWriter = mock(IndexWriter.class);
        WritableIndexPartition partition = newIndexPartitionMock(indexWriter);
        WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
        LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
        // when
        writer.write(labelChanges(i, labels(), labels(7)));
        writer.close();
        // then
        Document document = new Document();
        format.addRangeValuesField(document, 0);
        format.addLabelAndSearchFields(document, 7, new Bitmap(1L << i));
        verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document));
    }
}
Also used : Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Aggregations

LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)10 Test (org.junit.Test)7 IndexWriter (org.apache.lucene.index.IndexWriter)6 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)6 WritableDatabaseLabelScanIndex (org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex)6 PartitionedLuceneLabelScanWriter (org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter)6 Document (org.apache.lucene.document.Document)5 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)2 BitSet (java.util.BitSet)1 Supplier (java.util.function.Supplier)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermQuery (org.apache.lucene.search.TermQuery)1 WorkSync (org.neo4j.concurrent.WorkSync)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)1 TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)1 PropertyPhysicalToLogicalConverter (org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter)1 NodeStore (org.neo4j.kernel.impl.store.NodeStore)1