use of org.apache.hyracks.api.comm.FixedSizeFrame in project asterixdb by apache.
the class AbstractTupleMemoryManagerTest method prepareVariableSizeTuples.
protected Map<Integer, Integer> prepareVariableSizeTuples() throws HyracksDataException {
Map<Integer, Integer> dataSet = new HashMap<>();
ByteBuffer buffer = ByteBuffer.allocate(Common.BUDGET);
FixedSizeFrame frame = new FixedSizeFrame(buffer);
FrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
for (int i = 0; true; i++) {
tupleBuilder.reset();
tupleBuilder.addField(fieldsSerDer[0], i);
tupleBuilder.addField(fieldsSerDer[1], Utility.repeatString('a', i));
if (!appender.append(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray(), 0, tupleBuilder.getSize())) {
break;
}
dataSet.put(i, tupleBuilder.getSize() + tupleBuilder.getFieldEndOffsets().length * 4);
}
inFTA.reset(buffer);
return dataSet;
}
use of org.apache.hyracks.api.comm.FixedSizeFrame in project asterixdb by apache.
the class VariableTupleMemoryManagerTest method deleteRandomSelectedTuples.
private ByteBuffer deleteRandomSelectedTuples(Map<Integer, Integer> map, Map<TuplePointer, Integer> mapInserted, int minNumOfRecordTobeDeleted) throws HyracksDataException {
ByteBuffer buffer = ByteBuffer.allocate(Common.BUDGET);
FixedSizeFrame frame = new FixedSizeFrame(buffer);
FrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
assert (minNumOfRecordTobeDeleted < mapInserted.size());
int countDeleted = minNumOfRecordTobeDeleted + random.nextInt(mapInserted.size() - minNumOfRecordTobeDeleted);
ITuplePointerAccessor accessor = tupleMemoryManager.createTuplePointerAccessor();
for (int i = 0; i < countDeleted; i++) {
Iterator<Map.Entry<TuplePointer, Integer>> iter = mapInserted.entrySet().iterator();
assert (iter.hasNext());
Map.Entry<TuplePointer, Integer> pair = iter.next();
accessor.reset(pair.getKey());
appender.append(accessor.getBuffer().array(), accessor.getTupleStartOffset(), accessor.getTupleLength());
map.remove(pair.getValue());
tupleMemoryManager.deleteTuple(pair.getKey());
iter.remove();
}
return buffer;
}
use of org.apache.hyracks.api.comm.FixedSizeFrame in project asterixdb by apache.
the class VariableFramesMemoryManagerTest method prepareRandomTuples.
private HashMap<Integer, Integer> prepareRandomTuples() throws HyracksDataException {
frameList.clear();
HashMap<Integer, Integer> set = new HashMap<>(NUM_MIN_FRAME);
int[] fieldSlot = { 0 };
int id = 0;
int size = 0;
while (size < BUDGET) {
int tupleLength = random.nextInt(BUDGET / 3) + 4;
IFrame frame = new FixedSizeFrame(Common.commonFrameManager.allocateFrame(FrameHelper.calcAlignedFrameSizeToStore(1, tupleLength, MIN_FRAME_SIZE)));
IFrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
// System.out.println("id:" + id + ",frameSize:" + frame.getInitialFrameSize() / MIN_FRAME_SIZE);
ByteBuffer buffer = ByteBuffer.allocate(tupleLength);
buffer.putInt(0, id);
assertTrue(appender.append(fieldSlot, buffer.array(), 0, buffer.capacity()));
set.put(id++, tupleLength);
size += frame.getFrameSize();
frameList.add(frame);
}
return set;
}
use of org.apache.hyracks.api.comm.FixedSizeFrame in project asterixdb by apache.
the class VariableFramesMemoryManagerTest method prepareTuples.
private HashMap<Integer, Integer> prepareTuples() throws HyracksDataException {
frameList.clear();
HashMap<Integer, Integer> set = new HashMap<>(NUM_MIN_FRAME);
for (int i = 0; i < NUM_MIN_FRAME; ++i) {
IFrame frame = new FixedSizeFrame(Common.commonFrameManager.allocateFrame(MIN_FRAME_SIZE));
IFrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
int[] fieldSlot = { 0 };
ByteBuffer buffer = ByteBuffer.allocate(MIN_FRAME_SIZE / 2);
buffer.putInt(0, i);
appender.append(fieldSlot, buffer.array(), 0, buffer.capacity());
set.put(i, buffer.capacity());
frameList.add(frame);
}
return set;
}
use of org.apache.hyracks.api.comm.FixedSizeFrame in project asterixdb by apache.
the class AbstractTupleMemoryManagerTest method prepareFixedSizeTuples.
protected Map<Integer, Integer> prepareFixedSizeTuples(int tuplePerFrame, int extraMetaBytePerFrame, int extraMetaBytePerRecord) throws HyracksDataException {
Map<Integer, Integer> dataSet = new HashMap<>();
ByteBuffer buffer = ByteBuffer.allocate(Common.BUDGET);
FixedSizeFrame frame = new FixedSizeFrame(buffer);
FrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
int sizePerTuple = (Common.MIN_FRAME_SIZE - 1 - tuplePerFrame * 4 - 4 - extraMetaBytePerFrame) / tuplePerFrame;
int sizeChar = //2byte to write str length
sizePerTuple - extraMetaBytePerRecord - fieldsSerDer.length * 4 - 4 - 2;
assert (sizeChar > 0);
for (int i = 0; i < Common.NUM_MIN_FRAME * tuplePerFrame; i++) {
tupleBuilder.reset();
tupleBuilder.addField(fieldsSerDer[0], i);
tupleBuilder.addField(fieldsSerDer[1], Utility.repeatString('a', sizeChar));
if (!appender.append(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray(), 0, tupleBuilder.getSize())) {
assert false;
}
dataSet.put(i, tupleBuilder.getSize() + tupleBuilder.getFieldEndOffsets().length * 4);
}
inFTA.reset(buffer);
return dataSet;
}
Aggregations