From commits-return-13442-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Sat Jun 16 06:48:53 2012 Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2C5C9019 for ; Sat, 16 Jun 2012 06:48:53 +0000 (UTC) Received: (qmail 15363 invoked by uid 500); 16 Jun 2012 06:48:53 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 15257 invoked by uid 500); 16 Jun 2012 06:48:52 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 15248 invoked by uid 99); 16 Jun 2012 06:48:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2012 06:48:52 +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; Sat, 16 Jun 2012 06:48:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1FBC92388860; Sat, 16 Jun 2012 06:48:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1350869 - in /jackrabbit/branches/2.4/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java test/java/org/apache/jackrabbit/core/data/ConsistencyCheckerImplTest.java Date: Sat, 16 Jun 2012 06:48:31 -0000 To: commits@jackrabbit.apache.org From: unico@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120616064831.1FBC92388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: unico Date: Sat Jun 16 06:48:30 2012 New Revision: 1350869 URL: http://svn.apache.org/viewvc?rev=1350869&view=rev Log: JCR-3267 fix bundles immediately during checkbundle in order to avoid lost update problem; also add unit test for consistency fixing (backport) Added: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ConsistencyCheckerImplTest.java - copied unchanged from r1350221, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ConsistencyCheckerImplTest.java Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java?rev=1350869&r1=1350868&r2=1350869&view=diff ============================================================================== --- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java (original) +++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/ConsistencyCheckerImpl.java Sat Jun 16 06:48:30 2012 @@ -76,8 +76,6 @@ public class ConsistencyCheckerImpl { boolean fix, Set reports, String lostNFoundId) throws RepositoryException { int count = 0; - Collection modifications = new ArrayList(); - Set orphaned = new HashSet(); NodeId lostNFound = null; if (fix && lostNFoundId != null) { @@ -116,9 +114,7 @@ public class ConsistencyCheckerImpl { error(id.toString(), "No bundle found for id '" + id + "'"); } else { - checkBundleConsistency(id, bundle, fix, - modifications, lostNFound, orphaned, - reports); + checkBundleConsistency(id, bundle, fix, lostNFound, reports); count++; if (count % 1000 == 0 && listener == null) { @@ -174,8 +170,7 @@ public class ConsistencyCheckerImpl { + id + "'"); } } else { - checkBundleConsistency(id, bundle, fix, modifications, - lostNFound, orphaned, reports); + checkBundleConsistency(id, bundle, fix, lostNFound, reports); if (recursive) { for (NodePropBundle.ChildNodeEntry entry : bundle @@ -197,49 +192,6 @@ public class ConsistencyCheckerImpl { } } - // repair collected broken bundles - if (fix && !modifications.isEmpty()) { - info(null, pm + ": Fixing " + modifications.size() - + " inconsistent bundle(s)..."); - for (NodePropBundle bundle : modifications) { - try { - info(bundle.getId().toString(), pm + ": Fixing bundle '" - + bundle.getId() + "'"); - bundle.markOld(); // use UPDATE instead of INSERT - pm.storeBundle(bundle); - pm.evictBundle(bundle.getId()); - } catch (ItemStateException e) { - error(bundle.getId().toString(), pm - + ": Error storing fixed bundle: " + e); - } - } - } - - if (fix && lostNFoundId != null && !orphaned.isEmpty()) { - // do we have things to add to "lost+found"? - try { - NodePropBundle lfBundle = pm.loadBundle(lostNFound); - if (lfBundle == null) { - error(lostNFoundId, "specified 'lost+found' node does not exist"); - } else if (!NameConstants.NT_UNSTRUCTURED.equals(lfBundle - .getNodeTypeName())) { - error(lostNFoundId, "specified 'lost+found' node is not of type nt:unstructered"); - } else { - lfBundle.markOld(); - for (NodeId orphan : orphaned) { - String nodeName = orphan + "-" - + System.currentTimeMillis(); - lfBundle.addChildNodeEntry(NF.create("", nodeName), - orphan); - } - pm.storeBundle(lfBundle); - pm.evictBundle(lfBundle.getId()); - } - } catch (Exception ex) { - error(null, "trying orphan adoption", ex); - } - } - log.info(pm + ": checked " + count + " bundles."); return count; @@ -255,13 +207,8 @@ public class ConsistencyCheckerImpl { * the bundle to check * @param fix * if true, repair things that can be repaired - * @param modifications - * if fix == true, collect the repaired - * {@linkplain NodePropBundle bundles} here */ - private void checkBundleConsistency(NodeId id, NodePropBundle bundle, - boolean fix, Collection modifications, - NodeId lostNFoundId, Set orphaned, Set reports) { + private void checkBundleConsistency(NodeId id, NodePropBundle bundle, boolean fix, NodeId lostNFoundId, Set reports) { // log.info(name + ": checking bundle '" + id + "'"); // skip all virtual nodes @@ -354,7 +301,7 @@ public class ConsistencyCheckerImpl { for (NodePropBundle.ChildNodeEntry entry : missingChildren) { bundle.getChildNodeEntries().remove(entry); } - modifications.add(bundle); + fixBundle(bundle); } // check parent reference @@ -374,10 +321,18 @@ public class ConsistencyCheckerImpl { + "'"; log.error(message); addMessage(reports, id, message); - orphaned.add(id); - if (lostNFoundId != null) { + if (fix && lostNFoundId != null) { + // add a child to lost+found + NodePropBundle lfBundle = pm.loadBundle(lostNFoundId); + lfBundle.markOld(); + String nodeName = id + "-" + System.currentTimeMillis(); + lfBundle.addChildNodeEntry(NF.create("", nodeName), id); + pm.storeBundle(lfBundle); + pm.evictBundle(lostNFoundId); + + // set lost+found parent bundle.setParentId(lostNFoundId); - modifications.add(bundle); + fixBundle(bundle); } } } else { @@ -403,18 +358,18 @@ public class ConsistencyCheckerImpl { + parentId + "'"; log.error(message); addMessage(reports, id, message); - - int l = (int) System.currentTimeMillis(); - int r = new Random().nextInt(); - int n = l + r; - String nodeName = Integer.toHexString(n); - parentBundle.addChildNodeEntry( - NF.create("{}" + nodeName), id); - log.info("NodeState '" + id - + "' adds itself to its parent node '" - + parentId + "' with a new name '" + nodeName - + "'"); - modifications.add(parentBundle); + if (fix) { + int l = (int) System.currentTimeMillis(); + int r = new Random().nextInt(); + int n = l + r; + String nodeName = Integer.toHexString(n); + parentBundle.addChildNodeEntry(NF.create("{}" + nodeName), id); + log.info("NodeState '" + id + + "' adds itself to its parent node '" + + parentId + "' with a new name '" + nodeName + + "'"); + fixBundle(parentBundle); + } } } else { return; @@ -486,4 +441,15 @@ public class ConsistencyCheckerImpl { listener.error(id, message); } } + + private void fixBundle(NodePropBundle bundle) { + try { + log.info(pm + ": Fixing bundle '" + bundle.getId() + "'"); + bundle.markOld(); // use UPDATE instead of INSERT + pm.storeBundle(bundle); + pm.evictBundle(bundle.getId()); + } catch (ItemStateException e) { + log.error(pm + ": Error storing fixed bundle: " + e); + } + } }