From oak-issues-return-60941-archive-asf-public=cust-asf.ponee.io@jackrabbit.apache.org Wed Apr 4 15:16:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 5DF6C18064F for ; Wed, 4 Apr 2018 15:16:05 +0200 (CEST) Received: (qmail 59176 invoked by uid 500); 4 Apr 2018 13:16:04 -0000 Mailing-List: contact oak-issues-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-issues@jackrabbit.apache.org Received: (qmail 59165 invoked by uid 99); 4 Apr 2018 13:16:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Apr 2018 13:16:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 02782C00E0 for ; Wed, 4 Apr 2018 13:16:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id LnF-NSlOMj5r for ; Wed, 4 Apr 2018 13:16:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 2704A5FB37 for ; Wed, 4 Apr 2018 13:16:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4D06BE00A6 for ; Wed, 4 Apr 2018 13:16:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 12A2425612 for ; Wed, 4 Apr 2018 13:16:00 +0000 (UTC) Date: Wed, 4 Apr 2018 13:16:00 +0000 (UTC) From: =?utf-8?Q?Michael_D=C3=BCrig_=28JIRA=29?= To: oak-issues@jackrabbit.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (OAK-7388) MergingNodeStateDiff may recreate nodes that were previously removed to resolve conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OAK-7388?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D164254= 86#comment-16425486 ]=20 Michael D=C3=BCrig commented on OAK-7388: ------------------------------------ Excellent analysis! The first snipped of code should be made into a unit te= st. And of course we should try to fix this! > MergingNodeStateDiff may recreate nodes that were previously removed to r= esolve conflicts > -------------------------------------------------------------------------= ---------------- > > Key: OAK-7388 > URL: https://issues.apache.org/jira/browse/OAK-7388 > Project: Jackrabbit Oak > Issue Type: Improvement > Components: core > Reporter: Francesco Mari > Assignee: Francesco Mari > Priority: Major > Fix For: 1.10 > > > {{MergingNodeStateDiff}} might behave incorrectly when the resolution of = a conflict involves the deletion of the conflicting node. I spotted this is= sue in a use case that can be expressed by the following code. > {noformat} > NodeState root =3D EmptyNodeState.EMPTY_NODE; > NodeState withProperty; > { > NodeBuilder builder =3D root.builder(); > builder.child("c").setProperty("foo", "bar"); > withProperty =3D builder.getNodeState(); > } > NodeState withUpdatedProperty; > { > NodeBuilder builder =3D withProperty.builder(); > builder.child("c").setProperty("foo", "baz"); > withUpdatedProperty =3D builder.getNodeState(); > } > NodeState withRemovedChild; > { > NodeBuilder builder =3D withProperty.builder(); > builder.child("c").remove(); > withRemovedChild =3D builder.getNodeState(); > } > NodeBuilder mergedBuilder =3D withUpdatedProperty.builder(); > withRemovedChild.compareAgainstBaseState(withProperty, new ConflictAnnota= tingRebaseDiff(mergedBuilder)); > NodeState merged =3D ConflictHook.of(DefaultThreeWayConflictHandler.OURS)= .processCommit( > =09mergedBuilder.getBaseState(),=20 > =09mergedBuilder.getNodeState(),=20 > =09CommitInfo.EMPTY > ); > assertFalse(merged.hasChildNode("c")); > {noformat} > The assertion at the end of the code fails becauuse `merged` actually has= a child node named `c`, and `c` is an empty node. After digging into the i= ssue, I figured out that the problem is caused by the following steps. > # {{MergingNodeStateDiff#childNodeAdded}} is invoked because of {{:confli= cts}}. This eventually results in the deletion of the conflicting child nod= e. > # {{MergingNodeStateDiff#childNodeChanged}} is called because in {{Modifi= edNodeState#compareAgainstBaseState}} the children are compared with the {{= !=3D}} operator instead of using {{Object#equals}}. > # {{org.apache.jackrabbit.oak.spi.state.NodeBuilder#child}} is called in = order to setup a new {{MergingNodeStateDiff}} to descend into the subtree t= hat was detected as modified. > # {{MemoryNodeBuilder#hasChildNode}} correctly returns {{false}}, because= the child was removed in step 1. The return value of {{false}} triggers th= e next step. > # {{MemoryNodeBuilder#setChildNode(java.lang.String)}} is invoked in orde= r to setup a new, empty child node. > In other words, the snippet above can be rewritten like the following. > {noformat} > NodeState root =3D EmptyNodeState.EMPTY_NODE; > NodeState withProperty; > { > NodeBuilder builder =3D root.builder(); > builder.child("c").setProperty("foo", "bar"); > withProperty =3D builder.getNodeState(); > } > NodeState withUpdatedProperty; > { > NodeBuilder builder =3D withProperty.builder(); > builder.child("c").setProperty("foo", "baz"); > withUpdatedProperty =3D builder.getNodeState(); > } > NodeState withRemovedChild; > { > NodeBuilder builder =3D withProperty.builder(); > builder.child("c").remove(); > withRemovedChild =3D builder.getNodeState(); > } > NodeBuilder mergedBuilder =3D withUpdatedProperty.builder(); > // As per MergingNodeStateDiff.childNodeAdded() > mergedBuilder.child("c").remove(); > // As per ModifiedNodeState#compareAgainstBaseState() > if (withUpdatedProperty.getChildNode("c") !=3D withRemovedChild.getChildN= ode("c")) { > // As per MergingNodeStateDiff.childNodeChanged() > mergedBuilder.child("c"); > } > NodeState merged =3D mergedBuilder.getNodeState(); > assertFalse(merged.hasChildNode("c")); > {noformat} > The end result is that {{MergingNodeStateDiff}} inadvertently adds the no= de that was removed in order to resolve a conflict. -- This message was sent by Atlassian JIRA (v7.6.3#76005)