use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class OQueryOperatorMinorEquals method executeIndexQuery.
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
final OIndexDefinition indexDefinition = index.getDefinition();
final OIndexInternal<?> internalIndex = index.getInternal();
OIndexCursor cursor;
if (!internalIndex.canBeUsedInEqualityOperators() || !internalIndex.hasRangeQuerySupport())
return null;
if (indexDefinition.getParamCount() == 1) {
final Object key;
if (indexDefinition instanceof OIndexDefinitionMultiValue)
key = ((OIndexDefinitionMultiValue) indexDefinition).createSingleValue(keyParams.get(0));
else
key = indexDefinition.createValue(keyParams);
if (key == null)
return null;
cursor = index.iterateEntriesMinor(key, true, ascSortOrder);
} else {
// if we have situation like "field1 = 1 AND field2 <= 2"
// then we fetch collection which left included boundary is the smallest composite key in the
// index that contains key with value field1=1 and which right not included boundary
// is the biggest composite key in the index that contains key with value field1=1 and field2=2.
final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
final Object keyOne = compositeIndexDefinition.createSingleValue(keyParams.subList(0, keyParams.size() - 1));
if (keyOne == null)
return null;
final Object keyTwo = compositeIndexDefinition.createSingleValue(keyParams);
if (keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, true, keyTwo, true, ascSortOrder);
}
updateProfiler(iContext, index, keyParams, indexDefinition);
return cursor;
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class IndexCrashRestoreMultiValueAddDeleteIT method compareIndexes.
private void compareIndexes() {
baseDocumentTx.activateOnCurrentThread();
OIndexCursor cursor = baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").cursor();
long lastTs = 0;
long minLostTs = Long.MAX_VALUE;
long restoredRecords = 0;
Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
while (entry != null) {
baseDocumentTx.activateOnCurrentThread();
Integer key = (Integer) entry.getKey();
OIdentifiable identifiable = entry.getValue();
ODocument doc = identifiable.getRecord();
long ts = doc.<Long>field("ts");
if (ts > lastTs)
lastTs = ts;
entry = cursor.nextEntry();
testDocumentTx.activateOnCurrentThread();
OIndex testIndex = testDocumentTx.getMetadata().getIndexManager().getIndex("mi");
Set<OIdentifiable> result = (Set<OIdentifiable>) testIndex.get(key);
if (result == null || result.size() != 10) {
if (minLostTs > ts)
minLostTs = ts;
} else {
boolean cnt = true;
for (int i = 0; i < 10; i++) {
if (!result.contains(new ORecordId("#0:" + i))) {
cnt = false;
break;
}
}
if (!cnt) {
if (minLostTs > ts)
minLostTs = ts;
} else
restoredRecords++;
}
}
baseDocumentTx.activateOnCurrentThread();
System.out.println("Restored entries : " + restoredRecords + " out of : " + baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").getSize());
System.out.println("Lost records max interval : " + (minLostTs == Long.MAX_VALUE ? 0 : lastTs - minLostTs));
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class IndexCrashRestoreMultiValueIT method compareIndexes.
private void compareIndexes() {
baseDocumentTx.activateOnCurrentThread();
OIndexCursor cursor = baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").cursor();
long lastTs = 0;
long minLostTs = Long.MAX_VALUE;
long restoredRecords = 0;
Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
while (entry != null) {
baseDocumentTx.activateOnCurrentThread();
Integer key = (Integer) entry.getKey();
OIdentifiable identifiable = entry.getValue();
ODocument doc = identifiable.getRecord();
long ts = doc.<Long>field("ts");
if (ts > lastTs)
lastTs = ts;
entry = cursor.nextEntry();
testDocumentTx.activateOnCurrentThread();
OIndex testIndex = testDocumentTx.getMetadata().getIndexManager().getIndex("mi");
Set<OIdentifiable> result = (Set<OIdentifiable>) testIndex.get(key);
if (result == null || result.size() < 10) {
if (minLostTs > ts)
minLostTs = ts;
} else {
boolean cnt = true;
for (int i = 0; i < 10; i++) {
if (!result.contains(new ORecordId("#0:" + i))) {
cnt = false;
break;
}
}
if (!cnt) {
if (minLostTs > ts)
minLostTs = ts;
} else {
restoredRecords++;
}
}
}
baseDocumentTx.activateOnCurrentThread();
System.out.println("Restored entries : " + restoredRecords + " out of : " + baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").getSize() + " minLostTs:: " + minLostTs);
long maxInterval = minLostTs == Long.MAX_VALUE ? 0 : lastTs - minLostTs;
System.out.println("Lost records max interval (ms) : " + maxInterval);
assertThat(maxInterval).isLessThan(2000);
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class IndexCrashRestoreSingleValueIT method compareIndexes.
private void compareIndexes() {
ODatabaseRecordThreadLocal.INSTANCE.set(baseDocumentTx);
OIndexCursor cursor = baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").cursor();
long lastTs = 0;
long minLostTs = Long.MAX_VALUE;
long restoredRecords = 0;
Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
while (entry != null) {
ODatabaseRecordThreadLocal.INSTANCE.set(baseDocumentTx);
Integer key = (Integer) entry.getKey();
OIdentifiable identifiable = entry.getValue();
ODocument doc = identifiable.getRecord();
long ts = doc.<Long>field("ts");
if (ts > lastTs)
lastTs = ts;
entry = cursor.nextEntry();
ODatabaseRecordThreadLocal.INSTANCE.set(testDocumentTx);
OIndex testIndex = testDocumentTx.getMetadata().getIndexManager().getIndex("mi");
Set<OIdentifiable> result = (Set<OIdentifiable>) testIndex.get(key);
if (result == null || result.isEmpty()) {
if (minLostTs > ts)
minLostTs = ts;
} else
restoredRecords++;
}
ODatabaseRecordThreadLocal.INSTANCE.set(baseDocumentTx);
System.out.println("Restored entries : " + restoredRecords + " out of : " + baseDocumentTx.getMetadata().getIndexManager().getIndex("mi").getSize());
long maxInterval = minLostTs == Long.MAX_VALUE ? 0 : lastTs - minLostTs;
System.out.println("Lost records max interval (ms) : " + maxInterval);
assertThat(maxInterval).isLessThan(2000);
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class IndexTxAwareMultiValueGetEntriesTest method testRemoveOneWithinTransaction.
@Test
public void testRemoveOneWithinTransaction() {
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareMultiValueGetEntriesTest");
Assert.assertTrue(index instanceof OIndexTxAwareMultiValue);
final int clusterId = database.getDefaultClusterId();
List<Long> positions = getValidPositions(clusterId);
index.put(1, new ORecordId(clusterId, positions.get(1)));
index.put(2, new ORecordId(clusterId, positions.get(2)));
index.remove(1, new ORecordId(clusterId, positions.get(1)));
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareMultiValueGetEntriesTest"));
Set<OIdentifiable> result = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 1);
database.commit();
result = new HashSet<OIdentifiable>();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 1);
}
Aggregations