예제 #1
0
 /**
  * we will only loop until we see that the position number we are currently
  * looping with is the same as the position number with which we started.
  * if the two position values are equal then that means we have cycled on the
  * whole node list and we should not continue.  with each iteration we log an error
  * before moving on to the next node in the list
  */
 protected function sendDelete()
 {
     $forwardInfo = $this->getForwardInfo();
     if ($forwardInfo) {
         // disconnect before we make another request
         WebDFS_Helper::disconnectClient();
         if (isset($this->params['propagateDelete']) && !$this->params['propagateDelete']) {
             return;
         }
         $errNo = 0;
         $origPosition = $forwardInfo['position'];
         $curl = curl_init();
         $headers = array();
         $loops = 0;
         $nodeLength = count($this->getTargetNodes());
         do {
             if ($loops >= $nodeLength) {
                 $this->errorLog('noNodeFound', __FUNCTION__, __FILE__, __LINE__);
                 break;
             }
             $loops++;
             $headers[0] = self::HEADER_REPLICA . ': ' . $forwardInfo['replica'];
             $headers[1] = self::HEADER_POSITION . ': ' . $forwardInfo['position'];
             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
             curl_setopt($curl, CURLOPT_TIMEOUT, 10);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
             curl_setopt($curl, CURLOPT_URL, $forwardInfo['forwardUrl']);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($curl);
             $errNo = curl_errno($curl);
             $info = curl_getinfo($curl);
             if ($errNo || $info['http_code'] >= 400) {
                 $this->errorLog('deleteSend', $forwardInfo['replica'], $forwardInfo['forwardUrl'], curl_errno($curl), curl_error($curl), $response);
                 $forwardInfo = $this->getForwardInfo($forwardInfo['replica'], $forwardInfo['position']);
             }
         } while (($errNo || $info['http_code'] >= 400) && $forwardInfo && $origPosition != $forwardInfo['position']);
         curl_close($curl);
     }
 }
예제 #2
0
파일: Move.php 프로젝트: shanehill00/webdfs
 protected function sendDataForMove()
 {
     $filePath = $this->finalPath;
     $forwardInfo = $this->getForwardInfo();
     if ($forwardInfo) {
         $fh = fopen($filePath, "rb");
         $size = filesize($filePath);
         rewind($fh);
         $errNo = 0;
         $origPosition = $forwardInfo['position'];
         $curl = curl_init();
         $headers = array();
         // disconnect before we make another request
         WebDFS_Helper::disconnectClient();
         $loops = 0;
         $nodeLength = count($this->getTargetNodes());
         do {
             if ($loops >= $nodeLength) {
                 $this->errorLog('noNodeFound', __FUNCTION__, __FILE__, __LINE__);
                 break;
             }
             $loops++;
             $headers[0] = self::HEADER_REPLICA . ': ' . $forwardInfo['replica'];
             $headers[1] = self::HEADER_POSITION . ': ' . $forwardInfo['position'];
             $headers[2] = self::HEADER_MOVE_CONTEXT . ': create';
             $headers[3] = self::HEADER_MOVE_CONFIG_INDEX . ': ' . $this->params['moveConfigIndex'];
             $headers[4] = self::HEADER_CONFIG_INDEX . ': ' . $this->params['configIndex'];
             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
             curl_setopt($curl, CURLOPT_UPLOAD, true);
             curl_setopt($curl, CURLOPT_INFILE, $fh);
             curl_setopt($curl, CURLOPT_INFILESIZE, $size);
             curl_setopt($curl, CURLOPT_TIMEOUT, 10);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "MOVE");
             curl_setopt($curl, CURLOPT_URL, $forwardInfo['forwardUrl']);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($curl);
             $errNo = curl_errno($curl);
             $info = curl_getinfo($curl);
             if ($errNo || $info['http_code'] >= 400) {
                 $this->errorLog('sendDataForMove', $forwardInfo['replica'], $forwardInfo['forwardUrl'], curl_errno($curl), curl_error($curl), $response);
                 $forwardInfo = $this->getForwardInfo($forwardInfo['replica'], $forwardInfo['position']);
             } else {
                 $this->debugLog('sendDataForMove', $forwardInfo['replica'], $forwardInfo['forwardUrl']);
             }
         } while (($errNo || $info['http_code'] >= 400) && $origPosition != $forwardInfo['position'] && $forwardInfo);
         curl_close($curl);
         fclose($fh);
     }
 }
예제 #3
0
파일: Put.php 프로젝트: shanehill00/webdfs
 protected function forwardDataForPut()
 {
     $targetNodes = $this->getTargetNodes();
     if ($this->iAmATarget()) {
         // disconnect the client before we start
         // replicating since we are a storage node
         // and already have the file
         WebDFS_Helper::disconnectClient($targetNodes, $this->params['fileName']);
         $this->sendDataForPut($this->finalPath);
     } else {
         $this->sendDataForPut($this->config['inputStream']);
         // unlink( $this->tmpPath );
         // disconnect only after we have
         // uploaded the file to the first
         // storage target node
         WebDFS_Helper::disconnectClient($targetNodes, $this->params['fileName']);
     }
 }