Search in sources :

Example 1 with DataFileCache

use of org.hsqldb_voltpatches.persist.DataFileCache in project voltdb by VoltDB.

the class TextTable method connect.

/**
     * connects to the data source
     */
private void connect(Session session, boolean withReadOnlyData) {
    // Open new cache:
    if ((dataSource.length() == 0) || isConnected) {
        // nothing to do
        return;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(this);
    this.store = store;
    DataFileCache cache = null;
    try {
        cache = (TextCache) database.logger.openTextCache(this, dataSource, withReadOnlyData, isReversed);
        store.setCache(cache);
        // read and insert all the rows from the source file
        Row row = null;
        int nextpos = 0;
        if (((TextCache) cache).ignoreFirst) {
            nextpos += ((TextCache) cache).readHeaderLine();
        }
        while (true) {
            row = (Row) store.get(nextpos, false);
            if (row == null) {
                break;
            }
            Object[] data = row.getData();
            nextpos = row.getPos() + row.getStorageSize();
            ((RowAVLDiskData) row).setNewNodes();
            systemUpdateIdentityValue(data);
            enforceRowConstraints(session, data);
            for (int i = 0; i < indexList.length; i++) {
                indexList[i].insert(null, store, row);
            }
        }
    } catch (Exception e) {
        int linenumber = cache == null ? 0 : ((TextCache) cache).getLineNumber();
        clearAllData(session);
        if (cache != null) {
            database.logger.closeTextCache(this);
            store.release();
        }
        // source and cache or have an empty source and null cache.
        throw Error.error(ErrorCode.TEXT_FILE, 0, new Object[] { new Integer(linenumber), e.getMessage() });
    }
    isConnected = true;
    isReadOnly = withReadOnlyData;
}
Also used : DataFileCache(org.hsqldb_voltpatches.persist.DataFileCache) TextCache(org.hsqldb_voltpatches.persist.TextCache) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 2 with DataFileCache

use of org.hsqldb_voltpatches.persist.DataFileCache in project voltdb by VoltDB.

the class DatabaseInformationFull method SYSTEM_CACHEINFO.

/**
     * Retrieves a <code>Table</code> object describing the current
     * state of all row caching objects for the accessible
     * tables defined within this database. <p>
     *
     * Currently, the row caching objects for which state is reported are: <p>
     *
     * <OL>
     * <LI> the system-wide <code>Cache</code> object used by CACHED tables.
     * <LI> any <code>TextCache</code> objects in use by [TEMP] TEXT tables.
     * </OL> <p>
     *
     * Each row is a cache object state description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * CACHE_FILE          CHARACTER_DATA   absolute path of cache data file
     * MAX_CACHE_SIZE      INTEGER   maximum allowable cached Row objects
     * MAX_CACHE_BYTE_SIZE INTEGER   maximum allowable size of cached Row objects
     * CACHE_LENGTH        INTEGER   number of data bytes currently cached
     * CACHE_SIZE          INTEGER   number of rows currently cached
     * FREE_BYTES          INTEGER   total bytes in available file allocation units
     * FREE_COUNT          INTEGER   total # of allocation units available
     * FREE_POS            INTEGER   largest file position allocated + 1
     * </pre> <p>
     *
     * <b>Notes:</b> <p>
     *
     * <code>TextCache</code> objects do not maintain a free list because
     * deleted rows are only marked deleted and never reused. As such, the
     * columns FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM, and
     * FREE_COUNT are always reported as zero for rows reporting on
     * <code>TextCache</code> objects. <p>
     *
     * Currently, CACHE_SIZE, FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM,
     * FREE_COUNT and FREE_POS are the only dynamically changing values.
     * All others are constant for the life of a cache object. In a future
     * release, other column values may also change over the life of a cache
     * object, as SQL syntax may eventually be introduced to allow runtime
     * modification of certain cache properties. <p>
     *
     * @return a description of the current state of all row caching
     *      objects associated with the accessible tables of the database
     */
Table SYSTEM_CACHEINFO() {
    Table t = sysTables[SYSTEM_CACHEINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_CACHEINFO]);
        // not null
        addColumn(t, "CACHE_FILE", CHARACTER_DATA);
        // not null
        addColumn(t, "MAX_CACHE_COUNT", CARDINAL_NUMBER);
        // not null
        addColumn(t, "MAX_CACHE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "CACHE_SIZE", CARDINAL_NUMBER);
        // not null
        addColumn(t, "CACHE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_COUNT", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_POS", CARDINAL_NUMBER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_CACHEINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    // column number mappings
    final int icache_file = 0;
    final int imax_cache_sz = 1;
    final int imax_cache_bytes = 2;
    final int icache_size = 3;
    final int icache_length = 4;
    final int ifree_bytes = 5;
    final int ifree_count = 6;
    final int ifree_pos = 7;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    DataFileCache cache = null;
    Object[] row;
    HashSet cacheSet;
    Iterator caches;
    Iterator tables;
    Table table;
    int iFreeBytes;
    int iLargestFreeItem;
    long lSmallestFreeItem;
    // Initialization
    cacheSet = new HashSet();
    // dynamic system tables are never cached
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    while (tables.hasNext()) {
        table = (Table) tables.next();
        PersistentStore currentStore = database.persistentStoreCollection.getStore(t);
        if (session.getGrantee().isFullyAccessibleByRole(table)) {
            if (currentStore != null) {
                cache = currentStore.getCache();
            }
            if (cache != null) {
                cacheSet.add(cache);
            }
        }
    }
    caches = cacheSet.iterator();
    // Do it.
    while (caches.hasNext()) {
        cache = (DataFileCache) caches.next();
        row = t.getEmptyRowData();
        row[icache_file] = FileUtil.getDefaultInstance().canonicalOrAbsolutePath(cache.getFileName());
        row[imax_cache_sz] = ValuePool.getInt(cache.capacity());
        row[imax_cache_bytes] = ValuePool.getLong(cache.bytesCapacity());
        row[icache_size] = ValuePool.getInt(cache.getCachedObjectCount());
        row[icache_length] = ValuePool.getLong(cache.getTotalCachedBlockSize());
        row[ifree_bytes] = ValuePool.getInt(cache.getTotalFreeBlockSize());
        row[ifree_count] = ValuePool.getInt(cache.getFreeBlockCount());
        row[ifree_pos] = ValuePool.getLong(cache.getFileFreePos());
        t.insertSys(store, row);
    }
    return t;
}
Also used : DataFileCache(org.hsqldb_voltpatches.persist.DataFileCache) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Aggregations

DataFileCache (org.hsqldb_voltpatches.persist.DataFileCache)2 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 Constraint (org.hsqldb_voltpatches.Constraint)1 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Table (org.hsqldb_voltpatches.Table)1 TextTable (org.hsqldb_voltpatches.TextTable)1 HashSet (org.hsqldb_voltpatches.lib.HashSet)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)1 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)1 TextCache (org.hsqldb_voltpatches.persist.TextCache)1