Return-Path: X-Original-To: apmail-curator-dev-archive@minotaur.apache.org Delivered-To: apmail-curator-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 84B4918A44 for ; Wed, 10 Feb 2016 13:48:35 +0000 (UTC) Received: (qmail 75120 invoked by uid 500); 10 Feb 2016 13:48:35 -0000 Delivered-To: apmail-curator-dev-archive@curator.apache.org Received: (qmail 75072 invoked by uid 500); 10 Feb 2016 13:48:35 -0000 Mailing-List: contact dev-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list dev@curator.apache.org Received: (qmail 74995 invoked by uid 99); 10 Feb 2016 13:48:35 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Feb 2016 13:48:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 936571A010D for ; Wed, 10 Feb 2016 13:48:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.28 X-Spam-Level: * X-Spam-Status: No, score=1.28 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=jordanzimmerman-com.20150623.gappssmtp.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id HsugHnMD_RmW for ; Wed, 10 Feb 2016 13:48:32 +0000 (UTC) Received: from mail-yk0-f181.google.com (mail-yk0-f181.google.com [209.85.160.181]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 7944F429FF for ; Wed, 10 Feb 2016 13:48:32 +0000 (UTC) Received: by mail-yk0-f181.google.com with SMTP id z7so7526984yka.3 for ; Wed, 10 Feb 2016 05:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jordanzimmerman-com.20150623.gappssmtp.com; s=20150623; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to; bh=qBTWq/Z55h8/k11YVZWYFfx8sd4mW9GeJCiFxWsjy7c=; b=OSZqzG0MjYAP5DUPV3yeuSs60BcGxo89v25w0Zm4FhyNJOHmUMqjSR9Etilr4B8bHv 7m75Z+1lVdImhvTao8yNxQ6/3HqrJAxPgutGQfNZsfXzd4/V/utuSTTpu67FSoxBugmQ wutwuKzIUwGT59mfDwbc9Fe4wroP243VJpvYX8qziXzv2PJuakHhqr6pAw56sEpS37br BFcmrDfHu/S/qOj8FWm9zrnb2q5UZ0vx2oLkk/LKOAYoPUn7IilZwlY7dF/PqUcSN1fB j3As42IzHgaw2EC48XWyqqlzULSamY7AsKY0rG0fHi9o9U1P+kIFhbmE/viIqi9xcqFg B9uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-type:message-id:mime-version :subject:date:references:to:in-reply-to; bh=qBTWq/Z55h8/k11YVZWYFfx8sd4mW9GeJCiFxWsjy7c=; b=ZlOctIPKS292ntHoOhfCv0MS5fqSSS3picEdx92B43L7M0K/Ctve+C2trHO4oT2fAq tGNYdhWOgpBW1JSPIBlkwUZbsIL6kxW8KhB/1yIEtHVdYeCZu2IDYr3wXj8oM6qqFzDl g84ix0rqAaMTv3L1WgWHUBg1E6h0SAePM/eYMPjNrGq6TQoDFTHr9T6zmkgwFRdDpcze kyZN8Nz+Zx0tTafuLo8xVF7punbH9yQr7VGa3ullvrLcobaDftPKqjhLM0+Km32IahZ4 9sd3F+o6dZgiUHk4X7te4MJJL763xdxsbR7sBzSmHRabs/dYSyKjEpyUZ/4fl85m/6Ax 005A== X-Gm-Message-State: AG10YOR8HIyV2moVJ+ebLB+XZMfqeSDqww4nMybFllAamBWpqPR76f2jv8j4d0BVqRsGCQ== X-Received: by 10.37.59.193 with SMTP id i184mr5411182yba.27.1455112112083; Wed, 10 Feb 2016 05:48:32 -0800 (PST) Received: from [10.0.1.67] ([186.188.195.79]) by smtp.gmail.com with ESMTPSA id i142sm2559675ywg.12.2016.02.10.05.48.30 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 05:48:31 -0800 (PST) From: Jordan Zimmerman Content-Type: multipart/alternative; boundary="Apple-Mail=_BA4C62E6-639A-4B78-BC52-402A541F3CE8" Message-Id: <8C219932-05A7-49B4-99F7-732D431FC784@jordanzimmerman.com> Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Subject: Re: NamespaceWatcher hashCode and equals still bugging me Date: Wed, 10 Feb 2016 08:48:27 -0500 References: <82086D54-9F8D-43DF-90B8-A84B5789EE3D@jordanzimmerman.com> To: Scott Blum , dev@curator.apache.org In-Reply-To: X-Mailer: Apple Mail (2.3112) --Apple-Mail=_BA4C62E6-639A-4B78-BC52-402A541F3CE8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Scott - are you OK with a release or should I wait for more discussion = on this issue? -Jordan > On Feb 9, 2016, at 1:50 PM, Scott Blum wrote: >=20 > Sounds like a job for weak hash map. Will follow up later with more >=20 > On Feb 9, 2016 12:01 PM, "Jordan Zimmerman" = > wrote: > > So.... taking a step back, what was underlying motivation for the = hashCode / equality changes? IE, what's the bigger problem we were = trying to solve? >=20 > Before this change, we were maintaining a map from Watcher to = NamespaceWatcher so that we could track/remove the wrapped watcher. This = is necessary due to this guarantee of ZooKeeper: >=20 > = http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html#sc_WatchGu= arantees = >=20 > "if the same watch object is registered for an exists and a getData = call for the same file and that file is then deleted, the watch object = would only be invoked once with the deletion notification for the = file.=E2=80=9D >=20 > Given that NamespaceWatcher is an internal wrapper, Curator needs to = generate the same NamespaceWatcher for a given client=E2=80=99s = Watcher/CuratorWatcher. The map handled this. In the past, this was = difficult to manage and had potential memory leaks if the map wasn=E2=80=99= t managed correctly. It occurred to me that the map isn=E2=80=99t needed = if NamespaceWatcher could have equality/hash values the same as the = Watcher that it wraps. My testing proved this. >=20 > Thoughts? >=20 > -Jordan >=20 >=20 > > On Feb 9, 2016, at 11:49 AM, Scott Blum > wrote: > > > > Hi guys, > > > > I'm a practical guy, not a purist, but the 3.0 implementations of = NamespaceWatcher.hashCode() and equals() are bothering me. The reason I = care is that I want to avoid subtle bugs cropping up. > > > > So here's the problem. > > > > 1) equals() is not reflexive between NamespaceWatcher and Watcher > > > > Assuming you have a NamespaceWatcher nw wrapping a Watcher w, the = following code might or might not work: > > > > container.add(nw) > > container.remove(w) > > > > It depends on whether the underlying container ultimately does = "nw.equals(w)" or "w.equals(nw)". Set.contains() would have the same = problem. > > > > 2) hashCode() and equals() inconsistent with each other > > > > Because nw.hashCode() !=3D w.hashCode(), lookups in a hashSet or = hashMap will practically never work except by luck. > > > > hashSet.put(nw) > > hashSet.contains(w) > > > > Most of the time this will return false, except in the exact case = where nw and w happen to have hashCodes that map into the same bucket, = and the equality check is done the "right" order. > > > > > > So.... taking a step back, what was underlying motivation for the = hashCode / equality changes? IE, what's the bigger problem we were = trying to solve? > > > > Scott > > >=20 --Apple-Mail=_BA4C62E6-639A-4B78-BC52-402A541F3CE8--