use of org.apache.hyracks.data.std.primitive.LongPointable 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.data.std.primitive.LongPointable in project asterixdb by apache.
the class AbstractLSMIOOperationCallback method getTreeIndexLSN.
public static long getTreeIndexLSN(DiskComponentMetadata md) throws HyracksDataException {
LongPointable pointable = new LongPointable();
IMetadataPageManager metadataPageManager = md.getMetadataPageManager();
metadataPageManager.get(metadataPageManager.createMetadataFrame(), LSN_KEY, pointable);
return pointable.getLength() == 0 ? INVALID : pointable.longValue();
}
use of org.apache.hyracks.data.std.primitive.LongPointable in project asterixdb by apache.
the class AbstractLSMIOOperationCallback method afterOperation.
@Override
public final void afterOperation(LSMOperationType opType, List<ILSMComponent> oldComponents, ILSMDiskComponent newComponent) throws HyracksDataException {
//TODO: Copying Filters and all content of the metadata pages for flush operation should be done here
if (newComponent != null) {
putLSNIntoMetadata(newComponent, oldComponents);
putComponentIdIntoMetadata(newComponent, oldComponents);
if (opType == LSMOperationType.MERGE) {
LongPointable markerLsn = LongPointable.FACTORY.createPointable(ComponentMetadataUtil.getLong(oldComponents.get(0).getMetadata(), ComponentMetadataUtil.MARKER_LSN_KEY, ComponentMetadataUtil.NOT_FOUND));
newComponent.getMetadata().put(ComponentMetadataUtil.MARKER_LSN_KEY, markerLsn);
}
}
}
use of org.apache.hyracks.data.std.primitive.LongPointable in project asterixdb by apache.
the class LIFOMetadataFrameTest method test.
@Test
public void test() throws HyracksDataException {
LIFOMetaDataFrame frame = new LIFOMetaDataFrame();
VirtualPage page = new VirtualPage(ByteBuffer.allocate(512), 512);
MutableArrayValueReference testKey = new MutableArrayValueReference("TestLSNKey".getBytes());
frame.setPage(page);
frame.init();
LongPointable longPointable = (LongPointable) LongPointable.FACTORY.createPointable();
frame.get(testKey, longPointable);
Assert.assertNull(longPointable.getByteArray());
byte[] longBytes = new byte[Long.BYTES];
MutableArrayValueReference value = new MutableArrayValueReference(longBytes);
int space = frame.getSpace() - (value.getLength() + Integer.BYTES * 2 + testKey.getLength());
for (long l = 1L; l < 52L; l++) {
LongPointable.setLong(longBytes, 0, l);
frame.put(testKey, value);
Assert.assertEquals(space, frame.getSpace());
frame.get(testKey, longPointable);
Assert.assertEquals(l, longPointable.longValue());
}
Assert.assertEquals(frame.getFreePage(), -1);
// add 10 pages and monitor space
for (int i = 0; i < 10; i++) {
frame.addFreePage(i);
space -= Integer.BYTES;
Assert.assertEquals(space, frame.getSpace());
}
for (int i = 9; i >= 0; i--) {
int freePage = frame.getFreePage();
Assert.assertEquals(freePage, i);
space += Integer.BYTES;
Assert.assertEquals(space, frame.getSpace());
}
Assert.assertTrue(frame.getFreePage() < 0);
}
Aggregations