Exemplo n.º 1
0
 /**
  * Get file node model connection name which is related with node id
  * @param $id
  * @return array|false
  */
 public static function getFileNodeConfig($id)
 {
     $nodes = static::get(static::KEY_STORAGE_NODES);
     foreach ($nodes as $item) {
         if ($item['id'] == $id) {
             return $item;
         }
     }
     FileException::pop("The connection for storage node {$id} is not set. Check the configuration field {" . static::KEY_STORAGE_NODES . "}");
 }
Exemplo n.º 2
0
 /**
  * Make load balance and get storage node id
  * pick a storage node randomly
  * @return int
  */
 public function getNodeId()
 {
     if (Config::get(Config::KEY_LOAD_BALANCE_STRICT)) {
         $this->getUsedNodes();
         $nodeId = $this->pickStrictly();
     } else {
         $nodeId = $this->pickOneNodeRandomly();
     }
     if ($nodeId === false) {
         FileException::pop('Fail to select storage node.');
     }
     return $nodeId;
 }
Exemplo n.º 3
0
 /**
  * Remove file
  * @param $id string file id
  * @return bool|null
  */
 public function remove($id)
 {
     // wait if the file is locked
     if (!$this->locker->lock($id)) {
         FileException::pop("The file \"{$id}\" is locked. Try later.");
     }
     $fileMeta = new FileMeta();
     $fileContainer = new FileContainer();
     $fileContainer->addHandler(new StorageNodeHandler());
     $fileContainer->addHandler(new NodeMetaHandler());
     $fileMeta->setFileContainer($fileContainer);
     $fileMeta->remove($id);
     $fileContainer->dump();
     $this->locker->unlock($id);
     return true;
 }
Exemplo n.º 4
0
 private function getChunkSize()
 {
     if (!$this->chunkSize) {
         $this->chunkSize = Config::get(Config::KEY_FILE_CHUNK_SIZE);
     }
     if (!$this->chunkSize) {
         FileException::pop('File chunk size is not set');
     }
     return $this->chunkSize;
 }