Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 88970 invoked from network); 8 Feb 2011 16:45:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Feb 2011 16:45:40 -0000 Received: (qmail 5832 invoked by uid 500); 8 Feb 2011 16:45:40 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 5815 invoked by uid 500); 8 Feb 2011 16:45:38 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 5808 invoked by uid 99); 8 Feb 2011 16:45:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 16:45:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 16:45:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B5AD623889BF; Tue, 8 Feb 2011 16:45:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1068474 - /db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java Date: Tue, 08 Feb 2011 16:45:14 -0000 To: derby-commits@db.apache.org From: mikem@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110208164514.B5AD623889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mikem Date: Tue Feb 8 16:45:14 2011 New Revision: 1068474 URL: http://svn.apache.org/viewvc?rev=1068474&view=rev Log: DERBY-5002 In case of checksum error, insure correct error reported to user. backported change #1067357 from trunk to 10.6 branch, some manual merging required. 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/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java?rev=1068474&r1=1068473&r2=1068474&view=diff ============================================================================== --- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java (original) +++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/store/raw/data/StoredPage.java Tue Feb 8 16:45:14 2011 @@ -774,19 +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 { validateChecksum(newIdentity); @@ -850,8 +837,19 @@ public class StoredPage extends CachedPa } } - - } + 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)); + } + } /** * Validate the check sum on the page. @@ -1090,6 +1088,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 @@ -2037,8 +2050,18 @@ 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 ArrayInputStream lrdi = rawDataIn; @@ -2066,8 +2089,18 @@ 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 ArrayInputStream lrdi = rawDataIn; @@ -7972,6 +8005,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. *