RestoreCommitLogsAction.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:nomulus 作者:
/**
 * Restore the contents of one transaction to Datastore.
 *
 * <p>The objects to delete are listed in the {@link CommitLogManifest}, which will be the first
 * object in the iterable. The objects to save follow, each as a {@link CommitLogMutation}. We
 * restore by deleting the deletes and recreating the saves from their proto form. We also save
 * the commit logs themselves back to Datastore, so that the commit log system itself is
 * transparently restored alongside the data.
 *
 * @return the manifest, for use in restoring the {@link CommitLogBucket}.
 */
private CommitLogManifest restoreOneTransaction(PeekingIterator<ImmutableObject> commitLogs) {
  final CommitLogManifest manifest = (CommitLogManifest) commitLogs.next();
  Result<?> deleteResult = deleteAsync(manifest.getDeletions());
  List<Entity> entitiesToSave = Lists.newArrayList(ofy().save().toEntity(manifest));
  while (commitLogs.hasNext() && commitLogs.peek() instanceof CommitLogMutation) {
    CommitLogMutation mutation = (CommitLogMutation) commitLogs.next();
    entitiesToSave.add(ofy().save().toEntity(mutation));
    entitiesToSave.add(EntityTranslator.createFromPbBytes(mutation.getEntityProtoBytes()));
  }
  saveRaw(entitiesToSave);
  try {
    deleteResult.now();
  } catch (Exception e) {
    retrier.callWithRetry(
        () -> deleteAsync(manifest.getDeletions()).now(), RuntimeException.class);
  }
  return manifest;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号