コード例 #1
0
 private function _gen_zk_node()
 {
     $node_frame = new MetaNode();
     $val = array('val' => 'unit test');
     $node_value = $node_frame->serialize($val);
     $bad_node = pack("C2S1L1", 0, 64, 0, 0);
     return array('good' => $node_value, 'bad' => $bad_node);
 }
コード例 #2
0
 /**
  * 更新一个meta entry的值
  * @param string $entry_path : 节点相对路径(相对于meta)
  * @param stdobject $value  : stdclass格式的value
  * @return node value array on success or false on failure
  */
 public function update_entry($entry_path, &$new_value, $version)
 {
     if (false === $this->_inited) {
         BigpipeLog::warning("[%s:%u][%s][uninited]", __FILE__, __LINE__, __FUNCTION__);
         return false;
     }
     if ($version < 0) {
         // zookeeper中version == -1表示强制更新节点
         // 这里我们不允许有这种操作
         BigpipeLog::warning("[%s:%u][%s][invalid version][ver:%d]", __FILE__, __LINE__, __FUNCTION__, $version);
         return false;
     }
     $full_path = sprintf('%s/meta/%s', $this->_root_path, $entry_path);
     if (false === $this->_zk_connection->exists($full_path)) {
         BigpipeLog::warning("[%s:%u][%s][fail to find node under meta][node path:%s]", __FILE__, __LINE__, __FUNCTION__, $full_path);
         return false;
     }
     // serialize value
     $frame = new MetaNode();
     $node_value = $frame->serialize($new_value);
     if (false === $node_value) {
         BigpipeLog::warning("[%s:%u][%s][fail to serialize value][path:%s]", __FILE__, __LINE__, __FUNCTION__, $full_path);
         return false;
     }
     // update value in node
     if (false === $this->_zk_connection->update($full_path, $node_value, $version)) {
         BigpipeLog::warning("[%s:%u][%s][fail to upddate value][path:%s]", __FILE__, __LINE__, __FUNCTION__, $full_path);
         return false;
     }
     BigpipeLog::notice("[%s:%u][%s][update value in a node][path:%s]", __FILE__, __LINE__, __FUNCTION__, $full_path);
     return true;
 }