@Override public int getSlotSize() { return slotManager.getSlotSize(); }
public FrameOpSpaceStatus hasSpaceInsert(int bytesRequired) { if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(Constants.FREE_SPACE_OFFSET) - (buf.getInt(Constants.TUPLE_COUNT_OFFSET) * slotManager.getSlotSize())) { return FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE; } else if (bytesRequired + slotManager.getSlotSize() <= buf.getInt(TOTAL_FREE_SPACE_OFFSET)) { return FrameOpSpaceStatus.SUFFICIENT_SPACE; } else { return FrameOpSpaceStatus.INSUFFICIENT_SPACE; } }
@Override public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) throws HyracksDataException { int bytesRequired = tupleWriter.bytesRequired(tuple) + childPtrSize; if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(Constants.FREE_SPACE_OFFSET) - (buf.getInt(Constants.TUPLE_COUNT_OFFSET) * slotManager.getSlotSize())) { return FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE; } else if (bytesRequired + slotManager.getSlotSize() <= buf.getInt(TOTAL_FREE_SPACE_OFFSET)) { return FrameOpSpaceStatus.SUFFICIENT_SPACE; } else { return FrameOpSpaceStatus.INSUFFICIENT_SPACE; } }
@Override public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) throws HyracksDataException { int bytesRequired = tupleWriter.bytesRequired(tuple); // Enough space in the contiguous space region? if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(Constants.FREE_SPACE_OFFSET) - (buf.getInt(Constants.TUPLE_COUNT_OFFSET) * slotManager.getSlotSize())) { return FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE; } // Enough space after compaction? if (bytesRequired + slotManager.getSlotSize() <= buf.getInt(TOTAL_FREE_SPACE_OFFSET)) { return FrameOpSpaceStatus.SUFFICIENT_SPACE; } return FrameOpSpaceStatus.INSUFFICIENT_SPACE; }
@Override public int getBytesRequiredToWriteTuple(ITupleReference tuple) { return tupleWriter.bytesRequired(tuple) + slotManager.getSlotSize(); }
@Override public int getBytesRequiredToWriteTuple(ITupleReference tuple) { return tupleWriter.bytesRequired(tuple) + slotManager.getSlotSize(); }
@Override public int getBytesRequiredToWriteTuple(ITupleReference tuple) { return tupleWriter.bytesRequired(tuple) + childPtrSize + slotManager.getSlotSize(); }
@Override public int getBytesRequiredToWriteTuple(ITupleReference tuple) { return tupleWriter.bytesRequired(tuple) + CHILD_PTR_SIZE + slotManager.getSlotSize(); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { slotManager.insertSlot(-1, buf.getInt(Constants.FREE_SPACE_OFFSET)); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), buf.getInt(Constants.FREE_SPACE_OFFSET)); buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { slotManager.insertSlot(tupleIndex, buf.getInt(Constants.FREE_SPACE_OFFSET)); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), buf.getInt(Constants.FREE_SPACE_OFFSET)); buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); slotManager.insertSlot(tupleIndex, freeSpace); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), freeSpace); buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@Override public void delete(int tupleIndex, MultiComparator cmp) { int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleSize = tupleWriter.bytesRequired(frameTuple); // perform deletion (we just do a memcpy to overwrite the slot) int slotStartOff = slotManager.getSlotEndOff(); int length = slotOff - slotStartOff; System.arraycopy(buf.array(), slotStartOff, buf.array(), slotStartOff + slotManager.getSlotSize(), length); // maintain space information buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) - 1); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + tupleSize + slotManager.getSlotSize()); }
@Override public void delete(ITupleReference tuple, int tupleIndex) { int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleSize = tupleWriter.bytesRequired(frameTuple); // perform deletion (we just do a memcpy to overwrite the slot) int slotStartOff = slotManager.getSlotEndOff(); int length = slotOff - slotStartOff; System.arraycopy(buf.array(), slotStartOff, buf.array(), slotStartOff + slotManager.getSlotSize(), length); // maintain space information buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) - 1); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + tupleSize + slotManager.getSlotSize()); }
public int getFreeContiguousSpace() { return buf.capacity() - getFreeSpaceOff() - (getTupleCount() * slotManager.getSlotSize()); }
@Override public void deleteGreatest() { int slotOff = slotManager.getSlotEndOff(); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int keySize = tupleWriter.bytesRequired(frameTuple); System.arraycopy(buf.array(), tupleOff + keySize, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); // Maintain space information. buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) - 1); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + keySize + CHILD_PTR_SIZE + slotManager.getSlotSize()); int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); if (freeSpace == tupleOff + keySize + CHILD_PTR_SIZE) { buf.putInt(freeSpace, freeSpace - (keySize + CHILD_PTR_SIZE)); } }
@Override public int getTupleOffset(int slotNum) { return slotManager.getTupleOff(slotManager.getSlotStartOff() - slotNum * slotManager.getSlotSize()); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { frameTuple.setFieldCount(tuple.getFieldCount()); slotManager.insertSlot(AbstractSlotManager.GREATEST_KEY_INDICATOR, buf.getInt(Constants.FREE_SPACE_OFFSET)); int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); int bytesWritten = tupleWriter.writeTupleFields(tuple, 0, tuple.getFieldCount(), buf.array(), freeSpace); System.arraycopy(tuple.getFieldData(tuple.getFieldCount() - 1), getChildPointerOff(tuple), buf.array(), freeSpace + bytesWritten, childPtrSize); int tupleSize = bytesWritten + childPtrSize; buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + tupleSize); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - tupleSize - slotManager.getSlotSize()); }
@Override public void insertSorted(ITupleReference tuple) { int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); slotManager.insertSlot(slotManager.getGreatestKeyIndicator(), freeSpace); int bytesWritten = tupleWriter.writeTuple(tuple, buf, freeSpace); System.arraycopy(tuple.getFieldData(tuple.getFieldCount() - 1), getLeftChildPageOff(tuple), buf.array(), freeSpace + bytesWritten, CHILD_PTR_SIZE); int tupleSize = bytesWritten + CHILD_PTR_SIZE; buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + tupleSize); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - tupleSize - slotManager.getSlotSize()); System.arraycopy(tuple.getFieldData(0), getLeftChildPageOff(tuple) + CHILD_PTR_SIZE, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); }
@Override public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) throws HyracksDataException { int tupleSize = tupleWriter.bytesRequired(tuple) + CHILD_PTR_SIZE; if (tupleSize > getMaxTupleSize(buf.capacity())) { return FrameOpSpaceStatus.TOO_LARGE; } // Tuple bytes + child pointer + slot. int bytesRequired = tupleSize + slotManager.getSlotSize(); if (bytesRequired <= getFreeContiguousSpace()) { return FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE; } if (bytesRequired <= getTotalFreeSpace()) { return FrameOpSpaceStatus.SUFFICIENT_SPACE; } return FrameOpSpaceStatus.INSUFFICIENT_SPACE; }
private void growCapacity(IExtraPageBlockHelper extraPageBlockHelper, IBufferCache bufferCache, int deltaPages) throws HyracksDataException { int framePagesOld = page.getFrameSizeMultiplier(); int newMultiplier = framePagesOld + deltaPages; // we need to get the old slot offsets before we grow int oldSlotEnd = slotManager.getSlotEndOff(); int oldSlotStart = slotManager.getSlotStartOff() + slotManager.getSlotSize(); bufferCache.resizePage(getPage(), newMultiplier, extraPageBlockHelper); buf = getPage().getBuffer(); // fixup the slots System.arraycopy(buf.array(), oldSlotEnd, buf.array(), slotManager.getSlotEndOff(), oldSlotStart - oldSlotEnd); // fixup total free space counter buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + (bufferCache.getPageSize() * deltaPages)); }