📄 storedpage.java
字号:
* slotEntrySize * - 16 - OVERFLOW_POINTER_SIZE; **/ protected int maxFieldSize; /** * The page header is a fixed size, 56 bytes, following are variables used * to access the fields in the header: * <p> * 1 byte boolean isOverflowPage is page an overflow page * 1 byte byte pageStatus page status (field in base page) * 8 bytes long pageVersion page version (field in base page) * 2 bytes ushort slotsInUse number of slots in slot offset table * 4 bytes integer nextId next record identifier * 4 bytes integer generation generation number of this page(FUTURE USE) * 4 bytes integer prevGeneration previous generation of page (FUTURE USE) * 8 bytes long bipLocation the location of the BI page (FUTURE USE) * 2 bytes ushort deletedRowCount number of deleted rows on page.(rel 2.0) * 2 bytes long spare for future use * 4 bytes long spare (encryption writes random bytes) * 8 bytes long spare for future use * 8 bytes long spare for future use * * Note that spare space has been guaranteed to be writen with "0", so * that future use of field should not either not use "0" as a valid data * item or pick 0 as a valid default value so that on the fly upgrade can * assume that 0 means field was never assigned. * **/ private boolean isOverflowPage; // is page an overflow page? private int slotsInUse; // number of slots in slot offset table. private int nextId; // next record identifier private int generation; // (Future Use) generation number of this page private int prevGeneration; // (Future Use) previous generation of page private long bipLocation; // (Future Use) the location of the BI page private int deletedRowCount; // number of deleted rows on page. /** * Is the header in the byte array out of date wrt the fields. * <p> * this field must be set to true whenever one of the above header fields * is modified. Ie any of (isOverflowPage, slotsInUse, nextId, generation, * prevGeneration, bipLocation, deletedRowCount) **/ private boolean headerOutOfDate; /** * holder for the checksum. **/ private CRC32 checksum; /** * Minimum space to reserve for record portion length of row. * <p> * minimumRecordSize is stored in the container handle. It is used to * reserved minimum space for recordPortionLength. Default is 1. To * get the value from the container handle: * myContainer.getMinimumRecordSize(); * * minimumRecordSize is the minimum user record size, excluding the space we * use for the record header and field headers. When a record is inserted, * it is stored in a space at least as large as the sum of the * minimumRecordSize and total header size. * * For example, * If minimumRecordSize is 10 bytes, * the user record is 7 bytes, * we used 5 bytes for record and field headers, * this record will take (10 + 5) bytes of space, extra 3 bytes is * put into reserve. * * If minimumRecordSize is 10 bytes, * user record is 17 bytes, * we used 5 bytes for record and field headers, * this record will take (17 + 5) bytes of space, no reserve space * here. * * minimumRecordSize is defined by user on per container basis. * The default for minimumRecordSize is set to 1. * **/ protected int minimumRecordSize; /** * scratch variable used to keep track of the total user size for the row. * the information is used by logRow to maintain minimumRecordSize * on Page. minimumRecordSize is only considered for main data pages, * therefore, the page must be latched during an insert operation. **/ private int userRowSize; /** * slot field and slot entry size. * <p> * The size of these fields is dependant on the page size. * These 2 variables should be set when pageSize is determined, and should * not be changed for that page. * * Each slot entry contains 3 fields (slotOffet, recordPortionLength and * reservedSpace) for the record the slot is pointing to. * slotFieldSize is the size for each of the slot field. * slotEntrySize is the total space used for a single slot entry. **/ private int slotFieldSize; private int slotEntrySize; /** * Offset of the first entry in the slot table. * <p> * Offset table is located at end of page, just before checksum. It * grows backward as an array from this point toward the middle of the * page. * <p> * slotTableOffsetToFirstEntry is the offset to the beginning of the * first entry (slot[0]) in the slot table. This allows the following * math to get to the offset of N'th entry in the slot table: * * offset of slot[N] = slotTableOffsetToFirstEntry + (N * slotEntrySize) **/ private int slotTableOffsetToFirstEntry; /** * Offset of the record length entry in the 1st slot table entry. * <p> * Offset table is located at end of page, just before checksum. It * grows backward as an array from this point toward the middle of the * page. The record length is stored as the second "field" of the * slot table entry. * <p> * slotTableOffsetToFirstRecordLengthField is the offset to the beginning * of the record length field in the first entry (slot[0]) in the slot * table. This allows the following * math to get to the record length field of N'th entry in the slot table: * * offset of record length of slot[N] slot entry = * slotTableOffsetToFirstRecordLengthField + (N * slotEntrySize) **/ private int slotTableOffsetToFirstRecordLengthField; /** * Offset of the reserved space length entry in the 1st slot table entry. * <p> * Offset table is located at end of page, just before checksum. It * grows backward as an array from this point toward the middle of the * page. The reserved space length is stored as the third "field" of the * slot table entry. * <p> * slotTableOffsetToFirstReservedSpaceField is the offset to the beginning * of the reserved space field in the first entry (slot[0]) in the slot * table. This allows the following * math to get to the reserved space field of N'th entry in the slot table: * * offset of reserved space of slot[N] slot entry = * slotTableOffsetToFirstReservedSpaceField + (N * slotEntrySize) **/ private int slotTableOffsetToFirstReservedSpaceField; /** * total usable space on a page. * <p> * This is the space not taken by page hdr, page table, and existing * slot entries/rows. **/ protected int totalSpace; // total usable space on a page // freeSpace and firstFreeByte are initliazed to a minimum value. protected int freeSpace = Integer.MIN_VALUE; // free space on the page private int firstFreeByte = Integer.MIN_VALUE; // 1st free byte on page /** * % of page to keep free for updates. * <p> * How much of a head page should be reserved as "free" so that the space * can be used by update which expands the row without needing to overflow * it. 1 means save 1% of the free space for expansion. **/ protected int spareSpace; /** * Scratch variable used when you need a overflowRecordHeader. Declared * globally so that object is only allocated once per page. **/ private StoredRecordHeader overflowRecordHeader; /** * Input streams used to read/write bytes to/from the page byte array. **/ protected ArrayInputStream rawDataIn; protected ArrayOutputStream rawDataOut; protected FormatIdOutputStream logicalDataOut; /************************************************************************** * Constructors for This class: ************************************************************************** */ /** * Simple no-arg constructor for StoredPage. **/ public StoredPage() { super(); } /************************************************************************** * Private/Protected methods of This class: ************************************************************************** */ /** * get scratch space for over flow record header. * <p> * * @exception StandardException Standard exception policy. **/ private StoredRecordHeader getOverFlowRecordHeader() throws StandardException { return( overflowRecordHeader != null ? overflowRecordHeader : (overflowRecordHeader = new StoredRecordHeader())); } /** * Initialize the StoredPage. * <p> * Initialize the object, ie. perform work normally perfomed in constructor. * Called by setIdentity() and createIdentity() - the Cacheable interfaces * which are used to move a page in/out of cache. * * @return void **/ protected void initialize() { super.initialize(); if (rawDataIn == null) { rawDataIn = new ArrayInputStream(); checksum = new CRC32(); } if (pageData != null) rawDataIn.setData(pageData); } /** * Create the output streams. * <p> * Create the output streams, these are created on demand * to avoid creating unrequired objects for pages that are * never modified during their lifetime in the cache. * <p> * * @return void * * @exception StandardException Standard exception policy. **/ private void createOutStreams() { rawDataOut = new ArrayOutputStream(); rawDataOut.setData(pageData); logicalDataOut = new FormatIdOutputStream(rawDataOut); } /** * Tie the logical output stream to a passed in OutputStream. * <p> * Tie the logical output stream to a passed in OutputStream with * no limit as to the number of bytes that can be written. **/ private void setOutputStream(OutputStream out) { if (rawDataOut == null) createOutStreams(); logicalDataOut.setOutput(out); } /** * Reset the logical output stream. * <p> * Reset the logical output stream (logicalDataOut) to be attached * to the page array stream as is the norm, no limits are placed * on any writes. * **/ private void resetOutputStream() { logicalDataOut.setOutput(rawDataOut); } /************************************************************************** * Protected Methods of CachedPage class: (create, read and write a page.) ************************************************************************** */ /** * use this passed in page buffer as this object's page data. * <p> * The page content may not have been read in from disk yet. * For pagesize smaller than 64K: * Size of the record offset stored in a slot (unsigned short) * Size of the record portion length stored in a slot (unsigned short) * Size of the record portion length stored in a slot (unsigned short) * For pagesize greater than 64K, but less than 2gig: * Size of the record offset stored in a slot (int) * Size of the record portion length stored in a slot (int) * Size of the record portion length stored in a slot (int) * <p> * * @param pageBuffer The array of bytes to use as the page buffer. **/ protected void usePageBuffer(byte[] pageBuffer) { pageData = pageBuffer; int pageSize = pageData.length; if (rawDataIn != null) rawDataIn.setData(pageData); initSpace(); if (pageSize >= 65536) slotFieldSize = LARGE_SLOT_SIZE; else slotFieldSize = SMALL_SLOT_SIZE; slotEntrySize = 3 * slotFieldSize; // offset of slot table entry[0] slotTableOffsetToFirstEntry = (pageSize - CHECKSUM_SIZE - slotEntrySize); // offset of record length field in slot table entry[0] slotTableOffsetToFirstRecordLengthField = slotTableOffsetToFirstEntry + slotFieldSize; // offset of reserved space field in slot table entry[0] slotTableOffsetToFirstReservedSpaceField = slotTableOffsetToFirstEntry + (2 * slotFieldSize); if (rawDataOut != null) rawDataOut.setData(pageData); } /** * Create a new StoredPage. * <p> * Make this object represent a new page (ie. a page that never existed * before, as opposed to reading in an existing page from disk). * <p> * * @param newIdentity The key describing page (segment,container,page). * @param args information stored about the page, once in the * container header and passed in through the array. * * @exception StandardException Standard exception policy. **/ protected void createPage( PageKey newIdentity, int[] args) throws StandardException { // arg[0] is the formatId of the page // arg[1] is whether to sync the page to disk or not int pageSize = args[2]; spareSpace = args[3]; minimumRecordSize = args[4]; setPageArray(pageSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -