use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.
the class FramewriterTest method mockIndexAccessors.
private IIndexAccessor[] mockIndexAccessors() throws HyracksDataException {
IIndexCursor[] cursors = mockIndexCursors();
IIndexAccessor[] accessors = new IIndexAccessor[cursors.length * 2];
int j = 0;
for (int i = 0; i < cursors.length; i++) {
IIndexCursor cursor = cursors[i];
IIndexAccessor accessor = Mockito.mock(IIndexAccessor.class);
Mockito.when(accessor.createSearchCursor(Matchers.anyBoolean())).thenReturn(cursor);
accessors[j] = accessor;
j++;
accessor = Mockito.mock(IIndexAccessor.class);
Mockito.when(accessor.createSearchCursor(Matchers.anyBoolean())).thenReturn(cursor);
Mockito.doAnswer(new Answer<Object>() {
private int k = 0;
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
k++;
if (k % 2 == 0) {
throw new HyracksDataException("Couldn't search index");
}
return null;
}
}).when(accessor).search(Matchers.any(), Matchers.any());
accessors[j] = accessor;
j++;
}
return accessors;
}
use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.
the class MetadataNode method initializeDatasetIdFactory.
@Override
public void initializeDatasetIdFactory(JobId jobId) throws MetadataException, RemoteException {
int mostRecentDatasetId = MetadataIndexImmutableProperties.FIRST_AVAILABLE_USER_DATASET_ID;
try {
String resourceName = MetadataPrimaryIndexes.DATASET_DATASET.getFile().getRelativePath();
IIndex indexInstance = datasetLifecycleManager.get(resourceName);
datasetLifecycleManager.open(resourceName);
try {
IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false);
DatasetTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getDatasetTupleTranslator(false);
IValueExtractor<Dataset> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
RangePredicate rangePred = new RangePredicate(null, null, true, true, null, null);
indexAccessor.search(rangeCursor, rangePred);
int datasetId;
try {
while (rangeCursor.hasNext()) {
rangeCursor.next();
final ITupleReference ref = rangeCursor.getTuple();
final Dataset ds = valueExtractor.getValue(jobId, ref);
datasetId = ds.getDatasetId();
if (mostRecentDatasetId < datasetId) {
mostRecentDatasetId = datasetId;
}
}
} finally {
rangeCursor.close();
}
} finally {
datasetLifecycleManager.close(resourceName);
}
} catch (HyracksDataException e) {
throw new MetadataException(e);
}
DatasetIdFactory.initialize(mostRecentDatasetId);
}
use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.
the class LSMRTreeDeletedKeysBTreeMergeCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
cmp = lsmInitialState.getBTreeCmp();
operationalComponents = lsmInitialState.getOperationalComponents();
// We intentionally set the lsmHarness to null so that we don't call lsmHarness.endSearch() because we already do that when we merge r-trees.
lsmHarness = null;
int numBTrees = operationalComponents.size();
rangeCursors = new IIndexCursor[numBTrees];
RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp);
IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees];
for (int i = 0; i < numBTrees; i++) {
ILSMComponent component = operationalComponents.get(i);
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame();
rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
BTree btree = ((LSMRTreeDiskComponent) component).getBTree();
btreeAccessors[i] = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
btreeAccessors[i].search(rangeCursors[i], btreePredicate);
}
setPriorityQueueComparator();
initPriorityQueue();
}
use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.
the class AbstractModificationOperationCallbackTest method modificationCallbackTest.
@Test
public void modificationCallbackTest() throws Exception {
IIndexAccessor accessor = index.createAccessor(cb, NoOpOperationCallback.INSTANCE);
isFoundNull = true;
for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
TupleUtils.createIntegerTuple(builder, tuple, i);
accessor.insert(tuple);
}
isFoundNull = false;
for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
TupleUtils.createIntegerTuple(builder, tuple, i);
accessor.upsert(tuple);
}
isFoundNull = false;
for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
TupleUtils.createIntegerTuple(builder, tuple, i);
accessor.delete(tuple);
}
}
use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.
the class OrderedIndexExamplesTest method twoFixedLengthKeysOneFixedLengthValueExample.
/**
* Composite Key Example (Non-Unique Index). Create a tree index with two
* fixed-length key fields and one fixed-length value field. Fill index with
* random values using insertions (not bulk load) Perform scans and range
* search.
*/
@Test
public void twoFixedLengthKeysOneFixedLengthValueExample() throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Composite Key Test");
}
// Declare fields.
int fieldCount = 3;
ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
typeTraits[0] = IntegerPointable.TYPE_TRAITS;
typeTraits[1] = IntegerPointable.TYPE_TRAITS;
typeTraits[2] = IntegerPointable.TYPE_TRAITS;
// Declare field serdes.
ISerializerDeserializer[] fieldSerdes = { IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE };
// declare keys
int keyFieldCount = 2;
IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
cmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
cmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
// This is only used for the LSM-BTree.
int[] bloomFilterKeyFields = new int[keyFieldCount];
bloomFilterKeyFields[0] = 0;
bloomFilterKeyFields[1] = 1;
ITreeIndex treeIndex = createTreeIndex(typeTraits, cmpFactories, bloomFilterKeyFields, null, null, null, null);
treeIndex.create();
treeIndex.activate();
long start = System.currentTimeMillis();
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Inserting into tree...");
}
ArrayTupleBuilder tb = new ArrayTupleBuilder(fieldCount);
ArrayTupleReference tuple = new ArrayTupleReference();
IIndexAccessor indexAccessor = treeIndex.createAccessor(TestOperationCallback.INSTANCE, TestOperationCallback.INSTANCE);
int numInserts = 10000;
for (int i = 0; i < 10000; i++) {
int f0 = rnd.nextInt() % 2000;
int f1 = rnd.nextInt() % 1000;
int f2 = 5;
TupleUtils.createIntegerTuple(tb, tuple, f0, f1, f2);
if (LOGGER.isLoggable(Level.INFO)) {
if (i % 1000 == 0) {
LOGGER.info("Inserting " + i + " : " + f0 + " " + f1 + " " + f2);
}
}
try {
indexAccessor.insert(tuple);
} catch (HyracksDataException e) {
if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
throw e;
}
}
}
long end = System.currentTimeMillis();
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(numInserts + " inserts in " + (end - start) + "ms");
}
orderedScan(indexAccessor, fieldSerdes);
diskOrderScan(indexAccessor, fieldSerdes);
// Build low key.
ArrayTupleBuilder lowKeyTb = new ArrayTupleBuilder(1);
ArrayTupleReference lowKey = new ArrayTupleReference();
TupleUtils.createIntegerTuple(lowKeyTb, lowKey, -3);
// Build high key.
ArrayTupleBuilder highKeyTb = new ArrayTupleBuilder(1);
ArrayTupleReference highKey = new ArrayTupleReference();
TupleUtils.createIntegerTuple(highKeyTb, highKey, 3);
// Prefix-Range search in [-3, 3]
rangeSearch(cmpFactories, indexAccessor, fieldSerdes, lowKey, highKey, null, null);
treeIndex.validate();
treeIndex.deactivate();
treeIndex.destroy();
}
Aggregations