Connect to the above"Defaultcacheimpl Analysis of Memcache-client-forjava source Analysis", the main analysis Icache another for the memcached cache implementation, focusing on the implementation of the memcached of high-availability capabilities.
Because the underlying access multiplexed the implementation of the Java_memcached-release package, Memcache-client-forjava only made a simple package at the top. This paper focuses on how to carry out the encapsulation in order to improve their design experience. Personally think, Java_memcached-release source reading, more simple and easy than spymemcached. The spymemcached bottom uses nio,selector for reuse. The java_memcached-release uses pool technology for reuse.
To achieve memcached high availability, focus on the following areas
The correspondence between node nodes and key
Data replication between node nodes
Node Heartbeat detection
Cluster meta-configuration information management
Next mainly from the class diagram, data storage, data read 3 aspects of the simple description.
1. Overall class diagram
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/79/wKioL1e_7dPDV295AAFGw5R1I1I393.png "title=" 1.png " alt= "Wkiol1e_7dpdv295aafgw5r1i1i393.png"/>
*config Information: The parsing XML metadata is saved. Resolves the build at initialization time.
Memcachedcachemanager: Manages metadata, provides Imemcachedcache object aggregation, and cluster object relational data.
Memcachedcache: Operation memcached Unified Access Portal.
Memcachedclienthelper: Handling cluster and memcachedclient relationship helper classes
Memcachedclient:danga interface, all memcached operations are delegated to it for processing
Clusterprocessor: Handling node Data replication tasks
2. Start sequence
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/79/wKioL1e_8GXxWyGPAADMKhlIefg930.png "title=" Init.png "alt=" Wkiol1e_8gxxwygpaadmkhliefg930.png "/>
Can be easily divided into 2 parts: 1. Parse XML to *CONFIG;2. Constructs an object by metadata.
3. Put sequence diagram
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/7A/wKiom1e_8NSS5ql2AAEMHxgzZ-I978.png "title=" Put.png "alt=" Wkiom1e_8nss5ql2aaemhxgzz-i978.png "/>
Complete three parts of the work
1) Confirm the target node
2) Save data
3) Add the Data replication task to the queue.
4.get sequence diagram
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/7A/wKiom1e_8e-xgL3DAADSJMABAos190.png "title=" Get.png "alt=" Wkiom1e_8e-xgl3daadsjmabaos190.png "/>
Main work Content
1) two fetches.
2) Note that the second fetch, whether or not to fetch data from other nodes, will differ according to the standby,active mode.
3) Here the Standby mode is not what we understand, and is under a small hole.
Cluster active and standby two modes, the former speed may be slightly slower in some cases (when the key does not exist in any node of the cluster, the active mode will try two nodes to obtain data), but has the data recovery function, the latter is faster, but no data recovery function.
5. Doubts
Public object get (String key) { object result = null; boolean iserror = false; try { result = getcacheclient (Key). get (key); } catch (Memcachedexception ex) { Logger.error (New stringbuilder (Helper.getcachename ()) .append (" cluster get error"), ex); isError = true; } if (Result == null && helper.hascluster ()) if (iserror | | helper.getclustermode (). equals &nbSP; (memcachedclientclusterconfig.cluster_mode_active)) { List<memcachedclient> caches = helper.getclustercache (); for (memcachedclient cache : caches) { if (Getcacheclient (key). Equals ( Cache)) continue; try { try { result = cache.get (Key); } catch (Memcachedexception ex) { logger.error (New stringbuilder (Helper.getcachename ()) .append (" cluster get error"), ex); continue; } // Recover downtime nodes in a timely manner //only to judge another backup machine, not many times to judge, to prevent inefficiency if (Helper.getclustermode () .equals (Memcachedclientclusterconfig.cluster _mode_active) && result != null) { Object[] commands = new Object[]{CacheCommand.RECOVER,key,result}; addcommandtoqueue (commands); } break; } catch (exception e) { logger.error (New StringBuilder ( Helper.getcachename ()) .append (" cluster get error"), E); } } } return result;}
6. Other
Of course, also provides the statistics, restores the function, does not say.
This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1843007
Memcache-client-forjava source code Analysis of Memcachedcachemanager