Search in sources :

Example 6 with Page

use of org.h2.mvstore.Page in project h2database by h2database.

the class PageBtreeIndex method writeRow.

/**
 * Write a row to the data page at the given offset.
 *
 * @param data the data
 * @param offset the offset
 * @param onlyPosition whether only the position of the row is stored
 * @param row the row to write
 */
void writeRow(Data data, int offset, SearchRow row, boolean onlyPosition) {
    data.setPos(offset);
    data.writeVarLong(row.getKey());
    if (!onlyPosition) {
        for (Column col : columns) {
            int idx = col.getColumnId();
            data.writeValue(row.getValue(idx));
        }
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn)

Example 7 with Page

use of org.h2.mvstore.Page in project h2database by h2database.

the class PageBtreeIndex method readRow.

/**
 * Read a row from the data page at the given offset.
 *
 * @param data the data
 * @param offset the offset
 * @param onlyPosition whether only the position of the row is stored
 * @param needData whether the row data is required
 * @return the row
 */
SearchRow readRow(Data data, int offset, boolean onlyPosition, boolean needData) {
    synchronized (data) {
        data.setPos(offset);
        long key = data.readVarLong();
        if (onlyPosition) {
            if (needData) {
                return tableData.getRow(null, key);
            }
            SearchRow row = table.getTemplateSimpleRow(true);
            row.setKey(key);
            return row;
        }
        SearchRow row = table.getTemplateSimpleRow(columns.length == 1);
        row.setKey(key);
        for (Column col : columns) {
            int idx = col.getColumnId();
            row.setValue(idx, data.readValue());
        }
        return row;
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) SearchRow(org.h2.result.SearchRow)

Example 8 with Page

use of org.h2.mvstore.Page in project h2database by h2database.

the class PageBtreeNode method moveTo.

@Override
public void moveTo(Session session, int newPos) {
    PageStore store = index.getPageStore();
    store.logUndo(this, data);
    PageBtreeNode p2 = PageBtreeNode.create(index, newPos, parentPageId);
    readAllRows();
    p2.rowCountStored = rowCountStored;
    p2.rowCount = rowCount;
    p2.childPageIds = childPageIds;
    p2.rows = rows;
    p2.entryCount = entryCount;
    p2.offsets = offsets;
    p2.onlyPosition = onlyPosition;
    p2.parentPageId = parentPageId;
    p2.start = start;
    store.update(p2);
    if (parentPageId == ROOT) {
        index.setRootPageId(session, newPos);
    } else {
        Page p = store.getPage(parentPageId);
        if (!(p instanceof PageBtreeNode)) {
            throw DbException.throwInternalError();
        }
        PageBtreeNode n = (PageBtreeNode) p;
        n.moveChild(getPos(), newPos);
    }
    for (int i = 0; i < entryCount + 1; i++) {
        int child = childPageIds[i];
        PageBtree p = index.getPage(child);
        p.setParentPageId(newPos);
        store.update(p);
    }
    store.free(getPos());
}
Also used : PageStore(org.h2.store.PageStore) Page(org.h2.store.Page)

Example 9 with Page

use of org.h2.mvstore.Page in project h2database by h2database.

the class PageBtreeNode method remove.

@Override
SearchRow remove(SearchRow row) {
    int at = find(row, false, false, true);
    // merge is not implemented to allow concurrent usage
    // TODO maybe implement merge
    PageBtree page = index.getPage(childPageIds[at]);
    SearchRow last = page.remove(row);
    index.getPageStore().logUndo(this, data);
    updateRowCount(-1);
    written = false;
    changeCount = index.getPageStore().getChangeCount();
    if (last == null) {
        // the last row didn't change - nothing to do
        return null;
    } else if (last == row) {
        // this child is now empty
        index.getPageStore().free(page.getPos());
        if (entryCount < 1) {
            // no more children - this page is empty as well
            return row;
        }
        if (at == entryCount) {
            // removing the last child
            last = getRow(at - 1);
        } else {
            last = null;
        }
        removeChild(at);
        index.getPageStore().update(this);
        return last;
    }
    // the last row is in the last child
    if (at == entryCount) {
        return last;
    }
    int child = childPageIds[at];
    removeChild(at);
    // TODO this can mean only the position is now stored
    // should split at the next possible moment
    addChild(at, child, last);
    // remove and add swapped two children, fix that
    int temp = childPageIds[at];
    childPageIds[at] = childPageIds[at + 1];
    childPageIds[at + 1] = temp;
    index.getPageStore().update(this);
    return null;
}
Also used : SearchRow(org.h2.result.SearchRow)

Example 10 with Page

use of org.h2.mvstore.Page in project h2database by h2database.

the class WebThread method process.

@SuppressWarnings("unchecked")
private boolean process() throws IOException {
    boolean keepAlive = false;
    String head = readHeaderLine();
    if (head.startsWith("GET ") || head.startsWith("POST ")) {
        int begin = head.indexOf('/'), end = head.lastIndexOf(' ');
        String file;
        if (begin < 0 || end < begin) {
            file = "";
        } else {
            file = head.substring(begin + 1, end).trim();
        }
        trace(head + ": " + file);
        file = getAllowedFile(file);
        attributes = new Properties();
        int paramIndex = file.indexOf('?');
        session = null;
        if (paramIndex >= 0) {
            String attrib = file.substring(paramIndex + 1);
            parseAttributes(attrib);
            String sessionId = attributes.getProperty("jsessionid");
            file = file.substring(0, paramIndex);
            session = server.getSession(sessionId);
        }
        keepAlive = parseHeader();
        String hostAddr = socket.getInetAddress().getHostAddress();
        file = processRequest(file, hostAddr);
        if (file.length() == 0) {
            // asynchronous request
            return true;
        }
        String message;
        byte[] bytes;
        if (cache && ifModifiedSince != null && ifModifiedSince.equals(server.getStartDateTime())) {
            bytes = null;
            message = "HTTP/1.1 304 Not Modified\r\n";
        } else {
            bytes = server.getFile(file);
            if (bytes == null) {
                message = "HTTP/1.1 404 Not Found\r\n";
                bytes = ("File not found: " + file).getBytes(StandardCharsets.UTF_8);
                message += "Content-Length: " + bytes.length + "\r\n";
            } else {
                if (session != null && file.endsWith(".jsp")) {
                    String page = new String(bytes, StandardCharsets.UTF_8);
                    if (SysProperties.CONSOLE_STREAM) {
                        Iterator<String> it = (Iterator<String>) session.map.remove("chunks");
                        if (it != null) {
                            message = "HTTP/1.1 200 OK\r\n";
                            message += "Content-Type: " + mimeType + "\r\n";
                            message += "Cache-Control: no-cache\r\n";
                            message += "Transfer-Encoding: chunked\r\n";
                            message += "\r\n";
                            trace(message);
                            output.write(message.getBytes());
                            while (it.hasNext()) {
                                String s = it.next();
                                s = PageParser.parse(s, session.map);
                                bytes = s.getBytes(StandardCharsets.UTF_8);
                                if (bytes.length == 0) {
                                    continue;
                                }
                                output.write(Integer.toHexString(bytes.length).getBytes());
                                output.write("\r\n".getBytes());
                                output.write(bytes);
                                output.write("\r\n".getBytes());
                                output.flush();
                            }
                            output.write("0\r\n\r\n".getBytes());
                            output.flush();
                            return keepAlive;
                        }
                    }
                    page = PageParser.parse(page, session.map);
                    bytes = page.getBytes(StandardCharsets.UTF_8);
                }
                message = "HTTP/1.1 200 OK\r\n";
                message += "Content-Type: " + mimeType + "\r\n";
                if (!cache) {
                    message += "Cache-Control: no-cache\r\n";
                } else {
                    message += "Cache-Control: max-age=10\r\n";
                    message += "Last-Modified: " + server.getStartDateTime() + "\r\n";
                }
                message += "Content-Length: " + bytes.length + "\r\n";
            }
        }
        message += "\r\n";
        trace(message);
        output.write(message.getBytes());
        if (bytes != null) {
            output.write(bytes);
        }
        output.flush();
    }
    return keepAlive;
}
Also used : Iterator(java.util.Iterator) Properties(java.util.Properties) SysProperties(org.h2.engine.SysProperties)

Aggregations

CreateTableData (org.h2.command.ddl.CreateTableData)9 Value (org.h2.value.Value)8 Data (org.h2.store.Data)7 Column (org.h2.table.Column)6 Page (org.h2.mvstore.Page)5 IndexColumn (org.h2.table.IndexColumn)5 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)4 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)4 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)4 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)4 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)4 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)4 GridCacheSqlQuery (org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery)4 Row (org.h2.result.Row)4 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 CRC32 (java.util.zip.CRC32)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3