use of org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper in project asterixdb by apache.
the class LogMarkerTest method testInsertWithSnapshot.
@Test
public void testInsertWithSnapshot() {
try {
TestNodeController nc = new TestNodeController(null, false);
nc.init();
StorageComponentProvider storageManager = new StorageComponentProvider();
List<List<String>> partitioningKeys = new ArrayList<>();
partitioningKeys.add(Collections.singletonList("key"));
Dataset dataset = new Dataset(DATAVERSE_NAME, DATASET_NAME, DATAVERSE_NAME, DATA_TYPE_NAME, NODE_GROUP_NAME, null, null, new InternalDatasetDetails(null, PartitioningStrategy.HASH, partitioningKeys, null, null, null, false, null, false), null, DatasetType.INTERNAL, DATASET_ID, 0);
try {
nc.createPrimaryIndex(dataset, KEY_TYPES, RECORD_TYPE, META_TYPE, new NoMergePolicyFactory(), null, null, storageManager, KEY_INDEXES, KEY_INDICATORS_LIST);
IHyracksTaskContext ctx = nc.createTestContext(true);
nc.newJobId();
ITransactionContext txnCtx = nc.getTransactionManager().getTransactionContext(nc.getTxnJobId(), true);
LSMInsertDeleteOperatorNodePushable insertOp = nc.getInsertPipeline(ctx, dataset, KEY_TYPES, RECORD_TYPE, META_TYPE, new NoMergePolicyFactory(), null, null, KEY_INDEXES, KEY_INDICATORS_LIST, storageManager).getLeft();
insertOp.open();
TupleGenerator tupleGenerator = new TupleGenerator(RECORD_TYPE, META_TYPE, KEY_INDEXES, KEY_INDICATORS, RECORD_GEN_FUNCTION, UNIQUE_RECORD_FIELDS, META_GEN_FUNCTION, UNIQUE_META_FIELDS);
VSizeFrame frame = new VSizeFrame(ctx);
VSizeFrame marker = new VSizeFrame(ctx);
FrameTupleAppender tupleAppender = new FrameTupleAppender(frame);
long markerId = 0L;
for (int j = 0; j < NUM_OF_RECORDS; j++) {
if (j % SNAPSHOT_SIZE == 0) {
marker.reset();
marker.getBuffer().put(MessagingFrameTupleAppender.MARKER_MESSAGE);
marker.getBuffer().putLong(markerId);
marker.getBuffer().flip();
markerId++;
TaskUtil.putInSharedMap(HyracksConstants.KEY_MESSAGE, marker, ctx);
tupleAppender.flush(insertOp);
}
ITupleReference tuple = tupleGenerator.next();
DataflowUtils.addTupleToFrame(tupleAppender, tuple, insertOp);
}
if (tupleAppender.getTupleCount() > 0) {
tupleAppender.write(insertOp, true);
}
insertOp.close();
nc.getTransactionManager().completedTransaction(txnCtx, DatasetId.NULL, -1, true);
IIndexDataflowHelper dataflowHelper = nc.getPrimaryIndexDataflowHelper(dataset, KEY_TYPES, RECORD_TYPE, META_TYPE, new NoMergePolicyFactory(), null, null, storageManager, KEY_INDEXES, KEY_INDICATORS_LIST);
dataflowHelper.open();
LSMBTree btree = (LSMBTree) dataflowHelper.getIndexInstance();
LongPointable longPointable = LongPointable.FACTORY.createPointable();
ComponentMetadataUtil.get(btree, ComponentMetadataUtil.MARKER_LSN_KEY, longPointable);
long lsn = longPointable.getLong();
int numOfMarkers = 0;
LogReader logReader = (LogReader) nc.getTransactionSubsystem().getLogManager().getLogReader(false);
long expectedMarkerId = markerId - 1;
while (lsn >= 0) {
numOfMarkers++;
ILogRecord logRecord = logReader.read(lsn);
lsn = logRecord.getPreviousMarkerLSN();
long logMarkerId = logRecord.getMarker().getLong();
Assert.assertEquals(expectedMarkerId, logMarkerId);
expectedMarkerId--;
}
logReader.close();
dataflowHelper.close();
Assert.assertEquals(markerId, numOfMarkers);
nc.newJobId();
TestTupleCounterFrameWriter countOp = create(nc.getSearchOutputDesc(KEY_TYPES, RECORD_TYPE, META_TYPE), Collections.emptyList(), Collections.emptyList(), false);
IPushRuntime emptyTupleOp = nc.getFullScanPipeline(countOp, ctx, dataset, KEY_TYPES, RECORD_TYPE, META_TYPE, new NoMergePolicyFactory(), null, null, KEY_INDEXES, KEY_INDICATORS_LIST, storageManager);
emptyTupleOp.open();
emptyTupleOp.close();
Assert.assertEquals(NUM_OF_RECORDS, countOp.getCount());
} finally {
nc.deInit();
}
} catch (Throwable e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper in project asterixdb by apache.
the class AbstractExternalDatasetIndexesOperatorDescriptor method createPushRuntime.
@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, final int partition, int nPartitions) {
return new AbstractOperatorNodePushable() {
@Override
public void initialize() throws HyracksDataException {
try {
// perform operation on btrees
for (int i = 0; i < treeIndexesDataflowHelperFactories.size(); i++) {
IIndexDataflowHelper indexHelper = treeIndexesDataflowHelperFactories.get(i).create(ctx, partition);
performOpOnIndex(indexHelper, ctx);
}
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
@Override
public void deinitialize() throws HyracksDataException {
}
@Override
public int getInputArity() {
return 0;
}
@Override
public void setOutputFrameWriter(int index, IFrameWriter writer, RecordDescriptor recordDesc) throws HyracksDataException {
}
@Override
public IFrameWriter getInputFrameWriter(int index) {
return null;
}
};
}
use of org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper in project asterixdb by apache.
the class FramewriterTest method mockIndexHelpers.
public IIndexDataflowHelper[] mockIndexHelpers() throws HyracksDataException {
ITreeIndex[] indexes = mockIndexes();
IIndexDataflowHelper[] indexHelpers = new IIndexDataflowHelper[indexes.length * 2];
int j = 0;
for (int i = 0; i < indexes.length; i++) {
// normal
indexHelpers[j] = Mockito.mock(IIndexDataflowHelper.class);
Mockito.when(indexHelpers[j].getIndexInstance()).thenReturn(indexes[i]);
// throws exception when opened
j++;
indexHelpers[j] = Mockito.mock(IIndexDataflowHelper.class);
Mockito.doThrow(new HyracksDataException("couldn't open index")).when(indexHelpers[j]).open();
Mockito.when(indexHelpers[j].getIndexInstance()).thenReturn(null);
j++;
}
return indexHelpers;
}
use of org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper in project asterixdb by apache.
the class IndexDataflowHelperFactory method create.
@Override
public IIndexDataflowHelper create(IHyracksTaskContext ctx, int partition) throws HyracksDataException {
FileSplit fileSplit = fileSplitProvider.getFileSplits()[partition];
FileReference resourceRef = fileSplit.getFileReference(ctx.getIoManager());
return new IndexDataflowHelper(ctx.getJobletContext().getServiceContext(), storageMgr, resourceRef);
}
use of org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper in project asterixdb by apache.
the class ExternalFilesIndexModificationOperatorDescriptor method createPushRuntime.
@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
return new AbstractOperatorNodePushable() {
@Override
public void initialize() throws HyracksDataException {
final IIndexDataflowHelper indexHelper = dataflowHelperFactory.create(ctx, partition);
FileIndexTupleTranslator filesTupleTranslator = new FileIndexTupleTranslator();
// Open and get
indexHelper.open();
IIndex index = indexHelper.getIndexInstance();
LSMTwoPCBTreeBulkLoader bulkLoader = null;
try {
bulkLoader = (LSMTwoPCBTreeBulkLoader) ((ExternalBTree) index).createTransactionBulkLoader(BTree.DEFAULT_FILL_FACTOR, false, files.size());
// The files must be ordered according to their numbers
for (ExternalFile file : files) {
switch(file.getPendingOp()) {
case ADD_OP:
case APPEND_OP:
bulkLoader.add(filesTupleTranslator.getTupleFromFile(file));
break;
case DROP_OP:
bulkLoader.delete(filesTupleTranslator.getTupleFromFile(file));
break;
case NO_OP:
break;
default:
throw HyracksDataException.create(ErrorCode.UNKNOWN_EXTERNAL_FILE_PENDING_OP, file.getPendingOp());
}
}
bulkLoader.end();
} catch (Exception e) {
if (bulkLoader != null) {
bulkLoader.abort();
}
throw HyracksDataException.create(e);
} finally {
indexHelper.close();
}
}
@Override
public void deinitialize() throws HyracksDataException {
}
@Override
public int getInputArity() {
return 0;
}
@Override
public void setOutputFrameWriter(int index, IFrameWriter writer, RecordDescriptor recordDesc) throws HyracksDataException {
}
@Override
public IFrameWriter getInputFrameWriter(int index) {
return null;
}
};
}
Aggregations