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 2011/02/05 01:27:40 UTC
svn commit: r1067357 -
/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java
Author: mikem
Date: Sat Feb 5 00:27:40 2011
New Revision: 1067357
URL: http://svn.apache.org/viewvc?rev=1067357&view=rev
Log:
DERBY-5002 In case of checksum error, insure correct error reported to user.
Changed the order of sanity page checking to make sure that if there is a
checksum error on reading the page from disk, then it is the error reported.
Before this change certain page inconsistencies would be found before doing
the checksum check and would report different kinds of errors depending on
where the corruption happened on the page. The main error case checksums
try to catch is partially written page where because a derby page is made up
of multiple OS/drive blocks some blocks can make it to disk before others and
in the case of a hardware crash an incomplete page may be written. In this
case, the current derby implementation can not recover from log as it needs
a valid page to look at in order to apply log records. The db must be
recovered from derby backup in this case.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.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=1067357&r1=1067356&r2=1067357&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 Sat Feb 5 00:27:40 2011
@@ -774,18 +774,6 @@ public class StoredPage extends CachedPa
// 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(
- StandardException.newException(
- SQLState.DATA_CORRUPT_PAGE, ioe, newIdentity));
- }
try
{
@@ -849,8 +837,19 @@ public class StoredPage extends CachedPa
throw se;
}
}
-
+ try
+ {
+ readPageHeader();
+ initSlotTable(newIdentity);
+ }
+ catch (IOException ioe)
+ {
+ // i/o methods on the byte array have thrown an IOException
+ throw dataFactory.markCorrupt(
+ StandardException.newException(
+ SQLState.DATA_CORRUPT_PAGE, ioe, newIdentity));
+ }
}
/**
@@ -1092,6 +1091,21 @@ public class StoredPage extends CachedPa
{
try
{
+ if (SanityManager.DEBUG)
+ {
+ if (getRecordOffset(slot) <= 0)
+ {
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "getTotalSpace failed with getRecordOffset(" +
+ slot + ") = " +
+ getRecordOffset(slot) + " must be greater than 0." +
+ "page dump = \n" +
+ toUncheckedString());
+ SanityManager.THROWASSERT(
+ "bad record offset found in getTotalSpace()");
+ }
+ }
+
// A slot entry looks like the following:
// 1st field: offset of the record on the page
// 2nd field: length of the record on the page
@@ -2042,7 +2056,17 @@ public class StoredPage extends CachedPa
{
if (SanityManager.DEBUG)
{
- SanityManager.ASSERT(getRecordOffset(slot) != 0);
+ if (getRecordOffset(slot) <= 0)
+ {
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "getRecordPortionLength failed with getRecordOffset(" +
+ slot + ") = " +
+ getRecordOffset(slot) + " must be greater than 0." +
+ "page dump = \n" +
+ toUncheckedString());
+ SanityManager.THROWASSERT(
+ "bad record offset found in getRecordPortionLength()");
+ }
}
// these reads are always against the page array
@@ -2071,7 +2095,17 @@ public class StoredPage extends CachedPa
{
if (SanityManager.DEBUG)
{
- SanityManager.ASSERT(getRecordOffset(slot) != 0);
+ if (getRecordOffset(slot) <= 0)
+ {
+ SanityManager.DEBUG_PRINT("DEBUG_TRACE",
+ "getReservedCount failed with getRecordOffset(" +
+ slot + ") = " +
+ getRecordOffset(slot) + " must be greater than 0." +
+ "page dump = \n" +
+ toUncheckedString());
+ SanityManager.THROWASSERT(
+ "bad record offset found in getReservedCount");
+ }
}
// these reads are always against the page array
@@ -8044,6 +8078,25 @@ public class StoredPage extends CachedPa
return null;
}
+ public String toUncheckedString()
+ {
+ if (SanityManager.DEBUG)
+ {
+ String str = "---------------------------------------------------\n";
+ str += pageHeaderToString();
+
+ //if (SanityManager.DEBUG_ON("dumpPageImage"))
+ {
+ str += "---------------------------------------------------\n";
+ str += pagedataToHexDump(pageData);
+ str += "---------------------------------------------------\n";
+ }
+ return str;
+ }
+ else
+ return null;
+ }
+
/**
* Provide a hex dump of the data in the in memory version of the page.
* <p>