/** * make local file * @param $fileInfo InputFile * @return string */ public function localize($fileInfo) { $file = Config::get(Config::KEY_LOCALIZE_DIR) . '/' . $fileInfo->id; if (file_exists($file)) { unlink($file); } foreach ($fileInfo->chunkIds as $chunkId) { $content = $this->fileNode->get($chunkId); FileUtil::appendStringToFile($content, $file); } return $file; }
/** * 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; }
public function __construct() { $this->model = (new BaseModel())->setConnection(Config::get(Config::KEY_FILE_META_CONNECTION))->setCollection(Config::get(Config::KEY_FILE_META_COLLECTION)); }
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; }
private function getLockerFile($fid) { return Config::get(Config::KEY_LOCKER_FILES_DIR) . '/' . $this->prefix . $fid; }