Search in sources :

Example 1 with SimpleLog

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

the class Logger method openLog.

/**
     *  Opens the specified Database object's database files and starts up
     *  the logging process. <p>
     *
     *  If the specified Database object is a new database, its database
     *  files are first created.
     *
     * @param  db the Database
     * @throws  HsqlException if there is a problem, such as the case when
     *      the specified files are in use by another process
     */
public void openLog(Database db) {
    needsCheckpoint = false;
    String path = db.getPath();
    int loglevel = db.getProperties().getIntegerProperty(HsqlDatabaseProperties.hsqldb_applog, 0);
    this.database = db;
    if (loglevel != SimpleLog.LOG_NONE) {
        appLog = new SimpleLog(path + ".app.log", loglevel, !db.isFilesReadOnly());
    }
    appLog.sendLine(SimpleLog.LOG_ERROR, "Database (re)opened");
    logStatements = false;
    boolean useLock = db.getProperties().isPropertyTrue(HsqlDatabaseProperties.hsqldb_lock_file);
    if (useLock && !db.isFilesReadOnly()) {
        acquireLock(path);
    }
    log = new Log(db);
    log.open();
    logsStatements = logStatements = !db.isFilesReadOnly();
}
Also used : SimpleLog(org.hsqldb_voltpatches.lib.SimpleLog) SimpleLog(org.hsqldb_voltpatches.lib.SimpleLog)

Example 2 with SimpleLog

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

the class DataFileCache method close.

/**
     *  Parameter write indicates either an orderly close, or a fast close
     *  without backup.
     *
     *  When false, just closes the file.
     *
     *  When true, writes out all cached rows that have been modified and the
     *  free position pointer for the *.data file and then closes the file.
     */
public void close(boolean write) {
    SimpleLog appLog = database.logger.appLog;
    try {
        if (cacheReadonly) {
            if (dataFile != null) {
                dataFile.close();
                dataFile = null;
            }
            return;
        }
        StopWatch sw = new StopWatch();
        appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close(" + write + ") : start");
        if (write) {
            cache.saveAll();
            Error.printSystemOut("saveAll: " + sw.elapsedTime());
            appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : save data");
            if (fileModified || freeBlocks.isModified()) {
                // set empty
                dataFile.seek(LONG_EMPTY_SIZE);
                dataFile.writeLong(freeBlocks.getLostBlocksSize());
                // set end
                dataFile.seek(LONG_FREE_POS_POS);
                dataFile.writeLong(fileFreePosition);
                // set saved flag;
                dataFile.seek(FLAGS_POS);
                int flag = BitMap.set(0, FLAG_ISSAVED);
                if (hasRowInfo) {
                    flag = BitMap.set(flag, FLAG_ROWINFO);
                }
                dataFile.writeInt(flag);
                appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : flags");
                //
                if (dataFile.length() != fileFreePosition) {
                    dataFile.seek(fileFreePosition);
                }
                appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : seek end");
                Error.printSystemOut("pos and flags: " + sw.elapsedTime());
            }
        }
        if (dataFile != null) {
            dataFile.close();
            appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : close");
            dataFile = null;
            Error.printSystemOut("close: " + sw.elapsedTime());
        }
        boolean empty = fileFreePosition == INITIAL_FREE_POS;
        if (empty) {
            fa.removeElement(fileName);
            fa.removeElement(backupFileName);
        }
    } catch (Throwable e) {
        appLog.logContext(e, null);
        throw Error.error(ErrorCode.FILE_IO_ERROR, ErrorCode.M_DataFileCache_close, new Object[] { e, fileName });
    }
}
Also used : SimpleLog(org.hsqldb_voltpatches.lib.SimpleLog) StopWatch(org.hsqldb_voltpatches.lib.StopWatch)

Aggregations

SimpleLog (org.hsqldb_voltpatches.lib.SimpleLog)2 StopWatch (org.hsqldb_voltpatches.lib.StopWatch)1