Skip to content

Commit

Permalink
fix: 修复检查存储可用的时候大小不同的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiu2b2t committed Dec 20, 2024
1 parent d8ce134 commit 8254e74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions core/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ async def _check_available(self):
res = False
try:
res = await asyncio.wait_for(self.__check_available(storage), 10)
except asyncio.TimeoutError:
if storage in self.available_storages:
self.available_storages.remove(storage)
except:
logger.ttraceback("storage.error.check_available", type=storage.type, path=storage.path, url=getattr(storage, "url", None))
if storage in self.available_storages:
Expand All @@ -94,6 +91,7 @@ async def _check_available(self):
self.check_available.release()
else:
self.check_available.acquire()
logger.twarning("storage.warning.unavailable", storages=len(self.storages))

async def __check_available(self, storage: storages.iStorage):
file = MeasureFile(
Expand All @@ -104,6 +102,12 @@ async def __check_available(self, storage: storages.iStorage):
file,
io.BytesIO(CHECK_FILE_CONTENT.encode("utf-8")),
)
elif await storage.get_size(file) != len(CHECK_FILE_CONTENT):
await storage.delete_file(file)
await storage.write_file(
file,
io.BytesIO(CHECK_FILE_CONTENT.encode("utf-8")),
)
return await storage.get_size(file) == len(CHECK_FILE_CONTENT)

def add_storage(self, storage: storages.iStorage):
Expand Down
3 changes: 2 additions & 1 deletion i18n/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"cluster.warning.measure_storage": "尝试重定向至存储测速失败,已自动切换至本地测速",
"database.error.unable.to.decompress": "无法解压数据库,数据:%{data}",
"storage.error.check_available": "存储 [${type}] [${path}] [${url}] 检查可用性出错,原因:",
"dashboard.info.new_version": "当前版本 [${current}] 发现新版本 [${latest}]"
"dashboard.info.new_version": "当前版本 [${current}] 发现新版本 [${latest}]",
"storage.warning.unavailable": "当前无可用存储,已加载的存储 [${storages}] 个"
}

0 comments on commit 8254e74

Please sign in to comment.