Search in sources :

Example 1 with Storage

use of org.hsqldb_voltpatches.lib.Storage in project voltdb by VoltDB.

the class DataFileDefrag method process.

void process() throws IOException {
    boolean complete = false;
    Error.printSystemOut("Defrag Transfer begins");
    transactionRowLookup = database.txManager.getTransactionIDList();
    HsqlArrayList allTables = database.schemaManager.getAllTables();
    rootsList = new int[allTables.size()][];
    Storage dest = null;
    try {
        OutputStream fos = database.getFileAccess().openOutputStreamElement(filename + ".new");
        fileStreamOut = new BufferedOutputStream(fos, 1 << 12);
        for (int i = 0; i < DataFileCache.INITIAL_FREE_POS; i++) {
            fileStreamOut.write(0);
        }
        fileOffset = DataFileCache.INITIAL_FREE_POS;
        for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
            Table t = (Table) allTables.get(i);
            if (t.getTableType() == TableBase.CACHED_TABLE) {
                int[] rootsArray = writeTableToDataFile(t);
                rootsList[i] = rootsArray;
            } else {
                rootsList[i] = null;
            }
            Error.printSystemOut(t.getName().name + " complete");
        }
        writeTransactionRows();
        fileStreamOut.flush();
        fileStreamOut.close();
        fileStreamOut = null;
        // write out the end of file position
        dest = ScaledRAFile.newScaledRAFile(database, filename + ".new", false, ScaledRAFile.DATA_FILE_RAF, database.getURLProperties().getProperty("storage_class_name"), database.getURLProperties().getProperty("storage_key"));
        dest.seek(DataFileCache.LONG_FREE_POS_POS);
        dest.writeLong(fileOffset);
        dest.close();
        dest = null;
        for (int i = 0, size = rootsList.length; i < size; i++) {
            int[] roots = rootsList[i];
            if (roots != null) {
                Error.printSystemOut(org.hsqldb_voltpatches.lib.StringUtil.getList(roots, ",", ""));
            }
        }
        complete = true;
    } catch (IOException e) {
        throw Error.error(ErrorCode.FILE_IO_ERROR, filename + ".new");
    } catch (OutOfMemoryError e) {
        throw Error.error(ErrorCode.OUT_OF_MEMORY);
    } finally {
        if (fileStreamOut != null) {
            fileStreamOut.close();
        }
        if (dest != null) {
            dest.close();
        }
        if (!complete) {
            database.getFileAccess().removeElement(filename + ".new");
        }
    }
//Error.printSystemOut("Transfer complete: ", stopw.elapsedTime());
}
Also used : Storage(org.hsqldb_voltpatches.lib.Storage) Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Storage

use of org.hsqldb_voltpatches.lib.Storage in project voltdb by VoltDB.

the class ScaledRAFile method newScaledRAFile.

/**
     * seekPosition is the position in seek() calls or after reading or writing
     * realPosition is the file position
     */
static Storage newScaledRAFile(Database database, String name, boolean readonly, int type, String classname, String key) throws FileNotFoundException, IOException {
    if (classname != null) {
        try {
            Class zclass = Class.forName(classname);
            Constructor constructor = zclass.getConstructor(new Class[] { String.class, Boolean.class, Object.class });
            return (Storage) constructor.newInstance(new Object[] { name, new Boolean(readonly), key });
        } catch (ClassNotFoundException e) {
            throw new IOException();
        } catch (NoSuchMethodException e) {
            throw new IOException();
        } catch (InstantiationException e) {
            throw new IOException();
        } catch (IllegalAccessException e) {
            throw new IOException();
        } catch (java.lang.reflect.InvocationTargetException e) {
            throw new IOException();
        }
    }
    if (type == DATA_FILE_JAR) {
        return new ScaledRAFileInJar(name);
    } else if (type == DATA_FILE_RAF) {
        return new ScaledRAFile(database, name, readonly);
    } else {
        RandomAccessFile file = new RandomAccessFile(name, readonly ? "r" : "rw");
        if (file.length() > MAX_NIO_LENGTH) {
            return new ScaledRAFile(database, name, file, readonly);
        } else {
            file.close();
        }
        try {
            Class.forName("java.nio.MappedByteBuffer");
            Class c = Class.forName("org.hsqldb_voltpatches.persist.ScaledRAFileHybrid");
            Constructor constructor = c.getConstructor(new Class[] { Database.class, String.class, boolean.class });
            return (ScaledRAInterface) constructor.newInstance(new Object[] { database, name, new Boolean(readonly) });
        } catch (Exception e) {
            return new ScaledRAFile(database, name, readonly);
        }
    }
}
Also used : Constructor(java.lang.reflect.Constructor) IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) Storage(org.hsqldb_voltpatches.lib.Storage) RandomAccessFile(java.io.RandomAccessFile) Database(org.hsqldb_voltpatches.Database)

Aggregations

IOException (java.io.IOException)2 Storage (org.hsqldb_voltpatches.lib.Storage)2 BufferedOutputStream (java.io.BufferedOutputStream)1 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 Constructor (java.lang.reflect.Constructor)1 Database (org.hsqldb_voltpatches.Database)1 Table (org.hsqldb_voltpatches.Table)1 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)1