/** * Read a page. * * @param pos the page id * @return the page */ public synchronized Data readPage(int pos) { Data page = createData(); readPage(pos, page); return page; }
private Data getBuffer() { if (writeBuffer.length() == 0) { return writeBuffer; } return store.createData(); }
PageLog(PageStore store) { this.store = store; dataBuffer = store.createData(); trace = store.getTrace(); compress = new CompressLZF(); compressBuffer = new byte[store.getPageSize() * 2]; }
/** * Set the page size. The size must be a power of two. This method must be * called before opening. * * @param size the page size */ public void setPageSize(int size) { if (size < PAGE_SIZE_MIN || size > PAGE_SIZE_MAX) { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, fileName + " pageSize: " + size); } boolean good = false; int shift = 0; for (int i = 1; i <= size;) { if (size == i) { good = true; break; } shift++; i += i; } if (!good) { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, fileName); } pageSize = size; emptyPage = createData(); pageSizeShift = shift; }
private void readVariableHeader() { Data page = createData(); for (int i = 1;; i++) { if (i == 3) { throw DbException.get( ErrorCode.FILE_CORRUPTED_1, fileName); } page.reset(); readPage(i, page); CRC32 crc = new CRC32(); crc.update(page.getBytes(), 4, pageSize - 4); int expected = (int) crc.getValue(); int got = page.readInt(); if (expected == got) { writeCountBase = page.readLong(); logKey = page.readInt(); logFirstTrunkPage = page.readInt(); logFirstDataPage = page.readInt(); break; } } }
@Override public void write() { data = store.createData(); data.writeByte((byte) Page.TYPE_FREE_LIST); data.writeShortInt(0); for (int i = 0; i < pageCount; i += 8) { data.writeByte((byte) used.getByte(i)); } store.writePage(getPos(), data); }
/** * Write the header data. */ void initWrite() { data = store.createData(); data.writeByte((byte) Page.TYPE_STREAM_DATA); data.writeShortInt(0); data.writeInt(trunk); data.writeInt(logKey); remaining = store.getPageSize() - data.length(); }
/** * Add a page to the free list. * * @param pageId the page id * @param undo if the undo record must have been written */ void free(int pageId, boolean undo) { if (trace.isDebugEnabled()) { // trace.debug("free " + pageId + " " + undo); } cache.remove(pageId); if (SysProperties.CHECK && !recoveryRunning && undo) { // ensure the undo entry is already written if (logMode != LOG_MODE_OFF) { log.addUndo(pageId, null); } } freePage(pageId); if (recoveryRunning) { writePage(pageId, createData()); if (reservedPages != null && reservedPages.containsKey(pageId)) { // re-allocate the page if it is used later on again int latestPos = reservedPages.get(pageId); if (latestPos > log.getLogPos()) { allocatePage(pageId); } } } }
/** * Open the log for writing. For an existing database, the recovery * must be run first. * * @param newFirstTrunkPage the first trunk page * @param atEnd whether only pages at the end of the file should be used */ void openForWriting(int newFirstTrunkPage, boolean atEnd) { trace.debug("log openForWriting firstPage: " + newFirstTrunkPage); this.firstTrunkPage = newFirstTrunkPage; logKey++; pageOut = new PageOutputStream(store, newFirstTrunkPage, undoAll, logKey, atEnd); pageOut.reserve(1); // pageBuffer = new BufferedOutputStream(pageOut, 8 * 1024); store.setLogFirstPage(logKey, newFirstTrunkPage, pageOut.getCurrentDataPageId()); writeBuffer = store.createData(); }
/** * Create a new page. * * @param index the index * @param pageId the page id * @param parentPageId the parent * @return the page */ static PageDataNode create(PageDataIndex index, int pageId, int parentPageId) { PageDataNode p = new PageDataNode(index, pageId, index.getPageStore().createData()); index.getPageStore().logUndo(p, null); p.parentPageId = parentPageId; p.writeHead(); // 4 bytes for the rightmost child page id p.length = p.data.length() + 4; return p; }
/** * Create a new page. * * @param index the index * @param pageId the page id * @param parentPageId the parent * @return the page */ static PageBtreeLeaf create(PageBtreeIndex index, int pageId, int parentPageId) { PageBtreeLeaf p = new PageBtreeLeaf(index, pageId, index.getPageStore() .createData()); index.getPageStore().logUndo(p, null); p.rows = SearchRow.EMPTY_ARRAY; p.parentPageId = parentPageId; p.writeHead(); p.start = p.data.length(); return p; }
/** * Create a new b-tree node page. * * @param index the index * @param pageId the page id * @param parentPageId the parent page id * @return the page */ static PageBtreeNode create(PageBtreeIndex index, int pageId, int parentPageId) { PageBtreeNode p = new PageBtreeNode(index, pageId, index.getPageStore() .createData()); index.getPageStore().logUndo(p, null); p.parentPageId = parentPageId; p.writeHead(); // 4 bytes for the rightmost child page id p.start = p.data.length() + 4; p.rows = SearchRow.EMPTY_ARRAY; if (p.pageStoreInternalCount) { p.rowCount = 0; } return p; }
private void writeVariableHeader() { trace.debug("writeVariableHeader"); if (logMode == LOG_MODE_SYNC) { file.sync(); } Data page = createData(); page.writeInt(0); page.writeLong(getWriteCountTotal()); page.writeInt(logKey); page.writeInt(logFirstTrunkPage); page.writeInt(logFirstDataPage); CRC32 crc = new CRC32(); crc.update(page.getBytes(), 4, pageSize - 4); page.setInt(0, (int) crc.getValue()); file.seek(pageSize); file.write(page.getBytes(), 0, pageSize); file.seek(pageSize + pageSize); file.write(page.getBytes(), 0, pageSize); // don't increment the write counter, because it was just written }
@Override public void write() { data = store.createData(); data.writeByte((byte) Page.TYPE_STREAM_TRUNK); data.writeShortInt(0); data.writeInt(parent); data.writeInt(logKey); data.writeInt(nextTrunk); data.writeShortInt(pageCount); for (int i = 0; i < pageCount; i++) { data.writeInt(pageIds[i]); } store.writePage(getPos(), data); }
Data buff = store.createData(); int pageSize = store.getPageSize(); int offset = offsets[at];
/** * Create a new page. * * @param index the index * @param pageId the page id * @param parentPageId the parent * @return the page */ static PageDataLeaf create(PageDataIndex index, int pageId, int parentPageId) { PageDataLeaf p = new PageDataLeaf(index, pageId, index.getPageStore() .createData()); index.getPageStore().logUndo(p, null); p.rows = Row.EMPTY_ARRAY; p.parentPageId = parentPageId; p.columnCount = index.getTable().getColumns().length; p.writeHead(); p.start = p.data.length(); return p; }
/** * Set the state of an in-doubt transaction. * * @param sessionId the session * @param pageId the page where the commit was prepared * @param commit whether the transaction should be committed */ void setInDoubtTransactionState(int sessionId, int pageId, boolean commit) { PageStreamData d = (PageStreamData) store.getPage(pageId); d.initWrite(); Data buff = store.createData(); buff.writeByte((byte) (commit ? COMMIT : ROLLBACK)); buff.writeVarInt(sessionId); byte[] bytes = buff.getBytes(); d.write(bytes, 0, bytes.length); bytes = new byte[d.getRemaining()]; d.write(bytes, 0, bytes.length); d.write(); }
writePage(rootPageId, createData()); allocatePage(rootPageId);
int type, int parentPageId, int next, Data all, int offset, int size) { Data data = store.createData(); PageDataOverflow p = new PageDataOverflow(store, page, data); store.logUndo(p, null);
rowRef = new SoftReference<>(r); rows[0] = null; Data all = index.getPageStore().createData(); all.checkCapacity(data.length()); all.write(data.getBytes(), 0, data.length());