use of org.h2.store.Page in project h2database by h2database.
the class PageStore method readStaticHeader.
private void readStaticHeader() {
file.seek(FileStore.HEADER_LENGTH);
Data page = Data.create(database, new byte[PAGE_SIZE_MIN - FileStore.HEADER_LENGTH]);
file.readFully(page.getBytes(), 0, PAGE_SIZE_MIN - FileStore.HEADER_LENGTH);
readCount++;
setPageSize(page.readInt());
int writeVersion = page.readByte();
int readVersion = page.readByte();
if (readVersion > READ_VERSION) {
throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1, fileName);
}
if (writeVersion > WRITE_VERSION) {
close();
database.setReadOnly(true);
accessMode = "r";
file = database.openFile(fileName, accessMode, true);
}
}
use of org.h2.store.Page in project h2database by h2database.
the class PageBtreeIndex method getRowSize.
/**
* Get the size of a row (only the part that is stored in the index).
*
* @param dummy a dummy data page to calculate the size
* @param row the row
* @param onlyPosition whether only the position of the row is stored
* @return the number of bytes
*/
int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) {
int rowsize = Data.getVarLongLen(row.getKey());
if (!onlyPosition) {
for (Column col : columns) {
Value v = row.getValue(col.getColumnId());
rowsize += dummy.getValueLen(v);
}
}
return rowsize;
}
use of org.h2.store.Page in project h2database by h2database.
the class PageBtreeIndex method getPage.
/**
* Read the given page.
*
* @param id the page id
* @return the page
*/
PageBtree getPage(int id) {
Page p = store.getPage(id);
if (p == null) {
PageBtreeLeaf empty = PageBtreeLeaf.create(this, id, PageBtree.ROOT);
// could have been created before, but never committed
store.logUndo(empty, null);
store.update(empty);
return empty;
} else if (!(p instanceof PageBtree)) {
throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "" + p);
}
return (PageBtree) p;
}
use of org.h2.store.Page in project h2database by h2database.
the class PageBtreeLeaf method remove.
@Override
SearchRow remove(SearchRow row) {
int at = find(row, false, false, true);
SearchRow delete = getRow(at);
if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row);
}
index.getPageStore().logUndo(this, data);
if (entryCount == 1) {
// the page is now empty
return row;
}
removeRow(at);
memoryChange();
index.getPageStore().update(this);
if (at == entryCount) {
// the last row changed
return getRow(at - 1);
}
// the last row didn't change
return null;
}
use of org.h2.store.Page in project h2database by h2database.
the class PageBtreeNode method addRowTry.
@Override
int addRowTry(SearchRow row) {
while (true) {
int x = find(row, false, true, true);
PageBtree page = index.getPage(childPageIds[x]);
int splitPoint = page.addRowTry(row);
if (splitPoint == -1) {
break;
}
SearchRow pivot = page.getRow(splitPoint - 1);
index.getPageStore().logUndo(this, data);
int splitPoint2 = addChildTry(pivot);
if (splitPoint2 != -1) {
return splitPoint2;
}
PageBtree page2 = page.split(splitPoint);
readAllRows();
addChild(x, page2.getPos(), pivot);
index.getPageStore().update(page);
index.getPageStore().update(page2);
index.getPageStore().update(this);
}
updateRowCount(1);
written = false;
changeCount = index.getPageStore().getChangeCount();
return -1;
}
Aggregations