00001 /* Copyright (C) GridGain Systems. All Rights Reserved. */ 00002 00003 /* _________ _____ __________________ _____ 00004 * __ ____/___________(_)______ /__ ____/______ ____(_)_______ 00005 * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ 00006 * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / 00007 * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ 00008 */ 00009 00010 #ifndef GRIDCLIENTPARTITIONEDAFFINITY__HPP_INCLUDED 00011 #define GRIDCLIENTPARTITIONEDAFFINITY__HPP_INCLUDED 00012 00013 #include <vector> 00014 #include <string> 00015 #include <memory> 00016 00017 #include "gridgain/gridclientdataaffinity.hpp" 00018 #include "gridgain/impl/gridconsistenhashimpl.hpp" 00019 #include "gridgain/impl/gridclienttopology.hpp" 00020 00021 class GridClientNode; 00022 00024 typedef std::function<GridClientVariant (const GridClientNode&)> GridHashIdResolver; 00025 00051 class GridClientPartitionAffinity: public GridClientDataAffinity { 00052 public: 00054 static const int DFLT_PARTITION_CNT = 10000; 00055 00057 static const int DFLT_BACKUP_CNT = 1; 00058 00060 static const int DFLT_REPLICA_CNT = 128; 00061 00066 static const char* DFLT_REPLICA_CNT_ATTR_NAME; 00067 00071 GridClientPartitionAffinity(); 00072 00074 virtual ~GridClientPartitionAffinity(); 00075 00084 virtual TGridClientNodePtr getNode(const TNodesSet& nodes, const GridClientHasheableObject& key); 00085 00094 int getDefaultReplicas() const; 00095 00104 void setDefaultReplicas(int replicas); 00105 00111 int getKeyBackups() const; 00112 00118 void setKeyBackups(int backups); 00119 00132 int getPartitions() const; 00133 00139 void setPartitions(int parts); 00140 00148 const TGridClientNodePredicatePtr getBackupFilter(); 00149 00157 void setBackupFilter(const TGridClientNodePredicatePtr backupFilter); 00158 00165 std::string getReplicaCountAttributeName() const; 00166 00173 void setReplicaCountAttributeName(const std::string& attrName); 00174 00180 GridHashIdResolver getHashIdResolver() const; 00181 00187 void setHashIdResolver(GridHashIdResolver& hashIdResolver); 00188 00193 void checkRemoved(const GridClientNode& node); 00194 00199 int getReplicas(const GridClientNode& n); 00200 00201 private: 00208 void add(const GridClientNode& node, int replicas); 00209 00218 TGridClientNodePtr findNode(const GridClientUuid& id, const TNodesSet& nodes) const; 00219 00221 GridClientConsistentHashImpl nodeHash; 00222 00224 int parts; 00225 00227 int replicas; 00228 00230 int backups; 00231 00233 std::string attrName; 00234 00236 std::set<GridClientUuid> addedNodes; 00237 00239 TGridClientNodePredicatePtr backupFilter; 00240 00242 TGridClientNodePredicatePtr primaryFilter; 00243 00245 GridHashIdResolver hashIdResolver; 00246 00248 boost::mutex mux; 00249 }; 00250 00251 #endif // GRIDCLIENTPARTITIONEDAFFINITY__INCLUDED
1.7.1