Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-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 2A47218D83 for ; Fri, 25 Mar 2016 15:37:53 +0000 (UTC) Received: (qmail 54072 invoked by uid 500); 25 Mar 2016 15:37:53 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 54037 invoked by uid 500); 25 Mar 2016 15:37:53 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 54026 invoked by uid 99); 25 Mar 2016 15:37:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Mar 2016 15:37:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AF186DFBAF; Fri, 25 Mar 2016 15:37:52 +0000 (UTC) From: neykov To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request: Fix DynamicMultiGroup rebind Content-Type: text/plain Message-Id: <20160325153752.AF186DFBAF@git1-us-west.apache.org> Date: Fri, 25 Mar 2016 15:37:52 +0000 (UTC) Github user neykov commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/82#discussion_r57455466 --- Diff: core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java --- @@ -119,7 +125,36 @@ public void rebind() { super.rebind(); if (rescan == null) { - connectScanner(); + // The rescan can (in a different thread) cause us to remove the empty groups - i.e. remove + // it as a child, and unmanage it. That is dangerous during rebind, because the rebind-thread + // may concurrently (or subsequently) be initialising that child entity. It has caused + // rebind errors where the child's entity-rebind complains in setParent() that it was + // "previouslyOwned". Therefore we defer registering/executing our scanner until rebind is + // complete, so all entities are reconstituted. + // We don't worry about other managementNodeStates, such as standby: if we were told to + // rebind then we are free to fully initialise ourselves. But we do double-check that we + // are still managed before trying to execute. + + getExecutionContext().execute(new Runnable() { + @Override public void run() { + LOG.debug("Deferring scanner for {} until management context initialisation complete", DynamicMultiGroupImpl.this); + while (!isRebindComplete()) { + Time.sleep(100); // avoid thrashing + } + LOG.debug("Connecting scanner for {}", DynamicMultiGroupImpl.this); + connectScanner(); + } + private boolean isRebindComplete() { + // TODO Want to determine if finished rebinding (either success or fail is fine). + // But not a clean way to do this that works for both unit tests and live server?! + // * In RebindTestFixtureWithApp tests, mgmt.getHighAvailabilityManager().getNodeState() + // always returns INITIALIZING. + // * The rebind metrics is a hack, and feels very risky for HOT_STANDBY nodes that + // may have executed the rebind code multiple times. --- End diff -- `!mgmt().getRebindManager().isAwaitingInitialRebind()`should do the job. Tests might need an additional `((LocalManagementContext)getManagementContext()).noteStartupComplete();` See `HaHotCheckTest` for details. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---