当我运行写入谷歌云数据存储的数据流作业时,有时我会看到指标显示我有一个或两个 datastoreRpcErrors
:
由于这些数据存储写入通常包含一批 key ,我想知道在 RpcError 的情况下,是否会自动发生一些重试。如果没有,处理这些情况的好方法是什么?
最佳答案
tl;dr:默认情况下 datastoreRpcErrors
将自动使用 5 次重试。
我深入研究了datastoreio
的代码在光束 python sdk 中。看起来最终的实体突变是通过 DatastoreWriteFn()
批量刷新的。
# Flush the current batch of mutations to Cloud Datastore.
_, latency_ms = helper.write_mutations(
self._datastore, self._project, self._mutations,
self._throttler, self._update_rpc_stats,
throttle_delay=_Mutate._WRITE_BATCH_TARGET_LATENCY_MS/1000)
RPCError 被 helper
中的 write_mutations
中的这段代码捕获。 ; commit
方法有一个装饰器@retry.with_exponential_backoff
;并且默认重试次数设置为5; retry_on_rpc_error
定义了具体的 RPCError
和 SocketError
触发重试的原因。
for mutation in mutations:
commit_request.mutations.add().CopyFrom(mutation)
@retry.with_exponential_backoff(num_retries=5,
retry_filter=retry_on_rpc_error)
def commit(request):
# Client-side throttling.
while throttler.throttle_request(time.time()*1000):
try:
response = datastore.commit(request)
...
except (RPCError, SocketError):
if rpc_stats_callback:
rpc_stats_callback(errors=1)
raise
...
关于google-cloud-platform - 我应该担心 datastoreRpcErrors 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50455168/