use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class LuceneSchemaIndexUniquenessVerificationIT method verifyUniqueness.
private void verifyUniqueness(Collection<PropertyValue> data) throws IOException, IndexEntryConflictException {
Object[] propertyValues = data.stream().map(property -> property.value).toArray();
PropertyAccessor propertyAccessor = new TestPropertyAccessor(propertyValues);
index.verifyUniqueness(propertyAccessor, new int[] { PROPERTY_KEY_ID });
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class SimpleUniquenessVerifier method verify.
@Override
public void verify(PropertyAccessor accessor, int[] propKeyIds) throws IndexEntryConflictException, IOException {
try {
DuplicateCheckingCollector collector = DuplicateCheckingCollector.forProperties(accessor, propKeyIds);
IndexSearcher searcher = indexSearcher();
for (LeafReaderContext leafReaderContext : searcher.getIndexReader().leaves()) {
Fields fields = leafReaderContext.reader().fields();
for (String field : fields) {
if (LuceneDocumentStructure.NODE_ID_KEY.equals(field)) {
continue;
}
TermsEnum terms = LuceneDocumentStructure.originalTerms(fields.terms(field), field);
BytesRef termsRef;
while ((termsRef = terms.next()) != null) {
if (terms.docFreq() > 1) {
collector.reset();
searcher.search(new TermQuery(new Term(field, termsRef)), collector);
}
}
}
}
} catch (IOException e) {
Throwable cause = e.getCause();
if (cause instanceof IndexEntryConflictException) {
throw (IndexEntryConflictException) cause;
}
throw e;
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.
private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
try {
NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline(state, index);
int labelId = index.schema().getLabelId();
state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
if (existing != NO_SUCH_NODE && existing != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class BatchInserterImpl method shutdown.
@Override
public void shutdown() {
if (isShutdown) {
throw new IllegalStateException("Batch inserter already has shutdown");
}
isShutdown = true;
flushStrategy.forceFlush();
rebuildCounts();
try {
repopulateAllIndexes();
} catch (IOException | IndexEntryConflictException e) {
throw new RuntimeException(e);
} finally {
cursors.close();
neoStores.close();
try {
storeLocker.close();
} catch (IOException e) {
throw new UnderlyingStorageException("Could not release store lock", e);
}
msgLog.info(Thread.currentThread() + " Clean shutdown on BatchInserter(" + this + ")", true);
life.shutdown();
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class Operations method validateNoExistingNodeWithExactValues.
/**
* Check so that there is not an existing node with the exact match of label and property
*/
private void validateNoExistingNodeWithExactValues(IndexBackedConstraintDescriptor constraint, PropertyIndexQuery.ExactPredicate[] propertyValues, long modifiedNode) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
try (FullAccessNodeValueIndexCursor valueCursor = cursors.allocateFullAccessNodeValueIndexCursor(ktx.cursorContext(), memoryTracker);
IndexReaders indexReaders = new IndexReaders(index, allStoreHolder)) {
assertIndexOnline(index);
SchemaDescriptor schema = index.schema();
long[] labelIds = schema.lockingKeys();
if (labelIds.length != 1) {
throw new UnableToValidateConstraintException(constraint, new AssertionError(format("Constraint indexes are not expected to be multi-token indexes, " + "but the constraint %s was referencing an index with the following schema: %s.", constraint.userDescription(token), schema.userDescription(token))), token);
}
// Take a big fat lock, and check for existing node in index
ktx.lockClient().acquireExclusive(ktx.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelIds[0], propertyValues));
allStoreHolder.nodeIndexSeekWithFreshIndexReader(valueCursor, indexReaders.createReader(), propertyValues);
if (valueCursor.next() && valueCursor.nodeReference() != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(valueCursor.nodeReference(), NO_SUCH_NODE, PropertyIndexQuery.asValueTuple(propertyValues)), token);
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e, token);
}
}
Aggregations