You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by mi...@apache.org on 2010/06/29 20:17:11 UTC
svn commit: r959060 [2/3] - in
/db/derby/code/trunk/java/engine/org/apache/derby:
iapi/store/raw/RawStoreFactory.java impl/store/raw/data/StoredPage.java
impl/store/raw/data/StoredRecordHeader.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java?rev=959060&r1=959059&r2=959060&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java Tue Jun 29 18:17:11 2010
@@ -64,11 +64,11 @@ import org.apache.derby.iapi.util.ByteAr
/**
- StoredPage is a sub class of CachedPage that stores page data in a
- fixed size byte array and is designed to be written out to a file
- through a DataInput/DataOutput interface. A StoredPage can exist
- in its clean or dirty state without the FileContainer it was created
- from being in memory.
+ StoredPage is a sub class of CachedPage that stores page data in a
+ fixed size byte array and is designed to be written out to a file
+ through a DataInput/DataOutput interface. A StoredPage can exist
+ in its clean or dirty state without the FileContainer it was created
+ from being in memory.
<P><B>Page Format</B><BR>
The page is broken into five sections
@@ -82,21 +82,21 @@ import org.apache.derby.iapi.util.ByteAr
<BR><B>Page Header</B><BR>
The page header is a fixed size, 56 bytes
<PRE>
- 1 byte boolean is page an overflow page
- 1 byte byte page status (a field maintained in base page)
- 8 bytes long pageVersion (a field maintained in base page)
- 2 bytes unsigned short number of slots in slot offset table
- 4 bytes integer next record identifier
- 4 bytes integer generation number of this page (Future Use)
- 4 bytes integer previous generation of this page (Future Use)
- 8 bytes bipLocation the location of the beforeimage page (Future Use)
- 2 bytes unsigned short number of deleted rows on page. (new release 2.0)
+ 1 byte boolean is page an overflow page
+ 1 byte byte page status (a field maintained in base page)
+ 8 bytes long pageVersion (a field maintained in base page)
+ 2 bytes unsigned short number of slots in slot offset table
+ 4 bytes integer next record identifier
+ 4 bytes integer generation number of this page (Future Use)
+ 4 bytes integer previous generation of this page (Future Use)
+ 8 bytes bipLocation the location of the beforeimage page (Future Use)
+ 2 bytes unsigned short number of deleted rows on page. (new release 2.0)
2 bytes unsigned short % of the page to keep free for updates
- 2 bytes short spare for future use
- 4 bytes long spare for future use (encryption uses to write
+ 2 bytes short spare for future use
+ 4 bytes long spare for future use (encryption uses to write
random bytes here).
- 8 bytes long spare for future use
- 8 bytes long spare for future use
+ 8 bytes long spare for future use
+ 8 bytes long spare for future use
</PRE>
@@ -112,17 +112,17 @@ import org.apache.derby.iapi.util.ByteAr
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
+ 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
+ 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.
@@ -137,10 +137,10 @@ import org.apache.derby.iapi.util.ByteAr
Record Header format is defined in the StoredRecordHeader class.
-<PRE>
+<PRE>
<BR><B>Fields</B>
- 1 byte Boolean - is null, if true no more data follows.
+ 1 byte Boolean - is null, if true no more data follows.
4 bytes Integer - length of field that follows (excludes these four bytes).
StoredPage will use the static method provided by StoredFieldHeader
@@ -150,37 +150,37 @@ import org.apache.derby.iapi.util.ByteAr
<data>
</PRE>
- <BR><B>Slot Offset Table</B><BR>
- The slot offset table is a table of 6 or 12 bytes per record, depending on
+ <BR><B>Slot Offset Table</B><BR>
+ The slot offset table is a table of 6 or 12 bytes per record, depending on
the pageSize being less or greater than 64K:
- 2 bytes (unsigned short) or 4 bytes (int) page offset for the record that
+ 2 bytes (unsigned short) or 4 bytes (int) page offset for the record that
is assigned to the slot, and 2 bytes (unsigned short) or 4 bytes (int)
for the length of the record on this page.
- 2 bytes (unsigned short) or 4 bytes (int) for the length of the reserved
+ 2 bytes (unsigned short) or 4 bytes (int) for the length of the reserved
number of bytes for this record on this page.
- First slot is slot 0. The slot table grows backwards. Slots are never
+ First slot is slot 0. The slot table grows backwards. Slots are never
left empty.
- <BR><B>Checksum</B><BR>
- 8 bytes of a java.util.zip.CRC32 checksum of the entire's page contents
+ <BR><B>Checksum</B><BR>
+ 8 bytes of a java.util.zip.CRC32 checksum of the entire's page contents
without the 8 bytes representing the checksum.
- <P><B>Page Access</B>
- The page data is accessed in this class by one of three methods.
- <OL>
- <LI>As a byte array using pageData (field in cachedPage). This is the
+ <P><B>Page Access</B>
+ The page data is accessed in this class by one of three methods.
+ <OL>
+ <LI>As a byte array using pageData (field in cachedPage). This is the
fastest.
- <LI>As an ArrayInputStream (rawDataIn) and ArrayOutputStream (rawDataOut),
- this is used to set limits on any one reading the page logically.
- <LI>Logically through rawDataIn (ArrayInputStream) and
+ <LI>As an ArrayInputStream (rawDataIn) and ArrayOutputStream (rawDataOut),
+ this is used to set limits on any one reading the page logically.
+ <LI>Logically through rawDataIn (ArrayInputStream) and
logicalDataOut (FormatIdOutputStream), this provides the methods to write
logical data (e.g. booleans and integers etc.) and the ObjectInput
- and ObjectOutput interfaces for DataValueDescriptor's. These logical
+ and ObjectOutput interfaces for DataValueDescriptor's. These logical
streams are constructed using the array streams.
- </OL>
+ </OL>
- @see java.util.zip.CRC32
- @see ArrayInputStream
- @see ArrayOutputStream
+ @see java.util.zip.CRC32
+ @see ArrayInputStream
+ @see ArrayOutputStream
**/
public class StoredPage extends CachedPage
@@ -190,20 +190,20 @@ public class StoredPage extends CachedPa
**************************************************************************
*/
- /*
- * typed format
- */
+ /*
+ * typed format
+ */
- public static final int FORMAT_NUMBER =
+ public static final int FORMAT_NUMBER =
StoredFormatIds.RAW_STORE_STORED_PAGE;
/**
* Return my format identifier.
**/
- public int getTypeFormatId()
- {
- return StoredFormatIds.RAW_STORE_STORED_PAGE;
- }
+ public int getTypeFormatId()
+ {
+ return StoredFormatIds.RAW_STORE_STORED_PAGE;
+ }
/**
@@ -226,40 +226,40 @@ public class StoredPage extends CachedPa
/**
* Start of page, formatId must fit in 4 bytes.
* <p>
- * where the page header starts - page format is mandated by cached page
+ * where the page header starts - page format is mandated by cached page
**/
- protected static final int PAGE_HEADER_OFFSET = PAGE_FORMAT_ID_SIZE;
+ protected static final int PAGE_HEADER_OFFSET = PAGE_FORMAT_ID_SIZE;
/**
* Fixed size of the page header
**/
- protected static final int PAGE_HEADER_SIZE = 56;
+ protected static final int PAGE_HEADER_SIZE = 56;
- /**
- Start of the record storage area
- */
+ /**
+ Start of the record storage area
+ */
/**
* Start of the record storage area.
* <p>
* Note: a subclass may change the start of the record storage area.
* Don't always count on this number.
**/
- protected static final int RECORD_SPACE_OFFSET =
+ protected static final int RECORD_SPACE_OFFSET =
PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE;
/**
* offset of the page version number
**/
- protected static final int PAGE_VERSION_OFFSET = PAGE_HEADER_OFFSET + 2;
+ protected static final int PAGE_VERSION_OFFSET = PAGE_HEADER_OFFSET + 2;
/**
* SMALL_SLOT_SIZE are for pages smaller than 64K,
* LARGE_SLOT_SIZE is for pages bigger than 64K.
**/
- protected static final int SMALL_SLOT_SIZE = 2;
- protected static final int LARGE_SLOT_SIZE = 4;
+ protected static final int SMALL_SLOT_SIZE = 2;
+ protected static final int LARGE_SLOT_SIZE = 4;
/**
* Size of the checksum stored on the page.
@@ -268,7 +268,7 @@ public class StoredPage extends CachedPa
* grows backward up the page starting at the end of the page just before
* the checksum.
**/
- protected static final int CHECKSUM_SIZE = 8;
+ protected static final int CHECKSUM_SIZE = 8;
/**
* OVERFLOW_POINTER_SIZE - Number of bytes to reserve for overflow pointer
@@ -284,7 +284,7 @@ public class StoredPage extends CachedPa
* write the over flow pointer.
*
**/
- protected static final int OVERFLOW_POINTER_SIZE = 12;
+ protected static final int OVERFLOW_POINTER_SIZE = 12;
/**
* OVERFLOW_PTR_FIELD_SIZE - Number of bytes of an overflow field
@@ -296,20 +296,20 @@ public class StoredPage extends CachedPa
*
* The calcualtion is:
*
- * OVERFLOW_PTR_FIELD_SIZE =
+ * OVERFLOW_PTR_FIELD_SIZE =
* OVERFLOW_POINTER_SIZE +
* sizeof(status byte) +
* sizeof(field length field for a field which is just an overflow ptr)
*
*
**/
- protected static final int OVERFLOW_PTR_FIELD_SIZE =
+ protected static final int OVERFLOW_PTR_FIELD_SIZE =
OVERFLOW_POINTER_SIZE + 1 + 1;
/**
* In memory buffer used as scratch space for streaming columns.
**/
- ByteHolder bh = null;
+ ByteHolder bh = null;
/**************************************************************************
* Fields of the class
@@ -322,15 +322,15 @@ public class StoredPage extends CachedPa
* <p>
* Action taken in this routine is determined by the kind of column as
* specified in the columnFlag:
- * COLUMN_NONE - the column is insignificant
+ * COLUMN_NONE - the column is insignificant
* COLUMN_FIRST - this is the first column in a logRow() call
* COLUMN_LONG - this is a known long column, therefore we will
* store part of the column on the current page and
* overflow the rest if necessary.
**/
- protected static final int COLUMN_NONE = 0;
- protected static final int COLUMN_FIRST = 1;
- protected static final int COLUMN_LONG = 2;
+ protected static final int COLUMN_NONE = 0;
+ protected static final int COLUMN_FIRST = 1;
+ protected static final int COLUMN_LONG = 2;
/**
@@ -352,18 +352,18 @@ public class StoredPage extends CachedPa
* 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)
+ * 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
+ * 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
@@ -371,13 +371,13 @@ public class StoredPage extends CachedPa
* 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.
+ 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.
@@ -386,12 +386,12 @@ public class StoredPage extends CachedPa
* is modified. Ie any of (isOverflowPage, slotsInUse, nextId, generation,
* prevGeneration, bipLocation, deletedRowCount)
**/
- private boolean headerOutOfDate;
+ private boolean headerOutOfDate;
/**
* holder for the checksum.
**/
- private CRC32 checksum;
+ private CRC32 checksum;
/**
* Minimum space to reserve for record portion length of row.
@@ -423,7 +423,7 @@ public class StoredPage extends CachedPa
* The default for minimumRecordSize is set to 1.
*
**/
- protected int minimumRecordSize;
+ protected int minimumRecordSize;
/**
* scratch variable used to keep track of the total user size for the row.
@@ -431,8 +431,8 @@ public class StoredPage extends CachedPa
* on Page. minimumRecordSize is only considered for main data pages,
* therefore, the page must be latched during an insert operation.
**/
- private int userRowSize;
-
+ private int userRowSize;
+
/**
* slot field and slot entry size.
* <p>
@@ -445,8 +445,8 @@ public class StoredPage extends CachedPa
* 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;
+ private int slotFieldSize;
+ private int slotEntrySize;
/**
* Offset of the first entry in the slot table.
@@ -461,7 +461,7 @@ public class StoredPage extends CachedPa
*
* offset of slot[N] = slotTableOffsetToFirstEntry + (N * slotEntrySize)
**/
- private int slotTableOffsetToFirstEntry;
+ private int slotTableOffsetToFirstEntry;
/**
* Offset of the record length entry in the 1st slot table entry.
@@ -479,7 +479,7 @@ public class StoredPage extends CachedPa
* offset of record length of slot[N] slot entry =
* slotTableOffsetToFirstRecordLengthField + (N * slotEntrySize)
**/
- private int slotTableOffsetToFirstRecordLengthField;
+ private int slotTableOffsetToFirstRecordLengthField;
/**
@@ -498,7 +498,7 @@ public class StoredPage extends CachedPa
* offset of reserved space of slot[N] slot entry =
* slotTableOffsetToFirstReservedSpaceField + (N * slotEntrySize)
**/
- private int slotTableOffsetToFirstReservedSpaceField;
+ private int slotTableOffsetToFirstReservedSpaceField;
/**
* total usable space on a page.
@@ -506,11 +506,11 @@ public class StoredPage extends CachedPa
* 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
+ 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
+ // 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
/**
@@ -520,20 +520,20 @@ public class StoredPage extends CachedPa
* 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;
+ 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;
+ 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;
+ protected ArrayInputStream rawDataIn;
+ protected ArrayOutputStream rawDataOut;
+ protected FormatIdOutputStream logicalDataOut;
/**************************************************************************
@@ -545,10 +545,10 @@ public class StoredPage extends CachedPa
/**
* Simple no-arg constructor for StoredPage.
**/
- public StoredPage()
- {
- super();
- }
+ public StoredPage()
+ {
+ super();
+ }
/**************************************************************************
* Private/Protected methods of This class:
@@ -559,11 +559,11 @@ public class StoredPage extends CachedPa
* get scratch space for over flow record header.
* <p>
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private StoredRecordHeader getOverFlowRecordHeader()
- throws StandardException
+ private StoredRecordHeader getOverFlowRecordHeader()
+ throws StandardException
{
return(
overflowRecordHeader != null ?
@@ -578,19 +578,19 @@ public class StoredPage extends CachedPa
* Called by setIdentity() and createIdentity() - the Cacheable interfaces
* which are used to move a page in/out of cache.
**/
- protected void initialize()
- {
- super.initialize();
-
- if (rawDataIn == null)
- {
- rawDataIn = new ArrayInputStream();
- checksum = new CRC32();
- }
-
- if (pageData != null)
- rawDataIn.setData(pageData);
- }
+ protected void initialize()
+ {
+ super.initialize();
+
+ if (rawDataIn == null)
+ {
+ rawDataIn = new ArrayInputStream();
+ checksum = new CRC32();
+ }
+
+ if (pageData != null)
+ rawDataIn.setData(pageData);
+ }
/**
@@ -601,15 +601,15 @@ public class StoredPage extends CachedPa
* never modified during their lifetime in the cache.
* <p>
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private void createOutStreams()
- {
- rawDataOut = new ArrayOutputStream();
- rawDataOut.setData(pageData);
+ private void createOutStreams()
+ {
+ rawDataOut = new ArrayOutputStream();
+ rawDataOut.setData(pageData);
- logicalDataOut = new FormatIdOutputStream(rawDataOut);
- }
+ logicalDataOut = new FormatIdOutputStream(rawDataOut);
+ }
/**
* Tie the logical output stream to a passed in OutputStream.
@@ -617,13 +617,13 @@ public class StoredPage extends CachedPa
* 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();
+ private void setOutputStream(OutputStream out)
+ {
+ if (rawDataOut == null)
+ createOutStreams();
- logicalDataOut.setOutput(out);
- }
+ logicalDataOut.setOutput(out);
+ }
/**
* Reset the logical output stream.
@@ -633,11 +633,11 @@ public class StoredPage extends CachedPa
* on any writes.
*
**/
- private void resetOutputStream()
- {
+ private void resetOutputStream()
+ {
- logicalDataOut.setOutput(rawDataOut);
- }
+ logicalDataOut.setOutput(rawDataOut);
+ }
/**************************************************************************
* Protected Methods of CachedPage class: (create, read and write a page.)
@@ -645,28 +645,28 @@ public class StoredPage extends CachedPa
*/
/**
- * use this passed in page buffer as this object's page data.
+ * 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)
+ * 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);
+ protected void usePageBuffer(byte[] pageBuffer)
+ {
+ pageData = pageBuffer;
+
+ int pageSize = pageData.length;
+ if (rawDataIn != null)
+ rawDataIn.setData(pageData);
// Note that the slotFieldSize and slotEntrySize need to be
// calculated BEFORE initSpace() is called, because the
@@ -682,16 +682,16 @@ public class StoredPage extends CachedPa
(pageSize - CHECKSUM_SIZE - slotEntrySize);
// offset of record length field in slot table entry[0]
- slotTableOffsetToFirstRecordLengthField =
+ slotTableOffsetToFirstRecordLengthField =
slotTableOffsetToFirstEntry + slotFieldSize;
// offset of reserved space field in slot table entry[0]
- slotTableOffsetToFirstReservedSpaceField =
+ slotTableOffsetToFirstReservedSpaceField =
slotTableOffsetToFirstEntry + (2 * slotFieldSize);
- if (rawDataOut != null)
- rawDataOut.setData(pageData);
- }
+ if (rawDataOut != null)
+ rawDataOut.setData(pageData);
+ }
/**
* Calculate the slot field size from the page size.
@@ -720,28 +720,28 @@ public class StoredPage extends CachedPa
* @param args information stored about the page, once in the
* container header and passed in through the object.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- protected void createPage(PageKey newIdentity, PageCreationArgs args)
- throws StandardException
- {
+ protected void createPage(PageKey newIdentity, PageCreationArgs args)
+ throws StandardException
+ {
- spareSpace = args.spareSpace;
- minimumRecordSize = args.minimumRecordSize;
+ spareSpace = args.spareSpace;
+ minimumRecordSize = args.minimumRecordSize;
setPageArray(args.pageSize);
- cleanPage(); // clean up the page array
+ cleanPage(); // clean up the page array
- setPageVersion(0); // page is being created for the first time
+ setPageVersion(0); // page is being created for the first time
- nextId = RecordHandle.FIRST_RECORD_ID; // first record Id
- generation = 0;
- prevGeneration = 0; // there is no previous generation
- bipLocation = 0L;
+ nextId = RecordHandle.FIRST_RECORD_ID; // first record Id
+ generation = 0;
+ prevGeneration = 0; // there is no previous generation
+ bipLocation = 0L;
- createOutStreams();
- }
+ createOutStreams();
+ }
/**
* Initialize the page from values in the page buffer.
@@ -755,103 +755,103 @@ public class StoredPage extends CachedPa
* @param newIdentity The key representing page being read in (segment,
* container, page number)
*
- * @exception StandardException If the page cannot be read correctly,
+ * @exception StandardException If the page cannot be read correctly,
* or is inconsistent.
**/
- protected void initFromData(
+ protected void initFromData(
FileContainer myContainer,
PageKey newIdentity)
- throws StandardException
- {
- if (myContainer != null)
- {
+ throws StandardException
+ {
+ if (myContainer != null)
+ {
// read in info about page stored once in the container header.
- spareSpace = myContainer.getSpareSpace();
- minimumRecordSize = myContainer.getMinimumRecordSize();
- }
-
- // if it is null, assume spareSpace and minimumRecordSize is the
- // same. We would only call initFromData after a restore then.
-
- try
- {
- readPageHeader();
- initSlotTable(newIdentity);
- }
+ spareSpace = myContainer.getSpareSpace();
+ minimumRecordSize = myContainer.getMinimumRecordSize();
+ }
+
+ // if it is null, assume spareSpace and minimumRecordSize is the
+ // same. We would only call initFromData after a restore then.
+
+ try
+ {
+ readPageHeader();
+ initSlotTable(newIdentity);
+ }
catch (IOException ioe)
{
- // i/o methods on the byte array have thrown an IOException
- throw dataFactory.markCorrupt(
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, newIdentity));
- }
+ }
- try
- {
- validateChecksum(newIdentity);
- }
- catch (StandardException se)
- {
- if (se.getMessageId().equals(SQLState.FILE_BAD_CHECKSUM))
- {
- // it is remotely possible that the disk transfer got garbled,
- // i.e., the page is actually fine on disk but the version we
- // got has some rubbish on it. Double check.
- int pagesize = getPageSize();
- byte[] corruptPage = pageData;
- pageData = null; // clear this
+ try
+ {
+ validateChecksum(newIdentity);
+ }
+ catch (StandardException se)
+ {
+ if (se.getMessageId().equals(SQLState.FILE_BAD_CHECKSUM))
+ {
+ // it is remotely possible that the disk transfer got garbled,
+ // i.e., the page is actually fine on disk but the version we
+ // got has some rubbish on it. Double check.
+ int pagesize = getPageSize();
+ byte[] corruptPage = pageData;
+ pageData = null; // clear this
- // set up the new page array
- setPageArray(pagesize);
+ // set up the new page array
+ setPageArray(pagesize);
- try
+ try
{
- myContainer.readPage(newIdentity.getPageNumber(), pageData);
- }
+ myContainer.readPage(newIdentity.getPageNumber(), pageData);
+ }
catch (IOException ioe)
{
- throw dataFactory.markCorrupt(
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, newIdentity));
- }
+ }
+
+ if (SanityManager.DEBUG)
+ {
+ SanityManager.DEBUG_CLEAR("TEST_BAD_CHECKSUM");
+ }
+
+ // see if this read confirms the checksum error
+ try
+ {
+ validateChecksum(newIdentity);
+ }
+ catch (StandardException sse)
+ {
+ // really bad
+ throw dataFactory.markCorrupt(se);
+ }
- if (SanityManager.DEBUG)
- {
- SanityManager.DEBUG_CLEAR("TEST_BAD_CHECKSUM");
- }
-
- // see if this read confirms the checksum error
- try
- {
- validateChecksum(newIdentity);
- }
- catch (StandardException sse)
- {
- // really bad
- throw dataFactory.markCorrupt(se);
- }
-
- // If we got here, this means the first read is bad but the
- // second read is good. This could be due to disk I/O error or
- // a bug in the way the file pointer is mis-managed.
- String firstImage = pagedataToHexDump(corruptPage);
- String secondImage =
+ // If we got here, this means the first read is bad but the
+ // second read is good. This could be due to disk I/O error or
+ // a bug in the way the file pointer is mis-managed.
+ String firstImage = pagedataToHexDump(corruptPage);
+ String secondImage =
(SanityManager.DEBUG) ?
toString() : pagedataToHexDump(corruptPage);
- throw StandardException.newException(
+ throw StandardException.newException(
SQLState.FILE_IO_GARBLED, se,
newIdentity, firstImage, secondImage);
- }
- else
- {
- throw se;
- }
- }
-
+ }
+ else
+ {
+ throw se;
+ }
+ }
+
- }
+ }
/**
* Validate the check sum on the page.
@@ -862,69 +862,69 @@ public class StoredPage extends CachedPa
*
* @param id The key that describes the page.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- protected void validateChecksum(PageKey id)
+ protected void validateChecksum(PageKey id)
throws StandardException
- {
- long onDiskChecksum;
+ {
+ long onDiskChecksum;
- try
+ try
{
- // read the checksum stored on the page on disk. It is stored
+ // read the checksum stored on the page on disk. It is stored
// in the last "CHECKSUM_SIZE" bytes of the page, and is a long.
- rawDataIn.setPosition(getPageSize() - CHECKSUM_SIZE);
- onDiskChecksum = rawDataIn.readLong();
- }
+ rawDataIn.setPosition(getPageSize() - CHECKSUM_SIZE);
+ onDiskChecksum = rawDataIn.readLong();
+ }
catch (IOException ioe)
{
- // i/o methods on the byte array have thrown an IOException
- throw dataFactory.markCorrupt(
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, id));
- }
+ }
- // Force the checksum to be recalculated based on the current page.
- checksum.reset();
- checksum.update(pageData, 0, getPageSize() - CHECKSUM_SIZE);
-
- // force a bad checksum error
- if (SanityManager.DEBUG)
- {
- if (SanityManager.DEBUG_ON("TEST_BAD_CHECKSUM"))
+ // Force the checksum to be recalculated based on the current page.
+ checksum.reset();
+ checksum.update(pageData, 0, getPageSize() - CHECKSUM_SIZE);
+
+ // force a bad checksum error
+ if (SanityManager.DEBUG)
+ {
+ if (SanityManager.DEBUG_ON("TEST_BAD_CHECKSUM"))
{
// set on disk checksum to wrong value
- onDiskChecksum = 123456789;
+ onDiskChecksum = 123456789;
}
- }
+ }
- if (onDiskChecksum != checksum.getValue())
- {
- // try again using new checksum object to be doubly sure
- CRC32 newChecksum = new CRC32();
- newChecksum.reset();
- newChecksum.update(pageData, 0, getPageSize()-CHECKSUM_SIZE);
- if (onDiskChecksum != newChecksum.getValue())
- {
- throw StandardException.newException(
+ if (onDiskChecksum != checksum.getValue())
+ {
+ // try again using new checksum object to be doubly sure
+ CRC32 newChecksum = new CRC32();
+ newChecksum.reset();
+ newChecksum.update(pageData, 0, getPageSize()-CHECKSUM_SIZE);
+ if (onDiskChecksum != newChecksum.getValue())
+ {
+ throw StandardException.newException(
SQLState.FILE_BAD_CHECKSUM,
id,
new Long(checksum.getValue()),
new Long(onDiskChecksum),
pagedataToHexDump(pageData));
- }
- else
- {
- // old one is bad, get rid of it
- if (SanityManager.DEBUG)
- SanityManager.THROWASSERT("old checksum gets wrong value");
-
- checksum = newChecksum;
- }
- }
- }
+ }
+ else
+ {
+ // old one is bad, get rid of it
+ if (SanityManager.DEBUG)
+ SanityManager.THROWASSERT("old checksum gets wrong value");
+
+ checksum = newChecksum;
+ }
+ }
+ }
/**
* Recalculate checksum and write it to the page array.
@@ -932,16 +932,16 @@ public class StoredPage extends CachedPa
* Recalculate the checksum of the page, and write the result back into
* the last bytes of the page.
*
- * @exception IOException if writing to end of array fails.
+ * @exception IOException if writing to end of array fails.
**/
- protected void updateChecksum() throws IOException
- {
- checksum.reset();
- checksum.update(pageData, 0, getPageSize() - CHECKSUM_SIZE);
-
- rawDataOut.setPosition(getPageSize() - CHECKSUM_SIZE);
- logicalDataOut.writeLong(checksum.getValue());
- }
+ protected void updateChecksum() throws IOException
+ {
+ checksum.reset();
+ checksum.update(pageData, 0, getPageSize() - CHECKSUM_SIZE);
+
+ rawDataOut.setPosition(getPageSize() - CHECKSUM_SIZE);
+ logicalDataOut.writeLong(checksum.getValue());
+ }
/**
* Write information about page from variables into page byte array.
@@ -953,97 +953,97 @@ public class StoredPage extends CachedPa
*
* @param identity The key of this page.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- protected void writePage(PageKey identity)
+ protected void writePage(PageKey identity)
throws StandardException
- {
- if (SanityManager.DEBUG)
+ {
+ if (SanityManager.DEBUG)
{
// some consistency checks on fields of the page, good to check
// before we write them into the page.
- if ((freeSpace < 0) ||
+ if ((freeSpace < 0) ||
(firstFreeByte + freeSpace) != (getSlotOffset(slotsInUse - 1)))
{
// make sure free space is not negative and does not overlap
// used space.
- SanityManager.THROWASSERT(
+ SanityManager.THROWASSERT(
"writePage detected problem in freespace and used space."
+ "slotsInUse = " + slotsInUse
- + ", firstFreeByte = " + firstFreeByte
- + ", freeSpace = " + freeSpace
- + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
- + ", page = " + this);
- }
+ + ", firstFreeByte = " + firstFreeByte
+ + ", freeSpace = " + freeSpace
+ + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
+ + ", page = " + this);
+ }
- if ((slotsInUse == 0) &&
- (firstFreeByte != (getPageSize() - totalSpace - CHECKSUM_SIZE)))
+ if ((slotsInUse == 0) &&
+ (firstFreeByte != (getPageSize() - totalSpace - CHECKSUM_SIZE)))
{
- SanityManager.THROWASSERT("slotsInUse = " + slotsInUse
- + ", firstFreeByte = " + firstFreeByte
- + ", freeSpace = " + freeSpace
- + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
- + ", page = " + this);
+ SanityManager.THROWASSERT("slotsInUse = " + slotsInUse
+ + ", firstFreeByte = " + firstFreeByte
+ + ", freeSpace = " + freeSpace
+ + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
+ + ", page = " + this);
}
- }
+ }
- try
+ try
{
- if (headerOutOfDate)
+ if (headerOutOfDate)
{
- updatePageHeader();
+ updatePageHeader();
}
- else
+ else
{
- // page version always need to be updated if page is dirty,
- // either do it in updatePageHeader or by itself
- updatePageVersion();
+ // page version always need to be updated if page is dirty,
+ // either do it in updatePageHeader or by itself
+ updatePageVersion();
}
- updateChecksum();
+ updateChecksum();
- }
+ }
catch (IOException ioe)
{
- // i/o methods on the byte array have thrown an IOException
- throw dataFactory.markCorrupt(
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, identity));
- }
+ }
- }
+ }
/**
* Write out the format id of this page
*
* @param identity The key of this page.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- protected void writeFormatId(PageKey identity) throws StandardException
- {
- try
- {
- if (rawDataOut == null)
- createOutStreams();
+ protected void writeFormatId(PageKey identity) throws StandardException
+ {
+ try
+ {
+ if (rawDataOut == null)
+ createOutStreams();
- rawDataOut.setPosition(0);
+ rawDataOut.setPosition(0);
- FormatIdUtil.writeFormatIdInteger(
+ FormatIdUtil.writeFormatIdInteger(
logicalDataOut, getTypeFormatId());
- }
+ }
catch (IOException ioe)
{
- // i/o methods on the byte array have thrown an IOException
- throw dataFactory.markCorrupt(
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, identity));
- }
- }
+ }
+ }
/**************************************************************************
@@ -1062,12 +1062,12 @@ public class StoredPage extends CachedPa
* @see org.apache.derby.impl.store.raw.data.BasePage#releaseExclusive
*
**/
- protected void releaseExclusive()
- {
- super.releaseExclusive();
+ protected void releaseExclusive()
+ {
+ super.releaseExclusive();
- pageCache.release(this);
- }
+ pageCache.release(this);
+ }
/**
@@ -1081,16 +1081,16 @@ public class StoredPage extends CachedPa
* Do NOT count the slot entry size
* <p>
*
- * @return The number of bytes used by the row at slot "slot".
+ * @return The number of bytes used by the row at slot "slot".
*
* @param slot look at row at this slot.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- public int getTotalSpace(int slot)
+ public int getTotalSpace(int slot)
throws StandardException
- {
- try
+ {
+ try
{
// A slot entry looks like the following:
// 1st field: offset of the record on the page
@@ -1098,26 +1098,26 @@ public class StoredPage extends CachedPa
// 3rd field: amount of space reserved for the record to grow.
// position the read at the beginning of the 2nd field.
- rawDataIn.setPosition(getSlotOffset(slot) + slotFieldSize);
+ rawDataIn.setPosition(getSlotOffset(slot) + slotFieldSize);
// return the size of the record + size of the reserved space.
// the size of the fields to read is determined by slotFieldSize.
return(
- ((slotFieldSize == SMALL_SLOT_SIZE) ?
- (rawDataIn.readUnsignedShort() +
+ ((slotFieldSize == SMALL_SLOT_SIZE) ?
+ (rawDataIn.readUnsignedShort() +
rawDataIn.readUnsignedShort()) :
- (rawDataIn.readInt() +
+ (rawDataIn.readInt() +
rawDataIn.readInt())));
- }
+ }
catch (IOException ioe)
{
- throw dataFactory.markCorrupt(
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
- }
- }
+ }
+ }
/**
* Is there minimal space for insert?
@@ -1130,25 +1130,25 @@ public class StoredPage extends CachedPa
* copy of the row directly onto the page.
* <p>
*
- * @return true if we think the page will allow an insert, false otherwise.
+ * @return true if we think the page will allow an insert, false otherwise.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- public boolean spaceForInsert()
+ public boolean spaceForInsert()
throws StandardException
- {
- // is this an empty page
- if (slotsInUse == 0)
- return(true);
+ {
+ // is this an empty page
+ if (slotsInUse == 0)
+ return(true);
- if (!allowInsert())
- return(false);
+ if (!allowInsert())
+ return(false);
- int usedSpace = totalSpace - freeSpace;
- int bytesPerRow = usedSpace / slotsInUse;
+ int usedSpace = totalSpace - freeSpace;
+ int bytesPerRow = usedSpace / slotsInUse;
- return(bytesPerRow <= freeSpace);
- }
+ return(bytesPerRow <= freeSpace);
+ }
/**
* Is row guaranteed to be inserted successfully on this page?
@@ -1158,7 +1158,7 @@ public class StoredPage extends CachedPa
* the row remains unchanged and the page latch is held.
* <p>
*
- * @return bolean indicating if row can be inserted on this page.
+ * @return bolean indicating if row can be inserted on this page.
*
* @param row The row to check for insert.
* @param validColumns bit map to interpret valid columns in row.
@@ -1167,47 +1167,47 @@ public class StoredPage extends CachedPa
* 50 means use 50% of page (ie. make sure
* 2 rows fit per page).
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- public boolean spaceForInsert(
+ public boolean spaceForInsert(
Object[] row,
FormatableBitSet validColumns,
int overflowThreshold)
- throws StandardException
- {
+ throws StandardException
+ {
- // is this an empty page
- if (slotsInUse == 0)
- return true;
-
+ // is this an empty page
+ if (slotsInUse == 0)
+ return true;
+
// does the estimate think it won't fit, if not return false to avoid
// cost of calling logRow() just to figure out if the row will fit.
- if (!allowInsert())
- return false;
+ if (!allowInsert())
+ return false;
- DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();
+ DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();
- try
+ try
{
- // This is a public call, start column is rawstore only.
- // set the starting Column for the row to be 0.
- logRow(
+ // This is a public call, start column is rawstore only.
+ // set the starting Column for the row to be 0.
+ logRow(
0, true, nextId, row, validColumns, out,
0, Page.INSERT_DEFAULT, -1, -1, overflowThreshold);
- }
+ }
catch (NoSpaceOnPage nsop)
{
- return false;
- }
+ return false;
+ }
catch (IOException ioe)
{
- throw StandardException.newException(
+ throw StandardException.newException(
SQLState.DATA_UNEXPECTED_EXCEPTION, ioe);
- }
+ }
- return true;
- }
+ return true;
+ }
/**
* Is row guaranteed to be inserted successfully on this page?
@@ -1219,7 +1219,7 @@ public class StoredPage extends CachedPa
* This is a private call only used when calculating whether an overflow
* page can be used to insert part of an overflow row/column.
*
- * @return bolean indicating if row can be inserted on this page.
+ * @return bolean indicating if row can be inserted on this page.
*
* @param row The row to check for insert.
* @param validColumns bit map to interpret valid columns in row.
@@ -1228,40 +1228,40 @@ public class StoredPage extends CachedPa
* 50 means use 50% of page (ie. make sure
* 2 rows fit per page).
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private boolean spaceForInsert(
+ private boolean spaceForInsert(
Object[] row,
FormatableBitSet validColumns,
int spaceNeeded,
int startColumn,
int overflowThreshold)
- throws StandardException
- {
- if (!(spaceForInsert() && (freeSpace >= spaceNeeded)))
- return false;
+ throws StandardException
+ {
+ if (!(spaceForInsert() && (freeSpace >= spaceNeeded)))
+ return false;
- DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();
+ DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();
- try
+ try
{
- logRow(
+ logRow(
0, true, nextId, row, validColumns, out, startColumn,
Page.INSERT_DEFAULT, -1, -1, overflowThreshold);
- }
+ }
catch (NoSpaceOnPage nsop)
{
- return false;
- }
+ return false;
+ }
catch (IOException ioe)
{
- throw StandardException.newException(
+ throw StandardException.newException(
SQLState.DATA_UNEXPECTED_EXCEPTION, ioe);
- }
+ }
- return true;
- }
+ return true;
+ }
/**
* Is this page unfilled?
@@ -1271,12 +1271,12 @@ public class StoredPage extends CachedPa
* "average" sized row onto the page.
* <p>
*
- * @return true if page is relatively unfilled.
+ * @return true if page is relatively unfilled.
**/
- public boolean unfilled()
- {
- return (allowInsert() && (freeSpace > (getPageSize() / 2)));
- }
+ public boolean unfilled()
+ {
+ return (allowInsert() && (freeSpace > (getPageSize() / 2)));
+ }
/**
* Is there enough space on the page to insert a minimum size row?
@@ -1286,30 +1286,30 @@ public class StoredPage extends CachedPa
* reserved space on the page for existing rows to grow on the page.
* <p>
*
- * @return boolean indicating if a minimum sized row can be inserted.
+ * @return boolean indicating if a minimum sized row can be inserted.
**/
- public boolean allowInsert()
- {
- // is this an empty page
- if (slotsInUse == 0)
- return true;
+ public boolean allowInsert()
+ {
+ // is this an empty page
+ if (slotsInUse == 0)
+ return true;
- int spaceAvailable = freeSpace;
+ int spaceAvailable = freeSpace;
- spaceAvailable -= slotEntrySize; // need to account new slot entry
+ spaceAvailable -= slotEntrySize; // need to account new slot entry
- if ((spaceAvailable < minimumRecordSize) ||
+ if ((spaceAvailable < minimumRecordSize) ||
(spaceAvailable < StoredRecordHeader.MAX_OVERFLOW_ONLY_REC_SIZE))
{
- return false;
+ return false;
}
- // see that we reserve enough space for existing rows to grow on page
- if (((spaceAvailable * 100) / totalSpace) < spareSpace)
- return false;
+ // see that we reserve enough space for existing rows to grow on page
+ if (((spaceAvailable * 100) / totalSpace) < spareSpace)
+ return false;
- return true;
- }
+ return true;
+ }
/**
* Does this page have enough space to insert the input rows?
@@ -1318,31 +1318,31 @@ public class StoredPage extends CachedPa
* this page?
* <p>
*
- * @return true if the sum of the lengths will fit on the page.
+ * @return true if the sum of the lengths will fit on the page.
*
* @param num_rows number of rows to check for.
* @param spaceNeeded array of lengths of the rows to insert.
**/
- public boolean spaceForCopy(int num_rows, int[] spaceNeeded)
- {
- // determine how many more bytes are needed for the slot entries
- int bytesNeeded = slotEntrySize * num_rows;
+ public boolean spaceForCopy(int num_rows, int[] spaceNeeded)
+ {
+ // determine how many more bytes are needed for the slot entries
+ int bytesNeeded = slotEntrySize * num_rows;
- for (int i = 0; i < num_rows; i++)
+ for (int i = 0; i < num_rows; i++)
{
- if (spaceNeeded[i] > 0)
+ if (spaceNeeded[i] > 0)
{
// add up the space needed by the rows, add in minimumRecordSize
// if length of actual row is less than minimumRecordSize.
- bytesNeeded +=
+ bytesNeeded +=
(spaceNeeded[i] >= minimumRecordSize ?
spaceNeeded[i] : minimumRecordSize);
- }
- }
+ }
+ }
- return((freeSpace - bytesNeeded) >= 0);
- }
+ return((freeSpace - bytesNeeded) >= 0);
+ }
/**
* Does this page have enough space to move the row to it.
@@ -1353,15 +1353,15 @@ public class StoredPage extends CachedPa
* @param spaceNeeded length of the row encoded with source_id record id.
* @param source_id record id of the row being moved.
*
- * @return true if the record will fit on this page, after being given a
+ * @return true if the record will fit on this page, after being given a
* new record id as the next id on this page.
*
* @exception StandardException Standard exception policy.
**/
- protected boolean spaceForCopy(
+ protected boolean spaceForCopy(
int spaceNeeded,
int source_id)
- {
+ {
spaceNeeded =
spaceNeeded
- StoredRecordHeader.getStoredSizeRecordId(source_id)
@@ -1373,8 +1373,8 @@ public class StoredPage extends CachedPa
(spaceNeeded >= minimumRecordSize ?
spaceNeeded : minimumRecordSize);
- return((freeSpace - bytesNeeded) >= 0);
- }
+ return((freeSpace - bytesNeeded) >= 0);
+ }
/**
* Read the record at the given slot into the given row.
@@ -1415,28 +1415,28 @@ public class StoredPage extends CachedPa
* @return false if a qualifier_list is provided and the row does not
* qualifier (no row read in that case), else true.
*
- * @exception StandardException Standard Derby error policy
+ * @exception StandardException Standard Derby error policy
**/
- protected boolean restoreRecordFromSlot(
+ protected boolean restoreRecordFromSlot(
int slot,
Object[] row,
FetchDescriptor fetchDesc,
RecordHandle recordToLock,
StoredRecordHeader recordHeader,
boolean isHeadRow)
- throws StandardException
- {
- try
+ throws StandardException
+ {
+ try
{
- int offset_to_row_data =
+ int offset_to_row_data =
getRecordOffset(slot) + recordHeader.size();
- if (SanityManager.DEBUG)
+ if (SanityManager.DEBUG)
{
- if (getRecordOffset(slot) <
+ if (getRecordOffset(slot) <
(PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE))
{
- SanityManager.THROWASSERT(
+ SanityManager.THROWASSERT(
"Incorrect offset. offset = " +
getRecordOffset(slot) +
", offset should be < " +
@@ -1444,21 +1444,21 @@ public class StoredPage extends CachedPa
(PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) +
", current slot = " + slot +
", total slotsInUse = " + slotsInUse);
- }
+ }
SanityManager.ASSERT(
isHeadRow, "restoreRecordFromSlot called on a non-headrow");
SanityManager.ASSERT(
!isOverflowPage(),
"restoreRecordFromSlot called on an overflow page.");
- }
+ }
// position the array reading stream at beginning of row data just
// past the record header.
- ArrayInputStream lrdi = rawDataIn;
- lrdi.setPosition(offset_to_row_data);
+ ArrayInputStream lrdi = rawDataIn;
+ lrdi.setPosition(offset_to_row_data);
- if (!recordHeader.hasOverflow())
+ if (!recordHeader.hasOverflow())
{
if (isHeadRow)
{
@@ -1594,51 +1594,51 @@ public class StoredPage extends CachedPa
}
return(true);
- }
- }
+ }
+ }
catch (IOException ioe)
{
- if (SanityManager.DEBUG)
- {
- if (pageData == null)
- {
- SanityManager.DEBUG_PRINT("DEBUG_TRACE",
- "caught an IOException in restoreRecordFromSlot " +
- (PageKey)getIdentity() + " slot " + slot +
- ", pageData is null");
- }
- else
- {
- SanityManager.DEBUG_PRINT("DEBUG_TRACE",
- "caught an IOException in reestoreRecordFromSlot, " +
- (PageKey)getIdentity() + " slot " + slot +
- ", pageData.length = " +
- pageData.length + " pageSize = " + getPageSize());
- SanityManager.DEBUG_PRINT("DEBUG_TRACE",
- "Hex dump of pageData \n " +
- "--------------------------------------------------\n" +
- pagedataToHexDump(pageData) +
- "--------------------------------------------------\n");
- SanityManager.DEBUG_PRINT("DEBUG_TRACE",
- "Attempt to dump page " + this.toString());
- }
- }
+ if (SanityManager.DEBUG)
+ {
+ if (pageData == null)
+ {
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "caught an IOException in restoreRecordFromSlot " +
+ (PageKey)getIdentity() + " slot " + slot +
+ ", pageData is null");
+ }
+ else
+ {
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "caught an IOException in reestoreRecordFromSlot, " +
+ (PageKey)getIdentity() + " slot " + slot +
+ ", pageData.length = " +
+ pageData.length + " pageSize = " + getPageSize());
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "Hex dump of pageData \n " +
+ "--------------------------------------------------\n" +
+ pagedataToHexDump(pageData) +
+ "--------------------------------------------------\n");
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "Attempt to dump page " + this.toString());
+ }
+ }
- // i/o methods on the byte array have thrown an IOException
- throw dataFactory.markCorrupt(
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
- }
- }
+ }
+ }
- private StoredRecordHeader restoreLongRecordFromSlot(
+ private StoredRecordHeader restoreLongRecordFromSlot(
Object[] row,
FetchDescriptor fetchDesc,
RecordHandle recordToLock,
StoredRecordHeader parent_recordHeader)
- throws StandardException
- {
+ throws StandardException
+ {
int slot =
findRecordById(
@@ -1736,7 +1736,7 @@ public class StoredPage extends CachedPa
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, getPageId()));
}
- }
+ }
/**
* Create a new record handle.
@@ -1746,12 +1746,12 @@ public class StoredPage extends CachedPa
* storeRecordForInsert().
* <p>
*
- * @return The next id to assing to a row.
+ * @return The next id to assing to a row.
**/
- public int newRecordId()
- {
- return nextId;
- }
+ public int newRecordId()
+ {
+ return nextId;
+ }
/**
* Create a new record handle, and bump the id.
@@ -1762,16 +1762,16 @@ public class StoredPage extends CachedPa
* is not enough space on the page.
* <p>
*
- * @return The next id to assing to a row.
+ * @return The next id to assing to a row.
**/
- public int newRecordIdAndBump()
- {
+ public int newRecordIdAndBump()
+ {
// headerOutOfDate must be bumped as nextId is changing, and must
// eventually be updated in the page array.
- headerOutOfDate = true;
-
- return nextId++;
- }
+ headerOutOfDate = true;
+
+ return nextId++;
+ }
/**
@@ -1784,27 +1784,27 @@ public class StoredPage extends CachedPa
* the end of the operation.
* <p>
*
- * @return the next id based on the input id.
+ * @return the next id based on the input id.
*
* @param recordId The id caller just used, return the next one.
*
**/
- protected int newRecordId(int recordId)
- {
- if (SanityManager.DEBUG)
+ protected int newRecordId(int recordId)
+ {
+ if (SanityManager.DEBUG)
{
- SanityManager.ASSERT(
+ SanityManager.ASSERT(
recordId >= nextId,
"should not create a record Id that is already given out");
- }
+ }
- return recordId + 1;
- }
+ return recordId + 1;
+ }
- public boolean isOverflowPage()
- {
- return isOverflowPage;
- }
+ public boolean isOverflowPage()
+ {
+ return isOverflowPage;
+ }
@@ -1816,10 +1816,10 @@ public class StoredPage extends CachedPa
/**
* Get the full size of the page.
**/
- public final int getPageSize()
- {
- return pageData.length;
- }
+ public final int getPageSize()
+ {
+ return pageData.length;
+ }
/**
@@ -1828,10 +1828,10 @@ public class StoredPage extends CachedPa
* @param offset position of first byte to clear
* @param length how many bytes to clear
**/
- protected final void clearSection(int offset, int length)
- {
+ protected final void clearSection(int offset, int length)
+ {
Arrays.fill(pageData, offset, offset + length, (byte) 0);
- }
+ }
/**
* The maximum free space on this page possible.
@@ -1840,21 +1840,21 @@ public class StoredPage extends CachedPa
* for the records and the slot offset table.
* NOTE: subclass may have overwitten it to report less freeSpace
*
- * @return the maximum free space on this page possible.
+ * @return the maximum free space on this page possible.
*
**/
- protected int getMaxFreeSpace()
- {
- return getPageSize() - RECORD_SPACE_OFFSET - CHECKSUM_SIZE;
- }
+ protected int getMaxFreeSpace()
+ {
+ return getPageSize() - RECORD_SPACE_OFFSET - CHECKSUM_SIZE;
+ }
/**
* The current free space on the page.
**/
- protected int getCurrentFreeSpace()
- {
- return freeSpace;
- }
+ protected int getCurrentFreeSpace()
+ {
+ return freeSpace;
+ }
/**************************************************************************
* Page header routines
@@ -1867,34 +1867,34 @@ public class StoredPage extends CachedPa
* Read the page header from byte form in the page array into in memory
* variables.
**/
- private void readPageHeader()
+ private void readPageHeader()
throws IOException
- {
- // these reads are always against the page array
- ArrayInputStream lrdi = rawDataIn;
-
- lrdi.setPosition(PAGE_HEADER_OFFSET);
- long spare;
-
- isOverflowPage = lrdi.readBoolean();
- setPageStatus (lrdi.readByte());
- setPageVersion (lrdi.readLong());
- slotsInUse = lrdi.readUnsignedShort();
- nextId = lrdi.readInt();
- generation = lrdi.readInt(); // page generation (Future Use)
- prevGeneration = lrdi.readInt(); // previous generation (Future Use)
- bipLocation = lrdi.readLong(); // BIPage location (Future Use)
-
- // number of deleted rows on page, we start to store this release 2.0.
- // for upgrade reasons, a 0 on disk means -1, so, we subtract one here.
- deletedRowCount = lrdi.readUnsignedShort() - 1;
+ {
+ // these reads are always against the page array
+ ArrayInputStream lrdi = rawDataIn;
+
+ lrdi.setPosition(PAGE_HEADER_OFFSET);
+ long spare;
+
+ isOverflowPage = lrdi.readBoolean();
+ setPageStatus (lrdi.readByte());
+ setPageVersion (lrdi.readLong());
+ slotsInUse = lrdi.readUnsignedShort();
+ nextId = lrdi.readInt();
+ generation = lrdi.readInt(); // page generation (Future Use)
+ prevGeneration = lrdi.readInt(); // previous generation (Future Use)
+ bipLocation = lrdi.readLong(); // BIPage location (Future Use)
+
+ // number of deleted rows on page, we start to store this release 2.0.
+ // for upgrade reasons, a 0 on disk means -1, so, we subtract one here.
+ deletedRowCount = lrdi.readUnsignedShort() - 1;
// the next 4 (total 22 bytes) are reserved for future
- spare = lrdi.readUnsignedShort();
- spare = lrdi.readInt(); // used by encryption
- spare = lrdi.readLong();
- spare = lrdi.readLong();
- }
+ spare = lrdi.readUnsignedShort();
+ spare = lrdi.readInt(); // used by encryption
+ spare = lrdi.readLong();
+ spare = lrdi.readLong();
+ }
/**
@@ -1903,51 +1903,51 @@ public class StoredPage extends CachedPa
* Write the bytes of the page header, taking the values from those
* in the in memory variables.
**/
- private void updatePageHeader()
+ private void updatePageHeader()
throws IOException
- {
- rawDataOut.setPosition(PAGE_HEADER_OFFSET);
+ {
+ rawDataOut.setPosition(PAGE_HEADER_OFFSET);
- logicalDataOut.writeBoolean(isOverflowPage);
- logicalDataOut.writeByte(getPageStatus());
- logicalDataOut.writeLong(getPageVersion());
- logicalDataOut.writeShort(slotsInUse);
- logicalDataOut.writeInt(nextId);
- logicalDataOut.writeInt(generation); // page generation (Future Use)
- logicalDataOut.writeInt(prevGeneration); // previous generation (Future Use)
- logicalDataOut.writeLong(bipLocation); // BIPage location (Future Use)
+ logicalDataOut.writeBoolean(isOverflowPage);
+ logicalDataOut.writeByte(getPageStatus());
+ logicalDataOut.writeLong(getPageVersion());
+ logicalDataOut.writeShort(slotsInUse);
+ logicalDataOut.writeInt(nextId);
+ logicalDataOut.writeInt(generation); // page generation (Future Use)
+ logicalDataOut.writeInt(prevGeneration); // previous generation (Future Use)
+ logicalDataOut.writeLong(bipLocation); // BIPage location (Future Use)
- // number of deleted rows on page, we start to store this release 2.0.
- // for upgrade reasons, a 0 on disk means -1, so, we add one when we
+ // number of deleted rows on page, we start to store this release 2.0.
+ // for upgrade reasons, a 0 on disk means -1, so, we add one when we
// write it to disk.
- logicalDataOut.writeShort(deletedRowCount + 1);
+ logicalDataOut.writeShort(deletedRowCount + 1);
- logicalDataOut.writeShort(0); // reserved for future
- logicalDataOut.writeInt(
- dataFactory.random()); // random bytes for encryption
- logicalDataOut.writeLong(0); // reserved for future
- logicalDataOut.writeLong(0); // reserved for future
-
- // we put a random value int into the page if the database is encrypted
- // so that the checksum will be very different even with the same
- // page image, when we encrypt or decrypt the page, we move the
- // checksum to the front so that the encrypted page will look very
- // different even with just the one int difference. We never look at
- // the value of the random number and we could have put it anywhere in
- // the page as long as it doesn't obscure real data.
-
- headerOutOfDate = false;
- }
+ logicalDataOut.writeShort(0); // reserved for future
+ logicalDataOut.writeInt(
+ dataFactory.random()); // random bytes for encryption
+ logicalDataOut.writeLong(0); // reserved for future
+ logicalDataOut.writeLong(0); // reserved for future
+
+ // we put a random value int into the page if the database is encrypted
+ // so that the checksum will be very different even with the same
+ // page image, when we encrypt or decrypt the page, we move the
+ // checksum to the front so that the encrypted page will look very
+ // different even with just the one int difference. We never look at
+ // the value of the random number and we could have put it anywhere in
+ // the page as long as it doesn't obscure real data.
+
+ headerOutOfDate = false;
+ }
/**
* Update the page version number in the byte array
**/
- private void updatePageVersion()
+ private void updatePageVersion()
throws IOException
- {
- rawDataOut.setPosition(PAGE_VERSION_OFFSET);
- logicalDataOut.writeLong(getPageVersion());
- }
+ {
+ rawDataOut.setPosition(PAGE_VERSION_OFFSET);
+ logicalDataOut.writeLong(getPageVersion());
+ }
/**************************************************************************
* Slot Offset & Length table manipulation
@@ -1960,29 +1960,29 @@ public class StoredPage extends CachedPa
* Get the page offset of a slot entry, this is not the offset of
* the record stored in the slot, but the offset of the actual slot.
*
- * @return The page offset of a given slot entry.
+ * @return The page offset of a given slot entry.
*
* @param slot The array entry of the slot to find.
**/
- private int getSlotOffset(int slot)
- {
+ private int getSlotOffset(int slot)
+ {
// slot table grows backward from the spot at the end of the page just
// before the checksum which is located in the last 8 bytes of the page.
return(slotTableOffsetToFirstEntry - (slot * slotEntrySize));
- }
+ }
/**
* Get the page offset of the record associated with the input slot.
* <p>
* This is the actual offset on the page of the beginning of the record.
*
- * @return The page offset of the record associated with the input slot.
+ * @return The page offset of the record associated with the input slot.
*
* @param slot The array entry of the slot to find.
**/
- private int getRecordOffset(int slot)
- {
+ private int getRecordOffset(int slot)
+ {
byte[] data = pageData;
int offset = slotTableOffsetToFirstEntry - (slot * slotEntrySize);
@@ -2004,7 +2004,7 @@ public class StoredPage extends CachedPa
((data[offset++] & 0xff) << 16) |
((data[offset++] & 0xff) << 8) |
((data[offset] & 0xff) )));
- }
+ }
/**
* Set the page offset of the record associated with the input slot.
@@ -2014,16 +2014,16 @@ public class StoredPage extends CachedPa
* @param slot The array entry of the slot to set.
* @param recordOffset the new offset to set.
**/
- private void setRecordOffset(int slot, int recordOffset)
+ private void setRecordOffset(int slot, int recordOffset)
throws IOException
- {
- rawDataOut.setPosition(getSlotOffset(slot));
+ {
+ rawDataOut.setPosition(getSlotOffset(slot));
- if (slotFieldSize == SMALL_SLOT_SIZE)
- logicalDataOut.writeShort(recordOffset);
- else
- logicalDataOut.writeInt(recordOffset);
- }
+ if (slotFieldSize == SMALL_SLOT_SIZE)
+ logicalDataOut.writeShort(recordOffset);
+ else
+ logicalDataOut.writeInt(recordOffset);
+ }
/**
* Return length of row on this page.
@@ -2032,29 +2032,29 @@ public class StoredPage extends CachedPa
* this record. This length is stored as the second "field" of the
* slot table entry.
*
- * @return The length of the row on this page.
+ * @return The length of the row on this page.
*
* @param slot the slot of the row to look up the length of.
*
**/
- protected int getRecordPortionLength(int slot)
+ protected int getRecordPortionLength(int slot)
throws IOException
- {
- if (SanityManager.DEBUG)
+ {
+ if (SanityManager.DEBUG)
{
- SanityManager.ASSERT(getRecordOffset(slot) != 0);
- }
+ SanityManager.ASSERT(getRecordOffset(slot) != 0);
+ }
- // these reads are always against the page array
- ArrayInputStream lrdi = rawDataIn;
+ // these reads are always against the page array
+ ArrayInputStream lrdi = rawDataIn;
- lrdi.setPosition(
+ lrdi.setPosition(
slotTableOffsetToFirstRecordLengthField - (slot * slotEntrySize));
return(
(slotFieldSize == SMALL_SLOT_SIZE) ?
lrdi.readUnsignedShort() : lrdi.readInt());
- }
+ }
/**
* Return reserved length of row on this page.
@@ -2062,33 +2062,33 @@ public class StoredPage extends CachedPa
* Return the reserved length of this record.
* This length is stored as the third "field" of the slot table entry.
*
- * @return The reserved length of the row on this page.
+ * @return The reserved length of the row on this page.
*
* @param slot the slot of the row to look up the length of.
*
**/
- public int getReservedCount(int slot) throws IOException
- {
- if (SanityManager.DEBUG)
+ public int getReservedCount(int slot) throws IOException
+ {
+ if (SanityManager.DEBUG)
{
- SanityManager.ASSERT(getRecordOffset(slot) != 0);
- }
+ SanityManager.ASSERT(getRecordOffset(slot) != 0);
+ }
- // these reads are always against the page array
- ArrayInputStream lrdi = rawDataIn;
+ // these reads are always against the page array
+ ArrayInputStream lrdi = rawDataIn;
- lrdi.setPosition(
+ lrdi.setPosition(
slotTableOffsetToFirstReservedSpaceField - (slot * slotEntrySize));
return(
(slotFieldSize == SMALL_SLOT_SIZE) ?
lrdi.readUnsignedShort() : lrdi.readInt());
- }
+ }
- /**
- Update the length of data stored on this page for this record
- */
+ /**
+ Update the length of data stored on this page for this record
+ */
/**
* Update the length of data stored on this page for this record
* <p>
@@ -2103,61 +2103,61 @@ public class StoredPage extends CachedPa
* @param delta The amount the record length changed.
* @param reservedDelta The amount the reserved length changed.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private void updateRecordPortionLength(
+ private void updateRecordPortionLength(
int slot,
int delta,
int reservedDelta)
- throws IOException
- {
- if (SanityManager.DEBUG)
- {
- SanityManager.ASSERT(getRecordOffset(slot) != 0);
-
- if ((delta + reservedDelta) < 0)
- SanityManager.THROWASSERT(
- "total space of record is not allowed to shrink, delta == "
- + delta + " reservedDelta = " + reservedDelta);
-
- if ((getRecordPortionLength(slot) + delta) < 0)
- SanityManager.THROWASSERT(
- "record portion length cannot be < 0.recordPortionLength = "
- + getRecordPortionLength(slot) + " delta = " + delta);
-
- if ((getReservedCount(slot) + reservedDelta) < 0)
- SanityManager.THROWASSERT(
- "reserved space for record cannot be < 0. reservedCount = "
- + getReservedCount(slot) + " reservedDelta = "
- + reservedDelta);
- }
+ throws IOException
+ {
+ if (SanityManager.DEBUG)
+ {
+ SanityManager.ASSERT(getRecordOffset(slot) != 0);
+
+ if ((delta + reservedDelta) < 0)
+ SanityManager.THROWASSERT(
+ "total space of record is not allowed to shrink, delta == "
+ + delta + " reservedDelta = " + reservedDelta);
+
+ if ((getRecordPortionLength(slot) + delta) < 0)
+ SanityManager.THROWASSERT(
+ "record portion length cannot be < 0.recordPortionLength = "
+ + getRecordPortionLength(slot) + " delta = " + delta);
+
+ if ((getReservedCount(slot) + reservedDelta) < 0)
+ SanityManager.THROWASSERT(
+ "reserved space for record cannot be < 0. reservedCount = "
+ + getReservedCount(slot) + " reservedDelta = "
+ + reservedDelta);
+ }
// position the stream to beginning of 2nd field of slot entry.
- rawDataOut.setPosition(
+ rawDataOut.setPosition(
slotTableOffsetToFirstRecordLengthField - (slot * slotEntrySize));
// write the new record length to 2nd field
- if (slotFieldSize == SMALL_SLOT_SIZE)
- logicalDataOut.writeShort(getRecordPortionLength(slot) + delta);
- else
- logicalDataOut.writeInt(getRecordPortionLength(slot) + delta);
+ if (slotFieldSize == SMALL_SLOT_SIZE)
+ logicalDataOut.writeShort(getRecordPortionLength(slot) + delta);
+ else
+ logicalDataOut.writeInt(getRecordPortionLength(slot) + delta);
// if necessary, write the 3rd field - above write has positioned the
// stream to the 3rd field.
- if (reservedDelta != 0)
+ if (reservedDelta != 0)
{
- if (slotFieldSize == SMALL_SLOT_SIZE)
+ if (slotFieldSize == SMALL_SLOT_SIZE)
{
- logicalDataOut.writeShort(
+ logicalDataOut.writeShort(
getReservedCount(slot) + reservedDelta);
}
- else
+ else
{
- logicalDataOut.writeInt(
+ logicalDataOut.writeInt(
getReservedCount(slot) + reservedDelta);
}
- }
- }
+ }
+ }
/**
* Initialize the in-memory slot table.
@@ -2171,35 +2171,35 @@ public class StoredPage extends CachedPa
* to build the page existing info in the class is
* not set up yet (like getIdentity()).
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private void initSlotTable(
+ private void initSlotTable(
PageKey newIdentity)
throws StandardException
- {
- int localSlotsInUse = slotsInUse;
+ {
+ int localSlotsInUse = slotsInUse;
- // must initialize the header now
- initializeHeaders(localSlotsInUse);
+ // must initialize the header now
+ initializeHeaders(localSlotsInUse);
- // mark all the space on the page as free
- clearAllSpace();
-
- // first count the space occupied by the slot table
- freeSpace -= localSlotsInUse * slotEntrySize;
-
- int lastSlotOnPage = -1;
- int lastRecordOffset = -1;
-
- try
+ // mark all the space on the page as free
+ clearAllSpace();
+
+ // first count the space occupied by the slot table
+ freeSpace -= localSlotsInUse * slotEntrySize;
+
+ int lastSlotOnPage = -1;
+ int lastRecordOffset = -1;
+
+ try
{
- for (int slot = 0; slot < localSlotsInUse; slot++)
+ for (int slot = 0; slot < localSlotsInUse; slot++)
{
- if (SanityManager.DEBUG)
+ if (SanityManager.DEBUG)
{
int total_space = getTotalSpace(slot);
- if ((!isOverflowPage() &&
+ if ((!isOverflowPage() &&
(minimumRecordSize > total_space)) ||
(isOverflowPage() &&
(StoredRecordHeader.MAX_OVERFLOW_ONLY_REC_SIZE >
@@ -2211,93 +2211,93 @@ public class StoredPage extends CachedPa
// Overflow rows including reserved space must be
// larger than MAX_OVERFLOW_ONLY_REC_SIZE.
- SanityManager.THROWASSERT(
+ SanityManager.THROWASSERT(
"initSlotTable consistency check failed: " +
- " slot " + slot +
- " minimumRecordSize = " + minimumRecordSize +
- " totalSpace = " + total_space +
- " recordPortionLength = " +
+ " slot " + slot +
+ " minimumRecordSize = " + minimumRecordSize +
+ " totalSpace = " + total_space +
+ " recordPortionLength = " +
getRecordPortionLength(slot) +
" reservedCount = " + getReservedCount(slot));
}
- }
+ }
- int recordOffset = getRecordOffset(slot);
+ int recordOffset = getRecordOffset(slot);
- // check that offset points into the record space area.
- if ((recordOffset < RECORD_SPACE_OFFSET) ||
+ // check that offset points into the record space area.
+ if ((recordOffset < RECORD_SPACE_OFFSET) ||
(recordOffset >= (getPageSize() - CHECKSUM_SIZE)))
{
throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, newIdentity));
- }
+ }
- if (recordOffset > lastRecordOffset)
+ if (recordOffset > lastRecordOffset)
{
- lastRecordOffset = recordOffset;
- lastSlotOnPage = slot;
- }
- }
+ lastRecordOffset = recordOffset;
+ lastSlotOnPage = slot;
+ }
+ }
- bumpRecordCount(localSlotsInUse);
+ bumpRecordCount(localSlotsInUse);
- if (lastSlotOnPage != -1)
+ if (lastSlotOnPage != -1)
{
- // Calculate the firstFreeByte for the page,
+ // Calculate the firstFreeByte for the page,
// and the freeSpace on Page
- firstFreeByte =
+ firstFreeByte =
lastRecordOffset + getTotalSpace(lastSlotOnPage);
- freeSpace -= firstFreeByte - RECORD_SPACE_OFFSET;
- }
+ freeSpace -= firstFreeByte - RECORD_SPACE_OFFSET;
+ }
- if (SanityManager.DEBUG)
+ if (SanityManager.DEBUG)
{
- if ((freeSpace < 0) ||
+ if ((freeSpace < 0) ||
(firstFreeByte > getSlotOffset(slotsInUse - 1)) ||
((firstFreeByte + freeSpace) !=
getSlotOffset(slotsInUse - 1)))
{
- SanityManager.THROWASSERT(
+ SanityManager.THROWASSERT(
"firstFreeByte = " + firstFreeByte
- + ", freeSpace = " + freeSpace
- + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
- + ", slotsInUse = " + localSlotsInUse);
- }
+ + ", freeSpace = " + freeSpace
+ + ", slotOffset = " + (getSlotOffset(slotsInUse - 1))
+ + ", slotsInUse = " + localSlotsInUse);
+ }
- if (localSlotsInUse == 0)
+ if (localSlotsInUse == 0)
{
- SanityManager.ASSERT(
+ SanityManager.ASSERT(
firstFreeByte ==
(getPageSize() - totalSpace - CHECKSUM_SIZE));
}
- }
+ }
- // upgrade issue. Pre 1.5 release, we do not store deletedRowCount
- // therefore, if we are accessing an older database,
- // we need to calculate the deletedRowCount here.
- if (deletedRowCount == -1)
- {
- int count = 0;
- int maxSlot = slotsInUse;
- for (int slot = FIRST_SLOT_NUMBER ; slot < maxSlot; slot++)
- {
- if (isDeletedOnPage(slot))
- count++;
- }
- deletedRowCount = count;
- }
+ // upgrade issue. Pre 1.5 release, we do not store deletedRowCount
+ // therefore, if we are accessing an older database,
+ // we need to calculate the deletedRowCount here.
+ if (deletedRowCount == -1)
+ {
+ int count = 0;
+ int maxSlot = slotsInUse;
+ for (int slot = FIRST_SLOT_NUMBER ; slot < maxSlot; slot++)
+ {
+ if (isDeletedOnPage(slot))
+ count++;
+ }
+ deletedRowCount = count;
+ }
- }
+ }
catch (IOException ioe)
{
- // i/o methods on the byte array have thrown an IOException
+ // i/o methods on the byte array have thrown an IOException
throw dataFactory.markCorrupt(
StandardException.newException(
SQLState.DATA_CORRUPT_PAGE, ioe, newIdentity));
- }
- }
+ }
+ }
/**
@@ -2309,59 +2309,59 @@ public class StoredPage extends CachedPa
* @param recordPortionLength the actual length of record+hdr on page.
* @param reservedSpace the reserved length associated with record.
*
- * @exception StandardException Standard exception policy.
+ * @exception StandardException Standard exception policy.
**/
- private void setSlotEntry(
+ private void setSlotEntry(
int slot,
int recordOffset,
int recordPortionLength,
int reservedSpace)
- throws IOException
- {
- rawDataOut.setPosition(getSlotOffset(slot));
+ throws IOException
+ {
+ rawDataOut.setPosition(getSlotOffset(slot));
- if (SanityManager.DEBUG)
+ if (SanityManager.DEBUG)
{
- if ((recordPortionLength < 0) ||
+ if ((recordPortionLength < 0) ||
(reservedSpace < 0) ||
(recordPortionLength >= getPageSize()) ||
(reservedSpace >= getPageSize()))
{
- SanityManager.THROWASSERT(
- "recordPortionLength and reservedSpace must " +
+ SanityManager.THROWASSERT(
+ "recordPortionLength and reservedSpace must " +
"be > 0, and < page size."
- + " slot = " + slot
- + ", in use = " + slotsInUse
- + ", recordOffset = " + recordOffset
- + ", recordPortionLength = " + recordPortionLength
- + ", reservedSpace = " + reservedSpace);
- }
+ + " slot = " + slot
+ + ", in use = " + slotsInUse
+ + ", recordOffset = " + recordOffset
+ + ", recordPortionLength = " + recordPortionLength
+ + ", reservedSpace = " + reservedSpace);
+ }
- if (recordOffset < (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE))
+ if (recordOffset < (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE))
{
- SanityManager.THROWASSERT(
+ SanityManager.THROWASSERT(
"Record offset must be after the page header."
- + " slot = " + slot
- + ", in use = " + slotsInUse
- + ", recordOffset = " + recordOffset
- + ", recordPortionLength = " + recordPortionLength
- + ", reservedSpace = " + reservedSpace);
- }
- }
-
- if (slotFieldSize == SMALL_SLOT_SIZE)
- {
- logicalDataOut.writeShort(recordOffset);
[... 9033 lines stripped ...]