Beispiel #1
0
 public function Init()
 {
     $ShmList = ShmConfig::getStorageAvailableAddress($this->config);
     //从内存中获得可用列表
     if (empty($ShmList)) {
         //内存中没有,可能ping脚本没启,直接用配置
         foreach ($this->config['nodes'] as $value) {
             $list[] = $value['master'];
         }
     } else {
         $list = $ShmList;
     }
     $this->targets = $list;
     //和cache不一样,失效后是false不能剔除
 }
Beispiel #2
0
 public function Init()
 {
     $this->hash = new ConsistentHash();
     $this->MasterOrSlave = $ShmList = ShmConfig::getCacheAvailableAddress($this->config);
     //从内存中获得可用列表
     $list = array();
     if (empty($ShmList)) {
         //内存中没有,可能ping脚本没启,直接用配置
         foreach ($this->config['nodes'] as $node) {
             $list[] = $node['master'];
         }
     } else {
         foreach ($ShmList as $node) {
             //false已过滤,主/从在逻辑上都hash主的值
             $list[] = $node['master']['target'];
         }
     }
     $this->hash->addTargets($list);
     //传入逻辑结点列表
 }
Beispiel #3
0
 public static function getStorageAvailableAddress($config)
 {
     if (self::$UseMem) {
         ShmConfig::configStorage($config);
         $nodes = shm_get_var(self::getShmFd(), self::SHM_STORAGE_KEY);
         $ret = array();
         foreach ((array) $nodes['nodes'] as $node) {
             if (!isset($node['use'])) {
                 //ping没启动
                 break;
             }
             if ($node['use']) {
                 $ret[] = $node[$node['use']]['target'];
             } else {
                 //use=false证明m-s都失效了
                 $ret[] = false;
             }
         }
         return $ret;
     } else {
         //不用内存,直接用配置
         self::$StorageConfig = $config;
         return array();
     }
 }