Skip to content

Instantly share code, notes, and snippets.

@luanne
Last active August 29, 2015 14:14
Show Gist options
  • Save luanne/79da044a6a97f10748dd to your computer and use it in GitHub Desktop.
Save luanne/79da044a6a97f10748dd to your computer and use it in GitHub Desktop.
When a node is created with multiple labels and the order of labels supplied is such that a new label is first, and an existing label is next, where the existing label has a unique constraint defined on it, the constraint checker produces "This node was not found in the expected index"
package com.graphaware;
import org.neo4j.graphdb.DynamicLabel;
import org.neo4j.graphdb.schema.ConstraintCreator;
import org.neo4j.unsafe.batchinsert.BatchInserter;
import org.neo4j.unsafe.batchinsert.BatchInserters;
import java.util.Collections;
import java.util.Date;
import static org.neo4j.helpers.collection.MapUtil.map;
/**
* Created by luanne on 03/02/15.
*/
public class NodeNotFoundInExpectedIndex {
public static void main(String[] args) {
String path = "/tmp/test" + new Date().getTime() + ".graph.db";
System.out.println("path = " + path);
BatchInserter inserter = BatchInserters.inserter(path, Collections.EMPTY_MAP);
inserter.createNode(map("companyId", 25745l), DynamicLabel.label("Company"));
//Create a node with a label that does not exist yet, followed by the label which exists and has the constrain defined on it
//Creating the node with Company,Unknown produces no error
inserter.createNode(map("companyId", 0l), DynamicLabel.label("Unknown"), DynamicLabel.label("Company"));
ConstraintCreator constraintCreator = inserter.createDeferredConstraint(DynamicLabel.label("Company"));
constraintCreator.assertPropertyIsUnique("companyId").create();
inserter.shutdown();
}
/*
Consistency check produces
2015-02-03 16:01:00.453+0000 INFO [org.neo4j]: ERROR: This node was not found in the expected index.
Node[1,used=true,rel=-1,prop=1,labels=Inline(0x2000000001:[1, 0]),light]
Inconsistent with: IndexRule[id=1, label=0, kind=CONSTRAINT_INDEX_RULE, provider={key=lucene, version=1.0}, properties=0, owner=2] 0
.. 90%
.................... 100%
2015-02-03 16:01:00.471+0000 INFO [org.neo4j]: Inconsistencies found: ConsistencySummaryStatistics{
Number of errors: 1
Number of warnings: 0
Number of inconsistent NODE records: 1
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment