Search in sources :

Example 1 with RowOutputBinary

use of org.hsqldb_voltpatches.rowio.RowOutputBinary in project voltdb by VoltDB.

the class DataFileDefrag method writeTableToDataFile.

int[] writeTableToDataFile(Table table) throws IOException {
    Session session = database.getSessionManager().getSysSession();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowOutputInterface rowOut = new RowOutputBinary();
    DoubleIntIndex pointerLookup = new DoubleIntIndex(table.getPrimaryIndex().sizeEstimate(store), false);
    int[] rootsArray = table.getIndexRootsArray();
    long pos = fileOffset;
    int count = 0;
    pointerLookup.setKeysSearchTarget();
    Error.printSystemOut("lookup begins: " + stopw.elapsedTime());
    RowIterator it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        pointerLookup.addUnsorted(row.getPos(), (int) (pos / scale));
        if (count % 50000 == 0) {
            Error.printSystemOut("pointer pair for row " + count + " " + row.getPos() + " " + pos);
        }
        pos += row.getStorageSize();
    }
    Error.printSystemOut(table.getName().name + " list done ", stopw.elapsedTime());
    count = 0;
    it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        rowOut.reset();
        row.write(rowOut, pointerLookup);
        fileStreamOut.write(rowOut.getOutputStream().getBuffer(), 0, rowOut.size());
        fileOffset += row.getStorageSize();
        if ((count) % 50000 == 0) {
            Error.printSystemOut(count + " rows " + stopw.elapsedTime());
        }
    }
    for (int i = 0; i < rootsArray.length; i++) {
        if (rootsArray[i] == -1) {
            continue;
        }
        int lookupIndex = pointerLookup.findFirstEqualKeyIndex(rootsArray[i]);
        if (lookupIndex == -1) {
            throw Error.error(ErrorCode.DATA_FILE_ERROR);
        }
        rootsArray[i] = pointerLookup.getValue(lookupIndex);
    }
    setTransactionRowLookups(pointerLookup);
    Error.printSystemOut(table.getName().name + " : table converted");
    return rootsArray;
}
Also used : RowOutputInterface(org.hsqldb_voltpatches.rowio.RowOutputInterface) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) DoubleIntIndex(org.hsqldb_voltpatches.lib.DoubleIntIndex) RowOutputBinary(org.hsqldb_voltpatches.rowio.RowOutputBinary) Session(org.hsqldb_voltpatches.Session)

Aggregations

Session (org.hsqldb_voltpatches.Session)1 DoubleIntIndex (org.hsqldb_voltpatches.lib.DoubleIntIndex)1 RowIterator (org.hsqldb_voltpatches.navigator.RowIterator)1 RowOutputBinary (org.hsqldb_voltpatches.rowio.RowOutputBinary)1 RowOutputInterface (org.hsqldb_voltpatches.rowio.RowOutputInterface)1