* @param p1
     * @param p2
     * @param insertAt
     * @param includesRightEdge
     */
    void moveRecords(Buffer buffer, int p1, int p2, int insertAt, boolean includesRightEdge) {
        if (p2 - p1 + _keyBlockEnd > _alloc) {
            repack();
        }
        if (insertAt < _keyBlockEnd) {
            System.arraycopy(_bytes, insertAt, _bytes, insertAt + p2 - p1, _keyBlockEnd - insertAt);

        }
        clearBytes(insertAt, insertAt + p2 - p1);

        setKeyBlockEnd(getKeyBlockEnd() + p2 - p1);
        if (includesRightEdge)
            setKeyBlockEnd(getKeyBlockEnd() + KEYBLOCK_LENGTH);

        for (int p = p1; p < p2 || includesRightEdge && p == p2; p += KEYBLOCK_LENGTH) {
            int kbData = buffer.getInt(p);
            int ebc = decodeKeyBlockEbc(kbData);
            int db = decodeKeyBlockDb(kbData);
            int tail = decodeKeyBlockTail(kbData);
            int tbData = buffer.getInt(tail);
            int size = decodeTailBlockSize(tbData);
            int klength = decodeTailBlockKLength(tbData);
            int newSize = size;
            boolean edgeCase = includesRightEdge && p == p2;
            if (edgeCase) {
                // this is just for the right edge key of the left page
                newSize = _tailHeaderSize + klength;
            }

            int newTail = allocTail(newSize);
            if (newTail == -1) {
                repack();
                newTail = allocTail(newSize);
            }

            if (newTail == -1) {
                _persistit
                        .fatal("Insufficient space to move records in " + this + "from " + buffer + " at =" + p, null);
            }

            System.arraycopy(buffer._bytes, tail + 4, _bytes, newTail + 4, newSize - 4);

            putInt(newTail, encodeTailBlock(newSize, klength));

            if (edgeCase && isIndexPage()) {
                putInt(newTail + TAILBLOCK_POINTER, -1);
            }

            putInt(insertAt, encodeKeyBlock(ebc, db, newTail));
            insertAt += KEYBLOCK_LENGTH;

            if (!edgeCase) {
                //
                // Remove the record from the source page.
                //
                buffer.deallocTail(tail, size);
                buffer.putInt(p, 0);
            }
        }
    }