wuchong commented on a change in pull request #8341: [FLINK-11633][docs-zh]
Translate "Working with state" into Chinese
URL: https://github.com/apache/flink/pull/8341#discussion_r281010399
##########
File path: docs/dev/stream/state/state.zh.md
##########
@@ -703,43 +605,33 @@ checkpointedState =
context.getOperatorStateStore.getListState(descriptor)
{% endhighlight %}
</div>
</div>
-The naming convention of the state access methods contain its redistribution
-pattern followed by its state structure. For example, to use list state with
the
-union redistribution scheme on restore, access the state by using
`getUnionListState(descriptor)`.
-If the method name does not contain the redistribution pattern, *e.g.*
`getListState(descriptor)`,
-it simply implies that the basic even-split redistribution scheme will be used.
-After initializing the container, we use the `isRestored()` method of the
context to check if we are
-recovering after a failure. If this is `true`, *i.e.* we are recovering, the
restore logic is applied.
+调用不同的获取状态对象的接口,会使用不同的状态分配算法。比如 `getUnionListState(descriptor)` 会使用 union
redistribution 算法,
+而 `getListState(descriptor)` 则简单的使用 even-split redistribution 算法。
+
+当初始化好状态对象后,我们通过 `isRestored()` 方法判断是否从之前的故障中恢复回来,如果该方法返回 `true`
则表示从故障中进行恢复,会执行接下来的恢复逻辑。
-As shown in the code of the modified `BufferingSink`, this `ListState`
recovered during state
-initialization is kept in a class variable for future use in
`snapshotState()`. There the `ListState` is cleared
-of all objects included by the previous checkpoint, and is then filled with
the new ones we want to checkpoint.
+正入代码所示,`BufferingSink` 中初始化时,恢复回来的 `ListState` 的所有元素会添加到一个局部变量中,供下次
`snapshotState()` 时使用。
+然后清空 `ListState`,再把当前局部变量中的所有元素写入到 checkpoint 中。
-As a side note, the keyed state can also be initialized in the
`initializeState()` method. This can be done
-using the provided `FunctionInitializationContext`.
+另外,我们同样可以在 `initializeState()` 方法中使用 `FunctionInitializationContext` 初始化 keyed
state。
#### ListCheckpointed
-The `ListCheckpointed` interface is a more limited variant of
`CheckpointedFunction`,
-which only supports list-style state with even-split redistribution scheme on
restore.
-It also requires the implementation of two methods:
+`ListCheckpointed` 接口是 `CheckpointedFunction` 的精简版,仅支持 even-split
redistributuion 的 list state。同样需要实现两个方法:
{% highlight java %}
List<T> snapshotState(long checkpointId, long timestamp) throws Exception;
void restoreState(List<T> state) throws Exception;
{% endhighlight %}
-On `snapshotState()` the operator should return a list of objects to
checkpoint and
-`restoreState` has to handle such a list upon recovery. If the state is not
re-partitionable, you can always
-return a `Collections.singletonList(MY_STATE)` in the `snapshotState()`.
+`snapshotState()` 需要返回一个将写入到 checkpoint 的对象列表,`restoreState`
则需要处理恢复回来的对象列表。如果状态不可切分,
+则可以在 `snapshotState()` 中返回 `Collections.singletonList(MY_STATE)`。
-### Stateful Source Functions
+### 带状态的输入函数
Review comment:
```suggestion
### 带状态的 Source Function
```
Keep Source Function untranslated?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services