You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@usergrid.apache.org by snoopdave <gi...@git.apache.org> on 2016/05/16 20:27:40 UTC

[GitHub] usergrid pull request: Retries on Management App init, plus cachin...

GitHub user snoopdave opened a pull request:

    https://github.com/apache/usergrid/pull/524

    Retries on Management App init, plus caching

    First stab at improving the startup process so that, if we are unable to lookup or create the management app we fail fast and if we are able to, then we cache the value for later times when we may temporarily unable to look it up.
    
    - Attempt to get or create management app in CpEntityManagerFactory constructor
       - With configurable retries
       - Throw RuntimeException retry count exceeded
       - Cache Management App
    
    - CpEntityManager uses that new cache to get management app
    
    https://issues.apache.org/jira/browse/USERGRID-1283


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

    $ git pull https://github.com/snoopdave/usergrid usegrid-1283-mgmt-app-init

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

    https://github.com/apache/usergrid/pull/524.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 #524
    
----
commit e0c0c875271cda47f9baf9072f029a92921fd1be
Author: Dave Johnson <sn...@apache.org>
Date:   2016-05-16T20:10:07Z

    Move the initial get of management app to the CpEntityManagerFactory with retries, and caching for the management app itself.

----


---
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] usergrid pull request: Improvements to management app / startup lo...

Posted by snoopdave <gi...@git.apache.org>.
Github user snoopdave commented on the pull request:

    https://github.com/apache/usergrid/pull/524#issuecomment-221589680
  
    renamed this branch to usergrid-1283-mgmt-app-init


---
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] usergrid pull request: Retries on Management App init, plus cachin...

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

    https://github.com/apache/usergrid/pull/524#discussion_r64041172
  
    --- Diff: stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java ---
    @@ -142,12 +141,66 @@ public CpEntityManagerFactory( final CassandraService cassandraService, final Co
             this.connectionService = injector.getInstance( ConnectionService.class );
             this.indexSchemaCacheFactory = injector.getInstance( IndexSchemaCacheFactory.class );
     
    -        //this line always needs to be last due to the temporary cicular dependency until spring is removed
    +        // this line always needs to be last due to the temporary circular dependency until spring is removed
     
             this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
                 getManagementEntityManager() );
     
    +        int entityManagerCacheSize = 100;
    +        try {
    +            entityManagerCacheSize = Integer.parseInt(
    +                cassandraService.getProperties().getProperty( ENTITY_MANAGER_CACHE_SIZE, "100" ));
    +        } catch ( Exception e ) {
    +            logger.error("Error parsing " + ENTITY_MANAGER_CACHE_SIZE + " using " + entityManagerCacheSize, e );
    +        }
    +
    +        entityManagers = CacheBuilder.newBuilder()
    +            .maximumSize(entityManagerCacheSize)
    +            .build(new CacheLoader<UUID, EntityManager>() {
    +
    +            public EntityManager load( UUID appId ) { // no checked exception
    +
    +                // get entity manager and ensure it can get its own application
    +
    +                EntityManager entityManager = _getEntityManager( appId );
    +                Application app = null;
    +                Exception exception = null;
    +                try {
    +                    app = entityManager.getApplication();
    +                } catch (Exception e) {
    +                    exception = e;
    +                }
     
    +                // the management app is a special case
    +
    +                if ( CpNamingUtils.MANAGEMENT_APPLICATION_ID.equals( appId ) ) {
    +
    +                    if ( app != null ) {
    +
    +                        // we successfully fetched up the management app, cache it for a rainy day
    +                        managementAppEntityManager = entityManager;
    +
    +                    } else if ( managementAppEntityManager != null ) {
    +
    +                        // failed to fetch management app, use cached one
    +                        entityManager = managementAppEntityManager;
    +
    +                    } else {
    +
    +                        // fetch failed and we have nothing cached, we must be bootstrapping
    +                        logger.info("managementAppEntityManager is null, bootstrapping in progress");
    --- End diff --
    
    Exception is caught above when calling _getEntityManager in the case that it returns null and NPE would be thrown on getApplication().  At this point, it seems like we'd be returning a null value to the cache's load() method.  Is this intended behavior?


---
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] usergrid pull request: Improvements to management app / startup lo...

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

    https://github.com/apache/usergrid/pull/524


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