use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class IndexUpdaterMap method close.
@Override
public void close() throws UnderlyingStorageException {
Set<Pair<IndexDescriptor, UnderlyingStorageException>> exceptions = null;
for (Map.Entry<IndexDescriptor, IndexUpdater> updaterEntry : updaterMap.entrySet()) {
IndexUpdater updater = updaterEntry.getValue();
try {
updater.close();
} catch (UncheckedIOException | IndexEntryConflictException e) {
if (null == exceptions) {
exceptions = new HashSet<>();
}
exceptions.add(Pair.of(updaterEntry.getKey(), new UnderlyingStorageException(e)));
}
}
clear();
if (null != exceptions) {
throw new MultipleUnderlyingStorageExceptions(exceptions);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class ContractCheckingIndexProxyTest method closeWaitForUpdateToFinish.
@Test
void closeWaitForUpdateToFinish() throws InterruptedException {
// GIVEN
CountDownLatch latch = new CountDownLatch(1);
final IndexProxy inner = new IndexProxyAdapter() {
@Override
public IndexUpdater newUpdater(IndexUpdateMode mode, CursorContext cursorContext) {
return super.newUpdater(mode, cursorContext);
}
};
final IndexProxy outer = newContractCheckingIndexProxy(inner);
Thread actionThread = createActionThread(() -> outer.close(NULL));
outer.start();
// WHEN
Thread updaterThread = runInSeparateThread(() -> {
try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process((ValueIndexEntryUpdate<?>) null);
try {
actionThread.start();
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} catch (IndexEntryConflictException e) {
throw new RuntimeException(e);
}
});
ThreadTestUtils.awaitThreadState(actionThread, TEST_TIMEOUT, Thread.State.TIMED_WAITING);
latch.countDown();
updaterThread.join();
actionThread.join();
}
use of org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException in project neo4j by neo4j.
the class SimpleUniquenessVerifier method verify.
@Override
public void verify(NodePropertyAccessor accessor, int[] propKeyIds, List<Value[]> updatedValueTuples) throws IndexEntryConflictException, IOException {
try {
DuplicateCheckingCollector collector = DuplicateCheckingCollector.forProperties(accessor, propKeyIds);
for (Value[] valueTuple : updatedValueTuples) {
collector.init();
Query query = LuceneDocumentStructure.newSeekQuery(valueTuple);
indexSearcher().search(query, 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 SimpleUniquenessVerifier method verify.
@Override
public void verify(NodePropertyAccessor accessor, int[] propKeyIds) throws IndexEntryConflictException, IOException {
try {
DuplicateCheckingCollector collector = DuplicateCheckingCollector.forProperties(accessor, propKeyIds);
IndexSearcher searcher = indexSearcher();
for (LeafReaderContext leafReaderContext : searcher.getIndexReader().leaves()) {
LeafReader leafReader = leafReaderContext.reader();
for (FieldInfo fieldInfo : leafReader.getFieldInfos()) {
String field = fieldInfo.name;
if (LuceneDocumentStructure.useFieldForUniquenessVerification(field)) {
TermsEnum terms = leafReader.terms(field).iterator();
BytesRef termsRef;
while ((termsRef = terms.next()) != null) {
if (terms.docFreq() > 1) {
collector.init(terms.docFreq());
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 NativeIndexAccessorTests method getValues.
@Test
void getValues() throws IndexEntryConflictException, IndexNotApplicableKernelException {
// given
int nUpdates = 10000;
Iterator<ValueIndexEntryUpdate<IndexDescriptor>> randomUpdateGenerator = valueCreatorUtil.randomUpdateGenerator(random);
// noinspection unchecked
ValueIndexEntryUpdate<IndexDescriptor>[] someUpdates = new ValueIndexEntryUpdate[nUpdates];
for (int i = 0; i < nUpdates; i++) {
someUpdates[i] = randomUpdateGenerator.next();
}
processAll(someUpdates);
Value[] allValues = ValueCreatorUtil.extractValuesFromUpdates(someUpdates);
// Pick one out of all added values and do a range query for the value group of that value
Value value = random.among(allValues);
ValueGroup valueGroup = value.valueGroup();
IndexValueCapability valueCapability = indexCapability().valueCapability(valueGroup.category());
if (!valueCapability.equals(IndexValueCapability.YES)) {
// We don't need to do this test
return;
}
PropertyIndexQuery.RangePredicate<?> supportedQuery;
List<Value> expectedValues;
if (Values.isGeometryValue(value)) {
// Unless it's a point value in which case we query for the specific coordinate reference system instead
CoordinateReferenceSystem crs = ((PointValue) value).getCoordinateReferenceSystem();
supportedQuery = PropertyIndexQuery.range(0, crs);
expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == ValueGroup.GEOMETRY).filter(v -> ((PointValue) v).getCoordinateReferenceSystem() == crs).collect(Collectors.toList());
} else {
supportedQuery = PropertyIndexQuery.range(0, valueGroup);
expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).collect(Collectors.toList());
}
// when
try (var reader = accessor.newValueReader()) {
SimpleEntityValueClient client = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, client, unorderedValues(), supportedQuery);
// then
while (client.next()) {
Value foundValue = client.values[0];
assertTrue(expectedValues.remove(foundValue), "found value that was not expected " + foundValue);
}
assertThat(expectedValues.size()).as("did not find all expected values").isEqualTo(0);
}
}
Aggregations