You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2016/11/22 11:59:10 UTC

[GitHub] brooklyn-server pull request #453: BROOKLYN-352: fix ConcurrentModification ...

GitHub user aledsage opened a pull request:

    https://github.com/apache/brooklyn-server/pull/453

    BROOKLYN-352: fix ConcurrentModification in getAllEntitiesInApplication

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aledsage/brooklyn-server BROOKLYN-352

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/453.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #453
    
----
commit 00c8f1c659b5a23e94f62ba023231beb07b5796e
Author: Aled Sage <al...@gmail.com>
Date:   2016-11-22T11:55:59Z

    BROOKLYN-352: fix ConcurrentModification in getAllEntitiesInApplication

----


---
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.
---

[GitHub] brooklyn-server pull request #453: BROOKLYN-352: fix ConcurrentModification ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/453


---
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.
---

[GitHub] brooklyn-server pull request #453: BROOKLYN-352: fix ConcurrentModification ...

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/453#discussion_r89106124
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalEntityManager.java ---
    @@ -212,13 +213,41 @@ public EntityTypeRegistry getEntityTypeRegistry() {
     
         @Override
         public Iterable<Entity> getAllEntitiesInApplication(Application application) {
    +        // To fix https://issues.apache.org/jira/browse/BROOKLYN-352, we need to synchronize on
    +        // preRegisteredEntitiesById and preManagedEntitiesById while iterating over them (because
    +        // they are synchronizedMaps). entityProxiesById is a ConcurrentMap, so no need to 
    +        // synchronize on that.
    +        // Only synchronize on one at a time, to avoid the risk of deadlock.
    +        
             Predicate<Entity> predicate = EntityPredicates.applicationIdEqualTo(application.getId());
    -        Iterable<Entity> allentities = Iterables.concat(preRegisteredEntitiesById.values(), preManagedEntitiesById.values(), entityProxiesById.values());
    -        Iterable<Entity> result = Iterables.filter(allentities, predicate);
    -        return ImmutableSet.copyOf(Iterables.transform(result, new Function<Entity, Entity>() {
    -            @Override public Entity apply(Entity input) {
    -                return Entities.proxy(input);
    -            }}));
    +        Set<Entity> result = Sets.newLinkedHashSet();
    +        
    +        synchronized (preRegisteredEntitiesById) {
    --- End diff --
    
    Maybe it would be worth making `preRegisteredEntitiesById` and `preManagedEntitiesById` private, and providing access to them with code like this loop, but put into a `protected` method.  At the moment it's not impossible that some derived class in future would again use one of the maps but forget the synchronization. 


---
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.
---