Search in sources :

Example 1 with MetaIndex

use of org.h2.index.MetaIndex in project h2database by h2database.

the class PageStore method openMetaIndex.

private void openMetaIndex() {
    CreateTableData data = new CreateTableData();
    ArrayList<Column> cols = data.columns;
    cols.add(new Column("ID", Value.INT));
    cols.add(new Column("TYPE", Value.INT));
    cols.add(new Column("PARENT", Value.INT));
    cols.add(new Column("HEAD", Value.INT));
    cols.add(new Column("OPTIONS", Value.STRING));
    cols.add(new Column("COLUMNS", Value.STRING));
    metaSchema = new Schema(database, 0, "", null, true);
    data.schema = metaSchema;
    data.tableName = "PAGE_INDEX";
    data.id = META_TABLE_ID;
    data.temporary = false;
    data.persistData = true;
    data.persistIndexes = true;
    data.create = false;
    data.session = pageStoreSession;
    metaTable = new RegularTable(data);
    metaIndex = (PageDataIndex) metaTable.getScanIndex(pageStoreSession);
    metaObjects.clear();
    metaObjects.put(-1, metaIndex);
}
Also used : IndexColumn(org.h2.table.IndexColumn) Column(org.h2.table.Column) Schema(org.h2.schema.Schema) RegularTable(org.h2.table.RegularTable) CreateTableData(org.h2.command.ddl.CreateTableData)

Example 2 with MetaIndex

use of org.h2.index.MetaIndex in project h2database by h2database.

the class MetaTable method getIndexes.

@Override
public ArrayList<Index> getIndexes() {
    ArrayList<Index> list = New.arrayList();
    if (metaIndex == null) {
        return list;
    }
    list.add(new MetaIndex(this, IndexColumn.wrap(columns), true));
    // TODO re-use the index
    list.add(metaIndex);
    return list;
}
Also used : MetaIndex(org.h2.index.MetaIndex) Index(org.h2.index.Index) MultiVersionIndex(org.h2.index.MultiVersionIndex) MetaIndex(org.h2.index.MetaIndex)

Example 3 with MetaIndex

use of org.h2.index.MetaIndex in project h2database by h2database.

the class PageStore method recover.

/**
 * Run recovery.
 *
 * @return whether the transaction log was empty
 */
private boolean recover() {
    trace.debug("log recover");
    recoveryRunning = true;
    boolean isEmpty = true;
    isEmpty &= log.recover(PageLog.RECOVERY_STAGE_UNDO);
    if (reservedPages != null) {
        for (int r : reservedPages.keySet()) {
            if (trace.isDebugEnabled()) {
                trace.debug("reserve " + r);
            }
            allocatePage(r);
        }
    }
    isEmpty &= log.recover(PageLog.RECOVERY_STAGE_ALLOCATE);
    openMetaIndex();
    readMetaData();
    isEmpty &= log.recover(PageLog.RECOVERY_STAGE_REDO);
    boolean setReadOnly = false;
    if (!database.isReadOnly()) {
        if (log.getInDoubtTransactions().isEmpty()) {
            log.recoverEnd();
            int firstUncommittedSection = getFirstUncommittedSection();
            log.removeUntil(firstUncommittedSection);
        } else {
            setReadOnly = true;
        }
    }
    PageDataIndex systemTable = (PageDataIndex) metaObjects.get(0);
    isNew = systemTable == null;
    for (PageIndex index : metaObjects.values()) {
        if (index.getTable().isTemporary()) {
            // temporary indexes are removed after opening
            if (tempObjects == null) {
                tempObjects = new HashMap<>();
            }
            tempObjects.put(index.getId(), index);
        } else {
            index.close(pageStoreSession);
        }
    }
    allocatePage(PAGE_ID_META_ROOT);
    writeIndexRowCounts();
    recoveryRunning = false;
    reservedPages = null;
    writeBack();
    // clear the cache because it contains pages with closed indexes
    cache.clear();
    freeLists.clear();
    metaObjects.clear();
    metaObjects.put(-1, metaIndex);
    if (setReadOnly) {
        database.setReadOnly(true);
    }
    trace.debug("log recover done");
    return isEmpty;
}
Also used : PageDataIndex(org.h2.index.PageDataIndex) PageIndex(org.h2.index.PageIndex)

Example 4 with MetaIndex

use of org.h2.index.MetaIndex in project h2database by h2database.

the class PageStore method removeOldTempIndexes.

private void removeOldTempIndexes() {
    if (tempObjects != null) {
        metaObjects.putAll(tempObjects);
        for (PageIndex index : tempObjects.values()) {
            if (index.getTable().isTemporary()) {
                index.truncate(pageStoreSession);
                index.remove(pageStoreSession);
            }
        }
        pageStoreSession.commit(true);
        tempObjects = null;
    }
    metaObjects.clear();
    metaObjects.put(-1, metaIndex);
}
Also used : PageIndex(org.h2.index.PageIndex)

Aggregations

PageIndex (org.h2.index.PageIndex)2 CreateTableData (org.h2.command.ddl.CreateTableData)1 Index (org.h2.index.Index)1 MetaIndex (org.h2.index.MetaIndex)1 MultiVersionIndex (org.h2.index.MultiVersionIndex)1 PageDataIndex (org.h2.index.PageDataIndex)1 Schema (org.h2.schema.Schema)1 Column (org.h2.table.Column)1 IndexColumn (org.h2.table.IndexColumn)1 RegularTable (org.h2.table.RegularTable)1