private void updateMemcachedReadInstancesByZone ( ) { for ( ServerGroup serverGroup : memcachedInstancesByServerGroup . keySet ( ) ) { final BooleanProperty isZoneInWriteOnlyMode = writeOnlyFastPropertyMap . get ( serverGroup ) ; if ( isZoneInWriteOnlyMode . get ( ) . booleanValue ( ) ) { if ( memcachedReadInstancesByServerGroup . containsKey ( serverGroup ) ) { EVCacheMetricsFactory . increment ( _appName , null , serverGroup . getName ( ) , _appName + "-" + serverGroup . getName ( ) + "-WRITE_ONLY" ) ; memcachedReadInstancesByServerGroup . remove ( serverGroup ) ; } } else { if ( ! memcachedReadInstancesByServerGroup . containsKey ( serverGroup ) ) { EVCacheMetricsFactory . increment ( _appName , null , serverGroup . getName ( ) , _appName + "-" + serverGroup . getName ( ) + "-READ_ENABLED" ) ; memcachedReadInstancesByServerGroup . put ( serverGroup , memcachedInstancesByServerGroup . get ( serverGroup ) ) ; } } // if we lose over 50% of instances put that zone in writeonly mode. final List < EVCacheClient > clients = memcachedReadInstancesByServerGroup . get ( serverGroup ) ; if ( clients != null && ! clients . isEmpty ( ) ) { final EVCacheClient client = clients . get ( 0 ) ; if ( client != null ) { final EVCacheConnectionObserver connectionObserver = client . getConnectionObserver ( ) ; if ( connectionObserver != null ) { final int activeServerCount = connectionObserver . getActiveServerCount ( ) ; final int inActiveServerCount = connectionObserver . getInActiveServerCount ( ) ; if ( inActiveServerCount > activeServerCount ) { memcachedReadInstancesByServerGroup . remove ( serverGroup ) ; } } } } } if ( memcachedReadInstancesByServerGroup . size ( ) != memcachedFallbackReadInstances . getSize ( ) ) { memcachedFallbackReadInstances = new ServerGroupCircularIterator ( memcachedReadInstancesByServerGroup . keySet ( ) ) ; Map < String , Set < ServerGroup > > readServerGroupByZoneMap = new ConcurrentHashMap < String , Set < ServerGroup > > ( ) ; for ( ServerGroup serverGroup : memcachedReadInstancesByServerGroup . keySet ( ) ) { Set < ServerGroup > serverGroupList = readServerGroupByZoneMap . get ( serverGroup . getZone ( ) ) ; if ( serverGroupList == null ) { serverGroupList = new HashSet < ServerGroup > ( ) ; readServerGroupByZoneMap . put ( serverGroup . getZone ( ) , serverGroupList ) ; } serverGroupList . add ( serverGroup ) ; } Map < String , ServerGroupCircularIterator > _readServerGroupByZone = new ConcurrentHashMap < String , ServerGroupCircularIterator > ( ) ; for ( Entry < String , Set < ServerGroup > > readServerGroupByZoneEntry : readServerGroupByZoneMap . entrySet ( ) ) { _readServerGroupByZone . put ( readServerGroupByZoneEntry . getKey ( ) , new ServerGroupCircularIterator ( readServerGroupByZoneEntry . getValue ( ) ) ) ; } this . readServerGroupByZone = _readServerGroupByZone ; localServerGroupIterator = readServerGroupByZone . get ( _zone ) ; } }
back to the read map .