未验证 提交 193dcc8d 编写于 作者: C chenjian 提交者: GitHub

fix BOS file existence judgement bug (#1022)

* chore: fix typo

* chore: update dependencies

* fix: error when same tags in one chart in scalar page

* fix bos exists judgement bug

* contrain the renew token case
Co-authored-by: NPeter Pan <littlepanzh@gmail.com>
Co-authored-by: Nwuzewu <wuzewu@baidu.com>
上级 f7af2157
...@@ -397,6 +397,9 @@ class BosFileSystem(object): ...@@ -397,6 +397,9 @@ class BosFileSystem(object):
bucket_name, object_key = get_object_info(filename) bucket_name, object_key = get_object_info(filename)
if not self.exists(filename): if not self.exists(filename):
init_data = b'' init_data = b''
# Two cases will come here
# 1. the file not exist, then we need to create the file
# 2. sts token invalid in self.exists, we should renew the token, and continue to write
try: try:
self.bos_client.append_object( self.bos_client.append_object(
bucket_name=bucket_name, bucket_name=bucket_name,
...@@ -404,15 +407,23 @@ class BosFileSystem(object): ...@@ -404,15 +407,23 @@ class BosFileSystem(object):
data=init_data, data=init_data,
content_md5=content_md5(init_data), content_md5=content_md5(init_data),
content_length=len(init_data)) content_length=len(init_data))
except (exception.BceServerError, exception.BceHttpClientError): except (exception.BceServerError, exception.BceHttpClientError) as e:
self.renew_bos_client_from_server() if bucket_name == 'visualdl-server': # only sts token from visualdl-server, we can renew automatically
self.bos_client.append_object( self.renew_bos_client_from_server()
bucket_name=bucket_name, # we should add a judgement for case 2
key=object_key, try:
data=init_data, self.bos_client.get_object_meta_data(bucket_name, object_key)
content_md5=content_md5(init_data), except exception.BceError:
content_length=len(init_data)) # the file not exists, then create the file
return self.bos_client.append_object(
bucket_name=bucket_name,
key=object_key,
data=init_data,
content_md5=content_md5(init_data),
content_length=len(init_data))
return
else:
raise e # user defined bos token, we have no idea to renew the token, so throw the exception
content_length = len(file_content) content_length = len(file_content)
try: try:
...@@ -425,18 +436,20 @@ class BosFileSystem(object): ...@@ -425,18 +436,20 @@ class BosFileSystem(object):
content_md5=content_md5(file_content), content_md5=content_md5(file_content),
content_length=content_length, content_length=content_length,
offset=offset) offset=offset)
except (exception.BceServerError, exception.BceHttpClientError): except (exception.BceServerError, exception.BceHttpClientError) as e:
self.renew_bos_client_from_server() if bucket_name == 'visualdl-server': # only sts token from visualdl-server, we can renew automatically
offset = self.get_meta(bucket_name, self.renew_bos_client_from_server()
object_key).metadata.content_length offset = self.get_meta(bucket_name,
self.bos_client.append_object( object_key).metadata.content_length
bucket_name=bucket_name, self.bos_client.append_object(
key=object_key, bucket_name=bucket_name,
data=file_content, key=object_key,
content_md5=content_md5(file_content), data=file_content,
content_length=content_length, content_md5=content_md5(file_content),
offset=offset) content_length=content_length,
offset=offset)
else:
raise e # user defined bos token, we have no idea to renew the token, so throw the exception
self._file_contents_to_add = b'' self._file_contents_to_add = b''
self._file_contents_count = 0 self._file_contents_count = 0
self._start_append_time = time.time() self._start_append_time = time.time()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册