From oak-issues-return-60948-archive-asf-public=cust-asf.ponee.io@jackrabbit.apache.org Wed Apr 4 17:18:06 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 BAC0718067C for ; Wed, 4 Apr 2018 17:18:05 +0200 (CEST) Received: (qmail 48329 invoked by uid 500); 4 Apr 2018 15:18: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 48317 invoked by uid 99); 4 Apr 2018 15:18: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 15:18: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 5D5DEC013E for ; Wed, 4 Apr 2018 15:18: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 pYRbzcMN1epY for ; Wed, 4 Apr 2018 15:18:03 +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 53AD65FC04 for ; Wed, 4 Apr 2018 15:18:02 +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 399B7E0F06 for ; Wed, 4 Apr 2018 15:18:01 +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 8354825621 for ; Wed, 4 Apr 2018 15:18:00 +0000 (UTC) Date: Wed, 4 Apr 2018 15:18:00 +0000 (UTC) From: "Francesco Mari (JIRA)" To: oak-issues@jackrabbit.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (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: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OAK-7388?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Francesco Mari updated OAK-7388: -------------------------------- Fix Version/s: 1.9.0 > MergingNodeStateDiff may recreate nodes that were previously removed to resolve 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.9.0, 1.10 > > > {{MergingNodeStateDiff}} might behave incorrectly when the resolution of a conflict involves the deletion of the conflicting node. I spotted this issue in a use case that can be expressed by the following code. > {noformat} > NodeState root = EmptyNodeState.EMPTY_NODE; > NodeState withProperty; > { > NodeBuilder builder = root.builder(); > builder.child("c").setProperty("foo", "bar"); > withProperty = builder.getNodeState(); > } > NodeState withUpdatedProperty; > { > NodeBuilder builder = withProperty.builder(); > builder.child("c").setProperty("foo", "baz"); > withUpdatedProperty = builder.getNodeState(); > } > NodeState withRemovedChild; > { > NodeBuilder builder = withProperty.builder(); > builder.child("c").remove(); > withRemovedChild = builder.getNodeState(); > } > NodeBuilder mergedBuilder = withUpdatedProperty.builder(); > withRemovedChild.compareAgainstBaseState(withProperty, new ConflictAnnotatingRebaseDiff(mergedBuilder)); > NodeState merged = ConflictHook.of(DefaultThreeWayConflictHandler.OURS).processCommit( > mergedBuilder.getBaseState(), > mergedBuilder.getNodeState(), > CommitInfo.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 issue, I figured out that the problem is caused by the following steps. > # {{MergingNodeStateDiff#childNodeAdded}} is invoked because of {{:conflicts}}. This eventually results in the deletion of the conflicting child node. > # {{MergingNodeStateDiff#childNodeChanged}} is called because in {{ModifiedNodeState#compareAgainstBaseState}} the children are compared with the {{!=}} 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 that was detected as modified. > # {{MemoryNodeBuilder#hasChildNode}} correctly returns {{false}}, because the child was removed in step 1. The return value of {{false}} triggers the next step. > # {{MemoryNodeBuilder#setChildNode(java.lang.String)}} is invoked in order to setup a new, empty child node. > In other words, the snippet above can be rewritten like the following. > {noformat} > NodeState root = EmptyNodeState.EMPTY_NODE; > NodeState withProperty; > { > NodeBuilder builder = root.builder(); > builder.child("c").setProperty("foo", "bar"); > withProperty = builder.getNodeState(); > } > NodeState withUpdatedProperty; > { > NodeBuilder builder = withProperty.builder(); > builder.child("c").setProperty("foo", "baz"); > withUpdatedProperty = builder.getNodeState(); > } > NodeState withRemovedChild; > { > NodeBuilder builder = withProperty.builder(); > builder.child("c").remove(); > withRemovedChild = builder.getNodeState(); > } > NodeBuilder mergedBuilder = withUpdatedProperty.builder(); > // As per MergingNodeStateDiff.childNodeAdded() > mergedBuilder.child("c").remove(); > // As per ModifiedNodeState#compareAgainstBaseState() > if (withUpdatedProperty.getChildNode("c") != withRemovedChild.getChildNode("c")) { > // As per MergingNodeStateDiff.childNodeChanged() > mergedBuilder.child("c"); > } > NodeState merged = mergedBuilder.getNodeState(); > assertFalse(merged.hasChildNode("c")); > {noformat} > The end result is that {{MergingNodeStateDiff}} inadvertently adds the node that was removed in order to resolve a conflict. -- This message was sent by Atlassian JIRA (v7.6.3#76005)