本文介绍了ZooKeeper快照文件是否足以恢复状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在了解ZooKeeper,并正在寻找备份存储在ZooKeeper中的数据的选项. ZooKeeper写入两个数据文件,快照和事务日志.人们经常提到快照是模糊的",需要在它们上重播事务日志以获取最新状态.

I am learning about ZooKeeper and looking at options to back up data stored in ZooKeeper. ZooKeeper writes two data files, snapshot and transaction log. It is often mentioned that snapshots are "fuzzy" and need a transaction log to be replayed over them to get an up to date state.

对于观察者"而言,没有任何事务日志都保留在磁盘上.如果我要获取由观察者(或没有事务日志的领导者/关注者)编写的快照,并将其放入新的独立ZooKeeper中,则可以保证ZooKeeper的状态与将快照写入磁盘时的状态相同?

In the case of Observers, no transaction log is persisted to disk. If I were to take the snapshot written by an observer (or leader/follower without the transaction log), and placed it into a new standalone ZooKeeper, would ZooKeeper's state be guaranteed to be the same as it was when the snapshot was written to disk?

换句话说,要将ZooKeeper备份到其当前状态,您需要快照和事务日志.如果我只满意备份快照的时间,那么仅快照就足够了吗?

In other words, to perform a backup of ZooKeeper to its current state, you need the snapshot and transaction log. If I was content with backing up only to the time the snapshot was taken, would the snapshot alone be enough?

推荐答案

否.快照文件不足以保证返回到先前的状态.实际上,快照文件在任何时间点甚至都不能代表树的状态.

No. The snapshot file is not enough to guarantee a return to a previous state. In fact, the snapshot file may not even represent the state of the tree at any point in time.

摘自O'Reilly ZooKeeper的书:

From the O'Reilly ZooKeeper book:

让我们看一个例子来说明这一点.假设数据树只有两个znode:/z和/z'.最初,/z和/z'的数据均为整数1.现在考虑以下步骤序列:

Let’s walk through an example to illustrate this. Say that a data tree has only two znodes: /z and /z'. Initially, the data of both /z and /z' is the integer 1 Now consider the following sequence of steps:

  1. 创建快照.
  2. 序列化并将/z = 1写入快照.
  3. 将/z的数据设置为2(事务T).
  4. 将/z'的数据设置为2(事务Tʹ).
  5. 序列化/z'= 2到快照.

此快照包含/z = 1和/z'=2.但是,从未有两个znode的值像这样的时间点.但是,这不是问题,因为服务器重播事务.它用快照启动时已提交的最后一个事务标记每个快照,称为TS.如果服务器最终加载快照,它将在TS之后重播事务日志中的所有事务.在这种情况下,它们是T和Tʹ.在快照顶部重播T和Tʹ之后,服务器获得/z = 2和/z'= 2,这是有效状态.

This snapshot contains /z = 1 and /z' = 2. However, there has never been a point intime in which the values of both znodes were like that. This is not a problem, though,because the server replays transactions. It tags each snapshot with the last transaction that has been committed when the snapshot starts—call it TS. If the server eventually loads the snapshot, it replays all transactions in the transaction log that come after TS. In this case, they are T and Tʹ . After replaying T and Tʹ on top of the snapshot, the server obtains /z = 2 and /z' = 2, which is a valid state.

您可能会在ZooKeeper数据结构中发现模糊快照是可以接受的,但是如果您要保证有效的树,请同时获取快照和事务日志.

这篇关于ZooKeeper快照文件是否足以恢复状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 15:52