Zakelly commented on code in PR #26312:
URL: https://github.com/apache/flink/pull/26312#discussion_r2020517479


##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -25,40 +25,25 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-# Working with State V2 (New APIs)
+# 使用 State V2 (New APIs)
+本章节您将了解 Flink 用于编写有状态程序的新 API,要了解有状态流处理背后的概念,请参阅[Stateful Stream
+Processing]({{< ref "docs/concepts/stateful-stream-processing" >}})。
 
-In this section you will learn about the new APIs that Flink provides for 
writing
-stateful programs. Please take a look at [Stateful Stream
-Processing]({{< ref "docs/concepts/stateful-stream-processing" >}})
-to learn about the concepts behind stateful stream processing.
-
-The new state API is designed to be more flexible than the previous API. User 
can perform
-asynchronous state operations, thus making it more powerful and more efficient.
-The asynchronous state access is essential for the state backend to be able to 
handle
-large state sizes and to be able to spill to remote file systems when 
necessary.
-This is called the 'disaggregated state management'. For more information 
about this,
-please see [Disaggregated State Management]({{< ref 
"docs/ops/state/disaggregated_state" >}}).
+新的 state API 比以前的 API 更灵活,用户可以通过新的 API 使用异步状态操作,这使得新的 API 更加强大有效。

Review Comment:
   ```suggestion
   新的 state API 比以前的 API 更灵活,用户可以通过新的 API 使用异步状态操作,是一套更强大有效的 API。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -25,40 +25,25 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-# Working with State V2 (New APIs)
+# 使用 State V2 (New APIs)
+本章节您将了解 Flink 用于编写有状态程序的新 API,要了解有状态流处理背后的概念,请参阅[Stateful Stream
+Processing]({{< ref "docs/concepts/stateful-stream-processing" >}})。
 
-In this section you will learn about the new APIs that Flink provides for 
writing
-stateful programs. Please take a look at [Stateful Stream
-Processing]({{< ref "docs/concepts/stateful-stream-processing" >}})
-to learn about the concepts behind stateful stream processing.
-
-The new state API is designed to be more flexible than the previous API. User 
can perform
-asynchronous state operations, thus making it more powerful and more efficient.
-The asynchronous state access is essential for the state backend to be able to 
handle
-large state sizes and to be able to spill to remote file systems when 
necessary.
-This is called the 'disaggregated state management'. For more information 
about this,
-please see [Disaggregated State Management]({{< ref 
"docs/ops/state/disaggregated_state" >}}).
+新的 state API 比以前的 API 更灵活,用户可以通过新的 API 使用异步状态操作,这使得新的 API 更加强大有效。
+异步 state 访问对“存算分离”来说是必要的,即令状态后端支持大状态和在必要时将文件溢出到远程文件系统的能力。更多关于

Review Comment:
   ```suggestion
   异步 state 访问对存算分离来说是必要的,即令状态后端支持大状态时将文件溢出到远程文件系统的能力。更多关于
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的

Review Comment:
   ```suggestion
   但两个`asyncGet`的完成顺序不能保证。因此我们无法保证两个 `StateFuture` 后续步骤的执行顺序,也就无法确定元素 A 和 元素 B 的
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -79,143 +64,101 @@ KeyedStream<WordCount> keyed = words
 
 {{< top >}}
 
-## Using Keyed State V2
-
-Unlike the previous state API, the new state API is designed for asynchronous 
state access.
-Each type of state gives two versions of the API: synchronous and 
asynchronous. The synchronous
-API is a blocking API that waits for the state access to complete. The 
asynchronous API is
-non-blocking and returns a `StateFuture` that will be completed when the state 
access
-is done. After that a callback or following logic will be invoked (if any).
-The asynchronous API is more efficient and should be used whenever possible.
-It is highly **not** recommended to mixed synchronous and asynchronous state 
access in the same
-user function.
-
-The keyed state interfaces provide access to different types of state that are 
all scoped to
-the key of the current input element. This means that this type of state can 
only be used
-on a `KeyedStream`, which can be created via `stream.keyBy(…)` in Java. And 
then most importantly,
-the keyed stream needs to be enabled for asynchronous state access by calling 
`enableAsyncState()`.
-The new API set are only available on `KeyedStream` with `enableAsyncState()` 
invoked.
-
-Now, we will look at the different types of state available, and then we will 
see
-how they can be used in a program. Since the synchronous APIs are identical 
with the original APIs,
-We only focus on the asynchronous ones here. 
-
-### The Return Values
-
-First of all, we should get familiar with the return value of those 
asynchronous state access methods.
-
-`StateFuture<T>` is a future that will be completed with the result of the 
state access.
-The return bype is T. It provides multiple methods to handle the result, 
listed as:
-* `StateFuture<Void> thenAccept(Consumer<T>)`: This method takes a `Consumer` 
that will be called with the result
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the
-  `Consumer` is done.
-* `StateFuture<R> thenApply(Function<T, R>)`: This method takes a `Function` 
that will be called with the result
-  when the state access is done. The return value of the function will be the 
result of the following
-  `StateFuture`, which will be finished when the `Function` is done.
-* `StateFuture<R> thenCompose(Function<T, StateFuture<R>>)`: This method takes 
a `Function` that will
-  be called with the result when the state access is done. The return value of 
the function should be
-  a `StateFuture<R>`, which is exposed to the invoker of `thenCompose` as a 
return value.
-  The `StateFuture<R>` will be finished when the inner `StateFuture<R>` of 
`Function` is finished.
-* `StateFuture<R> thenCombine(StateFuture<U>, BiFunction<T, U, R>)`: This 
method takes another `StateFuture` and a
-  `BiFunction` that will be called with the results of both `StateFuture`s 
when they are done. The return
-  value of the `BiFunction` will be the result of the following `StateFuture`, 
which will be finished when
-  the `BiFunction` is done.
-
-Those methods are similar to the corresponding ones of the 
`CompletableFuture`. Besides these methods,
-keep in mind that `StateFuture` does not provide a `get()` method to block the 
current thread until the
-state access is done. This is because blocking the current thread may cause 
recursive blocking. The 
-`StateFuture<T>` also provides conditional version of `thenAccept`, 
`thenApply`, `thenCompose` and `thenCombine`,
-which is for the case that the state access is done and the following logic 
will be split into two branches
-based on the result of the state access. The conditional version of those 
methods are `thenConditionallyAccept`,
-`thenConditionallyApply`, `thenConditionallyCompose` and 
`thenConditionallyCombine`.
-
-`StateIterator<T>` is an iterator that can be used to iterate over the 
elements of a state. It provides
-the following methods:
-* `boolean isEmpty()` : A synchronous method returns a `true` if the iterator 
has no elements, and `false` otherwise.
-* `StateFuture<Void> onNext(Consumer<T>)` : This method takes a `Consumer` 
that will be called with the next element
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the `Consumer` is done.
-  Also, a function version of `onNext` is provided, which is 
`StateFuture<Collection<R>> onNext(Function<T, R>)`. This method
-  takes a `Function` that will be called with the next element when the state 
access is done. The return value of the function 
-  will be collected and returned as a collection of the following 
`StateFuture`, which will be
-  finished when the `Function` is done.
-
-We also provide a `StateFutureUtils` class that contains some utility methods 
to handle `StateFuture`s.
-These methods are:
-* `StateFuture<T> completedFuture(T)`: This method returns a completed 
`StateFuture` with the given value. This is
-useful when you want to return a constant value in a `thenCompose` method for 
further processing.
-* `StateFuture<Void> completedVoidFuture()`: This method returns a completed 
`StateFuture` with `null` value. 
-A void value version of `completedFuture`.
-* `StateFuture<Collection<T>> combineAll(Collection<StateFuture<T>>)` : This 
method takes a collection of `StateFuture`s
-and returns a `StateFuture` that will be completed when all the input 
`StateFuture`s are completed. The result of the
-returned `StateFuture` is a collection of the results of the input 
`StateFuture`s. This is useful when you want to
-combine the results of multiple `StateFuture`s.
-* `StateFuture<Iterable<T>> toIterable(StateFuture<StateIterator<T>>)` : This 
method takes a `StateFuture` of `StateIterator`
-and returns a `StateFuture` of `Iterable`. The result of the returned 
`StateFuture` is an `Iterable` that contains all
-the elements of the `StateIterator`. This is useful when you want to convert a 
`StateIterator` to an `Iterable`.
-There is no good reason to do so, since this may disable the capability of 
lazy loading. Only useful when the further 
-calculation depends on the whole data from the iterator.
-
-
-### State Primitives
-
-The available state primitives are:
-
-* `ValueState<T>`: This keeps a value that can be updated and
-retrieved (scoped to key of the input element as mentioned above, so there 
will possibly be one value
-for each key that the operation sees). The value can be set using 
`asyncUpdate(T)` and retrieved using
-`StateFuture<T> asyncValue()`.
-
-* `ListState<T>`: This keeps a list of elements. You can append elements and 
retrieve an `StateIterator`
-over all currently stored elements. Elements are added using `asyncAdd(T)` or 
`asyncAddAll(List<T>)`,
-the Iterable can be retrieved using `StateFuture<StateIterator<T>> asyncGet()`.
-You can also override the existing list with `asyncUpdate(List<T>)`
-
-* `ReducingState<T>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. The interface is similar to `ListState` but elements added 
using
-`asyncAdd(T)` are reduced to an aggregate using a specified `ReduceFunction`.
-
-* `AggregatingState<IN, OUT>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. Contrary to `ReducingState`, the aggregate type may be 
different from the type
-of elements that are added to the state. The interface is the same as for 
`ListState` but elements
-added using `asyncAdd(IN)` are aggregated using a specified 
`AggregateFunction`.
-
-* `MapState<UK, UV>`: This keeps a list of mappings. You can put key-value 
pairs into the state and
-retrieve an `StateIterator` over all currently stored mappings. Mappings are 
added using `asyncPut(UK, UV)` or
-`asyncPutAll(Map<UK, UV>)`. The value associated with a user key can be 
retrieved using `asyncGet(UK)`.
-The iterable views for mappings, keys and values can be retrieved using 
`asyncEntries()`,
-`asyncKeys()` and `asyncValues()` respectively. You can also use 
`asyncIsEmpty()` to check whether
-this map contains any key-value mappings.
-
-All types of state also have a method `asyncClear()` that clears the state for 
the currently
-active key, i.e. the key of the input element.
-
-It is important to keep in mind that these state objects are only used for 
interfacing
-with state. The state is not necessarily stored inside but might reside on 
disk or somewhere else.
-The second thing to keep in mind is that the value you get from the state
-depends on the key of the input element. So the value you get in one 
invocation of your
-user function can differ from the value in another invocation if the keys 
involved are different.
-
-To get a state handle, you have to create a `StateDescriptor`. This holds the 
name of the state
-(as we will see later, you can create several states, and they have to have 
unique names so
-that you can reference them), the type of the values that the state holds, and 
possibly
-a user-specified function, such as a `ReduceFunction`. Depending on what type 
of state you
-want to retrieve, you create either a `ValueStateDescriptor`, a 
`ListStateDescriptor`, 
-an `AggregatingStateDescriptor`, a `ReducingStateDescriptor`, or a 
`MapStateDescriptor`.
-To differentiate between the previous state APIs, you should use the 
`StateDescriptor`s under the
-`org.apache.flink.api.common.state.v2` package (note the **v2**).
-
-State is accessed using the `RuntimeContext`, so it is only possible in *rich 
functions*.
-Please see [here]({{< ref "docs/dev/datastream/user_defined_functions" 
>}}#rich-functions) for
-information about that, but we will also see an example shortly. The 
`RuntimeContext` that
-is available in a `RichFunction` has these methods for accessing state:
+## 使用 Keyed State V2
+
+和之前的 state API 不同,新的 state API 允许用户使用异步状态访问。每种类型的状态都提供了两种版本的 API:同步和异步。
+同步 API 是一个阻塞等待状态访问完成的 API。异步 API 是非阻塞的,它会返回一个 `StateFuture`,这个 `StateFuture` 
会在状态访问完成时完成。
+在 `StateFuture` 完成时,callback 或者 后续逻辑将会被调用(如果有的话)。异步 API 比同步 API 更加高效,更推荐使用异步 
API。

Review Comment:
   ```suggestion
   在 `StateFuture` 完成时,用户的回调会被执行。异步 API 比同步 API 更加高效,我们更推荐使用异步 API。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的
+`asyncClear` 和 `asyncUpdate` 的调用顺序。
+
+尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会串行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`

Review Comment:
   ```suggestion
   尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会并行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -25,40 +25,25 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-# Working with State V2 (New APIs)
+# 使用 State V2 (New APIs)

Review Comment:
   ```suggestion
   # 使用 State V2 (新的 API)
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -79,143 +64,101 @@ KeyedStream<WordCount> keyed = words
 
 {{< top >}}
 
-## Using Keyed State V2
-
-Unlike the previous state API, the new state API is designed for asynchronous 
state access.
-Each type of state gives two versions of the API: synchronous and 
asynchronous. The synchronous
-API is a blocking API that waits for the state access to complete. The 
asynchronous API is
-non-blocking and returns a `StateFuture` that will be completed when the state 
access
-is done. After that a callback or following logic will be invoked (if any).
-The asynchronous API is more efficient and should be used whenever possible.
-It is highly **not** recommended to mixed synchronous and asynchronous state 
access in the same
-user function.
-
-The keyed state interfaces provide access to different types of state that are 
all scoped to
-the key of the current input element. This means that this type of state can 
only be used
-on a `KeyedStream`, which can be created via `stream.keyBy(…)` in Java. And 
then most importantly,
-the keyed stream needs to be enabled for asynchronous state access by calling 
`enableAsyncState()`.
-The new API set are only available on `KeyedStream` with `enableAsyncState()` 
invoked.
-
-Now, we will look at the different types of state available, and then we will 
see
-how they can be used in a program. Since the synchronous APIs are identical 
with the original APIs,
-We only focus on the asynchronous ones here. 
-
-### The Return Values
-
-First of all, we should get familiar with the return value of those 
asynchronous state access methods.
-
-`StateFuture<T>` is a future that will be completed with the result of the 
state access.
-The return bype is T. It provides multiple methods to handle the result, 
listed as:
-* `StateFuture<Void> thenAccept(Consumer<T>)`: This method takes a `Consumer` 
that will be called with the result
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the
-  `Consumer` is done.
-* `StateFuture<R> thenApply(Function<T, R>)`: This method takes a `Function` 
that will be called with the result
-  when the state access is done. The return value of the function will be the 
result of the following
-  `StateFuture`, which will be finished when the `Function` is done.
-* `StateFuture<R> thenCompose(Function<T, StateFuture<R>>)`: This method takes 
a `Function` that will
-  be called with the result when the state access is done. The return value of 
the function should be
-  a `StateFuture<R>`, which is exposed to the invoker of `thenCompose` as a 
return value.
-  The `StateFuture<R>` will be finished when the inner `StateFuture<R>` of 
`Function` is finished.
-* `StateFuture<R> thenCombine(StateFuture<U>, BiFunction<T, U, R>)`: This 
method takes another `StateFuture` and a
-  `BiFunction` that will be called with the results of both `StateFuture`s 
when they are done. The return
-  value of the `BiFunction` will be the result of the following `StateFuture`, 
which will be finished when
-  the `BiFunction` is done.
-
-Those methods are similar to the corresponding ones of the 
`CompletableFuture`. Besides these methods,
-keep in mind that `StateFuture` does not provide a `get()` method to block the 
current thread until the
-state access is done. This is because blocking the current thread may cause 
recursive blocking. The 
-`StateFuture<T>` also provides conditional version of `thenAccept`, 
`thenApply`, `thenCompose` and `thenCombine`,
-which is for the case that the state access is done and the following logic 
will be split into two branches
-based on the result of the state access. The conditional version of those 
methods are `thenConditionallyAccept`,
-`thenConditionallyApply`, `thenConditionallyCompose` and 
`thenConditionallyCombine`.
-
-`StateIterator<T>` is an iterator that can be used to iterate over the 
elements of a state. It provides
-the following methods:
-* `boolean isEmpty()` : A synchronous method returns a `true` if the iterator 
has no elements, and `false` otherwise.
-* `StateFuture<Void> onNext(Consumer<T>)` : This method takes a `Consumer` 
that will be called with the next element
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the `Consumer` is done.
-  Also, a function version of `onNext` is provided, which is 
`StateFuture<Collection<R>> onNext(Function<T, R>)`. This method
-  takes a `Function` that will be called with the next element when the state 
access is done. The return value of the function 
-  will be collected and returned as a collection of the following 
`StateFuture`, which will be
-  finished when the `Function` is done.
-
-We also provide a `StateFutureUtils` class that contains some utility methods 
to handle `StateFuture`s.
-These methods are:
-* `StateFuture<T> completedFuture(T)`: This method returns a completed 
`StateFuture` with the given value. This is
-useful when you want to return a constant value in a `thenCompose` method for 
further processing.
-* `StateFuture<Void> completedVoidFuture()`: This method returns a completed 
`StateFuture` with `null` value. 
-A void value version of `completedFuture`.
-* `StateFuture<Collection<T>> combineAll(Collection<StateFuture<T>>)` : This 
method takes a collection of `StateFuture`s
-and returns a `StateFuture` that will be completed when all the input 
`StateFuture`s are completed. The result of the
-returned `StateFuture` is a collection of the results of the input 
`StateFuture`s. This is useful when you want to
-combine the results of multiple `StateFuture`s.
-* `StateFuture<Iterable<T>> toIterable(StateFuture<StateIterator<T>>)` : This 
method takes a `StateFuture` of `StateIterator`
-and returns a `StateFuture` of `Iterable`. The result of the returned 
`StateFuture` is an `Iterable` that contains all
-the elements of the `StateIterator`. This is useful when you want to convert a 
`StateIterator` to an `Iterable`.
-There is no good reason to do so, since this may disable the capability of 
lazy loading. Only useful when the further 
-calculation depends on the whole data from the iterator.
-
-
-### State Primitives
-
-The available state primitives are:
-
-* `ValueState<T>`: This keeps a value that can be updated and
-retrieved (scoped to key of the input element as mentioned above, so there 
will possibly be one value
-for each key that the operation sees). The value can be set using 
`asyncUpdate(T)` and retrieved using
-`StateFuture<T> asyncValue()`.
-
-* `ListState<T>`: This keeps a list of elements. You can append elements and 
retrieve an `StateIterator`
-over all currently stored elements. Elements are added using `asyncAdd(T)` or 
`asyncAddAll(List<T>)`,
-the Iterable can be retrieved using `StateFuture<StateIterator<T>> asyncGet()`.
-You can also override the existing list with `asyncUpdate(List<T>)`
-
-* `ReducingState<T>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. The interface is similar to `ListState` but elements added 
using
-`asyncAdd(T)` are reduced to an aggregate using a specified `ReduceFunction`.
-
-* `AggregatingState<IN, OUT>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. Contrary to `ReducingState`, the aggregate type may be 
different from the type
-of elements that are added to the state. The interface is the same as for 
`ListState` but elements
-added using `asyncAdd(IN)` are aggregated using a specified 
`AggregateFunction`.
-
-* `MapState<UK, UV>`: This keeps a list of mappings. You can put key-value 
pairs into the state and
-retrieve an `StateIterator` over all currently stored mappings. Mappings are 
added using `asyncPut(UK, UV)` or
-`asyncPutAll(Map<UK, UV>)`. The value associated with a user key can be 
retrieved using `asyncGet(UK)`.
-The iterable views for mappings, keys and values can be retrieved using 
`asyncEntries()`,
-`asyncKeys()` and `asyncValues()` respectively. You can also use 
`asyncIsEmpty()` to check whether
-this map contains any key-value mappings.
-
-All types of state also have a method `asyncClear()` that clears the state for 
the currently
-active key, i.e. the key of the input element.
-
-It is important to keep in mind that these state objects are only used for 
interfacing
-with state. The state is not necessarily stored inside but might reside on 
disk or somewhere else.
-The second thing to keep in mind is that the value you get from the state
-depends on the key of the input element. So the value you get in one 
invocation of your
-user function can differ from the value in another invocation if the keys 
involved are different.
-
-To get a state handle, you have to create a `StateDescriptor`. This holds the 
name of the state
-(as we will see later, you can create several states, and they have to have 
unique names so
-that you can reference them), the type of the values that the state holds, and 
possibly
-a user-specified function, such as a `ReduceFunction`. Depending on what type 
of state you
-want to retrieve, you create either a `ValueStateDescriptor`, a 
`ListStateDescriptor`, 
-an `AggregatingStateDescriptor`, a `ReducingStateDescriptor`, or a 
`MapStateDescriptor`.
-To differentiate between the previous state APIs, you should use the 
`StateDescriptor`s under the
-`org.apache.flink.api.common.state.v2` package (note the **v2**).
-
-State is accessed using the `RuntimeContext`, so it is only possible in *rich 
functions*.
-Please see [here]({{< ref "docs/dev/datastream/user_defined_functions" 
>}}#rich-functions) for
-information about that, but we will also see an example shortly. The 
`RuntimeContext` that
-is available in a `RichFunction` has these methods for accessing state:
+## 使用 Keyed State V2
+
+和之前的 state API 不同,新的 state API 允许用户使用异步状态访问。每种类型的状态都提供了两种版本的 API:同步和异步。
+同步 API 是一个阻塞等待状态访问完成的 API。异步 API 是非阻塞的,它会返回一个 `StateFuture`,这个 `StateFuture` 
会在状态访问完成时完成。
+在 `StateFuture` 完成时,callback 或者 后续逻辑将会被调用(如果有的话)。异步 API 比同步 API 更加高效,更推荐使用异步 
API。
+注意,**不建议**在同一个用户函数中混合使用同步和异步状态访问。

Review Comment:
   ```suggestion
   需要注意,**不建议**在同一个用户函数中混合使用同步和异步状态访问。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的
+`asyncClear` 和 `asyncUpdate` 的调用顺序。
+
+尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会串行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`
+方法中的用户代码都会在单个线程(任务线程)中执行。因此不会出现用户代码的并发问题。

Review Comment:
   ```suggestion
   方法中的用户代码都会在单个线程(即主任务线程)中执行。因此不会出现用户代码的并发问题。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的
+`asyncClear` 和 `asyncUpdate` 的调用顺序。
+
+尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会串行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`
+方法中的用户代码都会在单个线程(任务线程)中执行。因此不会出现用户代码的并发问题。
+
+通常,您无需担心状态访问方法的执行顺序问题,但 Flink 仍确保一些规则:
+* 同 key 的元素的执行顺序严格按照元素到达 `flatMap` 的顺序执行的。
+* 传递给 `thenXXxx` 方法的函数会按照调用链的顺序执行。如果它们不属于调用链,或者同时有多个调用链,则无法保证执行顺序。

Review Comment:
   ```suggestion
   * 传递给 `thenXXxx` 方法的函数会按照调用链的顺序执行。如果同时有多个调用链,则无法保证执行顺序。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的
+`asyncClear` 和 `asyncUpdate` 的调用顺序。
+
+尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会串行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`
+方法中的用户代码都会在单个线程(任务线程)中执行。因此不会出现用户代码的并发问题。
+
+通常,您无需担心状态访问方法的执行顺序问题,但 Flink 仍确保一些规则:
+* 同 key 的元素的执行顺序严格按照元素到达 `flatMap` 的顺序执行的。
+* 传递给 `thenXXxx` 方法的函数会按照调用链的顺序执行。如果它们不属于调用链,或者同时有多个调用链,则无法保证执行顺序。
+
+### 异步 APIs 的最佳实践
+
+异步 APIs 的设计比同步 APIs 更加高效和强大。当使用异步 APIs 时,有一些最佳实践应该遵循:
+* **不要混合同步和异步状态访问**
+* 使用 `thenXXxx` 方法的链式调用来处理状态访问的结果,然后给出另一个状态访问或结果。将逻辑分割成多个步骤,通过 `thenXXxx` 
+  方法分割。 

Review Comment:
   * 将逻辑分割成多个步骤,通过连续的 `thenXXxx` 来进行链式调用,前一个 `thenXXxx` 的结果传递给后一个 `thenXXxx` 。



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -275,62 +218,42 @@ env.fromElements(Tuple2.of(1L, 3L), Tuple2.of(1L, 5L), 
Tuple2.of(1L, 7L), Tuple2
 {{< /tab >}}
 {{< /tabs >}}
 
-This example implements a poor man's counting window. We key the tuples by the 
first field
-(in the example all have the same key `1`). The function stores the count and 
a running sum in
-a `ValueState`. Once the count reaches 2 it will emit the average and clear 
the state so that
-we start over from `0`. Note that this would keep a different state value for 
each different input
-key if we had tuples with different values in the first field.
-
-### Execution Order
-
-The state access methods are executed asynchronously. This means that the 
state access methods
-will not block the current thread. With synchronous APIs, the state access 
methods will be executed in
-the order they are called. However, with asynchronous APIs, the state access 
methods will be executed
-out of order, especially for those invokes for different incoming elements. 
For the above example,
-if the `flatMap` function is invoked for two different incoming elements A and 
B, the state access
-methods for A and B will be executed. Firstly, `asyncGet` is executed for A, 
then `asyncGet` is
-allowed to execute for B. The finish order of the two `asyncGet` is not 
guaranteed. Thus the order
-of continuation of the two `StateFuture`s is not guaranteed. Thus invokes of 
`asyncClear` or
-`asyncUpdate`for A and B are not determined.
-
-Although the state access methods are executed out of order, this not mean 
that all the user code
-are run in parallel. The user code in the `processElement`, `flatMap` or 
`thenXXxx` methods
-following the state access methods will be executed in a single thread (the 
task thread). So there
-is no concurrency issue for the user code.
-
-Typically, you don't need to worry about the execution order of the state 
access methods, but there
-is still some rules the Flink will ensure:
-* The execution order of user code entry `flatMap` for same-key elements are 
invoked strictly in
-order of element arrival.
-* The consumers or functions passed to the `thenXXxx` methods are executed in 
the order they are
-chained. If they are not chained, or there are multiple chains, the order is 
not guaranteed.
-
-### Best practice of asynchronous APIs
-
-The asynchronous APIs are designed to be more efficient and more powerful than 
the synchronous APIs.
-There are some best practices that you should follow when using the 
asynchronous APIs:
-* **Avoid mixing synchronous and asynchronous state access**
-* Use chaining of `thenXXxx` methods to handle the result of the state access 
and then gives another
-    state access or result. Divide the logic into multiple steps split by 
`thenXXxx` methods.
-* Avoid accessing mutable members of the user function 
(`RichFlatMapFunction`). Since the state access
-    methods are executed out of order, the mutable members may be accessed in 
unpredictable order.
-    Instead, use the result of the state access to pass the data between 
different steps. The 
-    `StateFutureUtils.completedFuture` or `thenApply` method can be used to 
pass the data. Or use
-    a captured container (`AtomicReference`) which is initialized for each 
invoke of the `flatMap`
-    to share between lambdas.
-
-
-### State Time-To-Live (TTL)
-
-A *time-to-live* (TTL) can be assigned to the keyed state of any type. If a 
TTL is configured and a
-state value has expired, the stored value will be cleaned up on a best effort 
basis which is
-discussed in more detail below.
-
-All state collection types support per-entry TTLs. This means that list 
elements and map entries
-expire independently.
-
-In order to use state TTL one must first build a `StateTtlConfig` 
configuration object. The TTL 
-functionality can then be enabled in any state descriptor by passing the 
configuration:
+这个例子实现了一个简单的计数窗口。 我们把元组的第一个元素当作 key(在示例中都 key 都是 "1")。 
+该函数将出现的次数以及总和存储在 "ValueState" 中。
+一旦出现次数达到 2,则将平均值发送到下游,并清除状态重新开始。 请注意,我们会为每个不同的 key(元组中第一个元素)保存一个单独的值。
+
+### 执行顺序
+状态访问是异步的,这意味着状态访问方法不会阻塞当前线程。在同步 API 下,状态访问方法会按照它们被调用的顺序执行,但是异步 API 下,
+尤其是对于不同输入元素的状态访问方法,状态访问方法可能会乱序执行。在上面的例子中,如果 `flatMap` 函数接收搭配两个不同的
+输入元素 A 和 B, A 和 B 的状态访问方法会被执行。首先,元素 A 的 `asyncGet`方法被执行,然后元素 B 的 `asyncGet` 
方法接着被执行,
+但两个`asyncGet`的完成顺序不能保证。因此,无法保证两个 `StateFuture` 后续步骤的执行顺序,即无法确定元素 A 和 元素 B 的
+`asyncClear` 和 `asyncUpdate` 的调用顺序。
+
+尽管状态访问方法可能会乱序执行,这也不意味着所有用户代码会串行执行。在 `processElement`, `flatMap` 或者 `thenXXxx`
+方法中的用户代码都会在单个线程(任务线程)中执行。因此不会出现用户代码的并发问题。
+
+通常,您无需担心状态访问方法的执行顺序问题,但 Flink 仍确保一些规则:
+* 同 key 的元素的执行顺序严格按照元素到达 `flatMap` 的顺序执行的。
+* 传递给 `thenXXxx` 方法的函数会按照调用链的顺序执行。如果它们不属于调用链,或者同时有多个调用链,则无法保证执行顺序。
+
+### 异步 APIs 的最佳实践
+
+异步 APIs 的设计比同步 APIs 更加高效和强大。当使用异步 APIs 时,有一些最佳实践应该遵循:
+* **不要混合同步和异步状态访问**
+* 使用 `thenXXxx` 方法的链式调用来处理状态访问的结果,然后给出另一个状态访问或结果。将逻辑分割成多个步骤,通过 `thenXXxx` 
+  方法分割。 
+* 避免在用户函数(例如 `RichFlatMapFunction`) 中使用可变(mutable)成员。因为状态访问方法是乱序执行的,
+  可变成员可能会以无法预测的顺序执行。相反,使用 state access 
的结果来在不同步骤之间传递数据。`StateFutureUtils.completedFuture` 
+  和 `thenApply` 方法可以被用来传递数据。或者一个捕获变量的容器 (`AtomicReference`),该容器在每次调用 `flatMap`时
+  都会初始化,以便在 lambda 之间共享。

Review Comment:
   ```suggestion
   * 避免在用户函数(例如 `RichFlatMapFunction`) 中使用可变(mutable)成员。因为状态访问方法是乱序执行的,
     可变成员可能会以无法预测的顺序执行。相反,使用 state access 
的结果来在不同步骤之间传递数据。`StateFutureUtils.completedFuture` 
     和 `thenApply` 方法可以被用来传递数据。或者使用一个每次在 `flatMap` 调用时初始化的容器 
(`AtomicReference`),以便在不同回调之间共享数据。
   ```



##########
docs/content.zh/docs/dev/datastream/fault-tolerance/state_v2.md:
##########
@@ -79,143 +64,101 @@ KeyedStream<WordCount> keyed = words
 
 {{< top >}}
 
-## Using Keyed State V2
-
-Unlike the previous state API, the new state API is designed for asynchronous 
state access.
-Each type of state gives two versions of the API: synchronous and 
asynchronous. The synchronous
-API is a blocking API that waits for the state access to complete. The 
asynchronous API is
-non-blocking and returns a `StateFuture` that will be completed when the state 
access
-is done. After that a callback or following logic will be invoked (if any).
-The asynchronous API is more efficient and should be used whenever possible.
-It is highly **not** recommended to mixed synchronous and asynchronous state 
access in the same
-user function.
-
-The keyed state interfaces provide access to different types of state that are 
all scoped to
-the key of the current input element. This means that this type of state can 
only be used
-on a `KeyedStream`, which can be created via `stream.keyBy(…)` in Java. And 
then most importantly,
-the keyed stream needs to be enabled for asynchronous state access by calling 
`enableAsyncState()`.
-The new API set are only available on `KeyedStream` with `enableAsyncState()` 
invoked.
-
-Now, we will look at the different types of state available, and then we will 
see
-how they can be used in a program. Since the synchronous APIs are identical 
with the original APIs,
-We only focus on the asynchronous ones here. 
-
-### The Return Values
-
-First of all, we should get familiar with the return value of those 
asynchronous state access methods.
-
-`StateFuture<T>` is a future that will be completed with the result of the 
state access.
-The return bype is T. It provides multiple methods to handle the result, 
listed as:
-* `StateFuture<Void> thenAccept(Consumer<T>)`: This method takes a `Consumer` 
that will be called with the result
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the
-  `Consumer` is done.
-* `StateFuture<R> thenApply(Function<T, R>)`: This method takes a `Function` 
that will be called with the result
-  when the state access is done. The return value of the function will be the 
result of the following
-  `StateFuture`, which will be finished when the `Function` is done.
-* `StateFuture<R> thenCompose(Function<T, StateFuture<R>>)`: This method takes 
a `Function` that will
-  be called with the result when the state access is done. The return value of 
the function should be
-  a `StateFuture<R>`, which is exposed to the invoker of `thenCompose` as a 
return value.
-  The `StateFuture<R>` will be finished when the inner `StateFuture<R>` of 
`Function` is finished.
-* `StateFuture<R> thenCombine(StateFuture<U>, BiFunction<T, U, R>)`: This 
method takes another `StateFuture` and a
-  `BiFunction` that will be called with the results of both `StateFuture`s 
when they are done. The return
-  value of the `BiFunction` will be the result of the following `StateFuture`, 
which will be finished when
-  the `BiFunction` is done.
-
-Those methods are similar to the corresponding ones of the 
`CompletableFuture`. Besides these methods,
-keep in mind that `StateFuture` does not provide a `get()` method to block the 
current thread until the
-state access is done. This is because blocking the current thread may cause 
recursive blocking. The 
-`StateFuture<T>` also provides conditional version of `thenAccept`, 
`thenApply`, `thenCompose` and `thenCombine`,
-which is for the case that the state access is done and the following logic 
will be split into two branches
-based on the result of the state access. The conditional version of those 
methods are `thenConditionallyAccept`,
-`thenConditionallyApply`, `thenConditionallyCompose` and 
`thenConditionallyCombine`.
-
-`StateIterator<T>` is an iterator that can be used to iterate over the 
elements of a state. It provides
-the following methods:
-* `boolean isEmpty()` : A synchronous method returns a `true` if the iterator 
has no elements, and `false` otherwise.
-* `StateFuture<Void> onNext(Consumer<T>)` : This method takes a `Consumer` 
that will be called with the next element
-  when the state access is done. It returns a `StateFuture<Void>`, which will 
be finished when the `Consumer` is done.
-  Also, a function version of `onNext` is provided, which is 
`StateFuture<Collection<R>> onNext(Function<T, R>)`. This method
-  takes a `Function` that will be called with the next element when the state 
access is done. The return value of the function 
-  will be collected and returned as a collection of the following 
`StateFuture`, which will be
-  finished when the `Function` is done.
-
-We also provide a `StateFutureUtils` class that contains some utility methods 
to handle `StateFuture`s.
-These methods are:
-* `StateFuture<T> completedFuture(T)`: This method returns a completed 
`StateFuture` with the given value. This is
-useful when you want to return a constant value in a `thenCompose` method for 
further processing.
-* `StateFuture<Void> completedVoidFuture()`: This method returns a completed 
`StateFuture` with `null` value. 
-A void value version of `completedFuture`.
-* `StateFuture<Collection<T>> combineAll(Collection<StateFuture<T>>)` : This 
method takes a collection of `StateFuture`s
-and returns a `StateFuture` that will be completed when all the input 
`StateFuture`s are completed. The result of the
-returned `StateFuture` is a collection of the results of the input 
`StateFuture`s. This is useful when you want to
-combine the results of multiple `StateFuture`s.
-* `StateFuture<Iterable<T>> toIterable(StateFuture<StateIterator<T>>)` : This 
method takes a `StateFuture` of `StateIterator`
-and returns a `StateFuture` of `Iterable`. The result of the returned 
`StateFuture` is an `Iterable` that contains all
-the elements of the `StateIterator`. This is useful when you want to convert a 
`StateIterator` to an `Iterable`.
-There is no good reason to do so, since this may disable the capability of 
lazy loading. Only useful when the further 
-calculation depends on the whole data from the iterator.
-
-
-### State Primitives
-
-The available state primitives are:
-
-* `ValueState<T>`: This keeps a value that can be updated and
-retrieved (scoped to key of the input element as mentioned above, so there 
will possibly be one value
-for each key that the operation sees). The value can be set using 
`asyncUpdate(T)` and retrieved using
-`StateFuture<T> asyncValue()`.
-
-* `ListState<T>`: This keeps a list of elements. You can append elements and 
retrieve an `StateIterator`
-over all currently stored elements. Elements are added using `asyncAdd(T)` or 
`asyncAddAll(List<T>)`,
-the Iterable can be retrieved using `StateFuture<StateIterator<T>> asyncGet()`.
-You can also override the existing list with `asyncUpdate(List<T>)`
-
-* `ReducingState<T>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. The interface is similar to `ListState` but elements added 
using
-`asyncAdd(T)` are reduced to an aggregate using a specified `ReduceFunction`.
-
-* `AggregatingState<IN, OUT>`: This keeps a single value that represents the 
aggregation of all values
-added to the state. Contrary to `ReducingState`, the aggregate type may be 
different from the type
-of elements that are added to the state. The interface is the same as for 
`ListState` but elements
-added using `asyncAdd(IN)` are aggregated using a specified 
`AggregateFunction`.
-
-* `MapState<UK, UV>`: This keeps a list of mappings. You can put key-value 
pairs into the state and
-retrieve an `StateIterator` over all currently stored mappings. Mappings are 
added using `asyncPut(UK, UV)` or
-`asyncPutAll(Map<UK, UV>)`. The value associated with a user key can be 
retrieved using `asyncGet(UK)`.
-The iterable views for mappings, keys and values can be retrieved using 
`asyncEntries()`,
-`asyncKeys()` and `asyncValues()` respectively. You can also use 
`asyncIsEmpty()` to check whether
-this map contains any key-value mappings.
-
-All types of state also have a method `asyncClear()` that clears the state for 
the currently
-active key, i.e. the key of the input element.
-
-It is important to keep in mind that these state objects are only used for 
interfacing
-with state. The state is not necessarily stored inside but might reside on 
disk or somewhere else.
-The second thing to keep in mind is that the value you get from the state
-depends on the key of the input element. So the value you get in one 
invocation of your
-user function can differ from the value in another invocation if the keys 
involved are different.
-
-To get a state handle, you have to create a `StateDescriptor`. This holds the 
name of the state
-(as we will see later, you can create several states, and they have to have 
unique names so
-that you can reference them), the type of the values that the state holds, and 
possibly
-a user-specified function, such as a `ReduceFunction`. Depending on what type 
of state you
-want to retrieve, you create either a `ValueStateDescriptor`, a 
`ListStateDescriptor`, 
-an `AggregatingStateDescriptor`, a `ReducingStateDescriptor`, or a 
`MapStateDescriptor`.
-To differentiate between the previous state APIs, you should use the 
`StateDescriptor`s under the
-`org.apache.flink.api.common.state.v2` package (note the **v2**).
-
-State is accessed using the `RuntimeContext`, so it is only possible in *rich 
functions*.
-Please see [here]({{< ref "docs/dev/datastream/user_defined_functions" 
>}}#rich-functions) for
-information about that, but we will also see an example shortly. The 
`RuntimeContext` that
-is available in a `RichFunction` has these methods for accessing state:
+## 使用 Keyed State V2
+
+和之前的 state API 不同,新的 state API 允许用户使用异步状态访问。每种类型的状态都提供了两种版本的 API:同步和异步。
+同步 API 是一个阻塞等待状态访问完成的 API。异步 API 是非阻塞的,它会返回一个 `StateFuture`,这个 `StateFuture` 
会在状态访问完成时完成。
+在 `StateFuture` 完成时,callback 或者 后续逻辑将会被调用(如果有的话)。异步 API 比同步 API 更加高效,更推荐使用异步 
API。
+注意,**不建议**在同一个用户函数中混合使用同步和异步状态访问。
+
+Key state 接口提供了对不同类型状态的访问,它们都是以 key 为作用域。这意味着这个类型的状态只能在 `KeyedStream` 
上使用,`keyedStream`
+可以通过 `stream.keyBy(…)` 在 Java 中创建。最重要的是,`keyedStream` 需要通过调用 
`enableAsyncState()` 来开启异步状态访问。
+新的 API 集合只有在 `KeyedStream` 上开启异步状态访问时才可用。
+
+接下来,我们将看到不同类型的状态,并看到它们如何在程序中使用。由于同步 API 与之前的 API 是等价的,这里只关注异步 API。
+
+### 返回值
+
+首先,我们应该熟悉异步状态访问方法的返回值。
+`StateFuture<T>` 完成时会返回状态访问的结果。返回类型是 T。它提供了多个方法来处理结果,包括:
+* `StateFuture<Void> thenAccept(Consumer<T>)`: 接受一个在状态访问完成时会被调用的 `Consumer` 
作为参数。 
+   它返回一个 `StateFuture<Void>`,在 `Consumer` 执行完时完成。
+* `StateFuture<R> thenApply(Function<T, R>)`: 接受一个在状态访问完成时会被调用的 `Function` 
作为参数。 
+   返回值 `StateFuture<R>` 会使用 `Function` 的返回值会作为内部结果,在 `Function` 执行完时完成。
+* `StateFuture<R> thenCompose(Function<T, StateFuture<R>>)`: 接受一个在状态访问完成时会被调用的
+   `Function` 作为参数。 函数的返回值是 `StateFuture<R>`, 被传给 `thenCompose` 
的调用者作为最终的返回值。返回值
+   `StateFuture<R>` 会在 `Function` 内部的 `StateFuture<R>` 完成时完成。
+* `StateFuture<R> thenCombine(StateFuture<U>, BiFunction<T, U, R>)`: 接受另一个 
`StateFuture<U>` 
+  和一个 `BiFunction` 作为参数,`BiFunction` 在两个 `StateFuture` 都完成时被调用。 返回值 
`StateFuture` 使用 
+  `BiFunction` 的返回值作为内部结果, 返回值的 `StateFuture<R>` 会在两个 `StateFuture` 都完成时完成。
+
+以上这些方法类似于 `CompletableFuture` 的相关方法。在此之外,注意,`StateFuture` 不提供 `get()` 
方法来阻塞当前线程,
+直到状态访问完成。 这是因为阻塞当前线程可能会导致递归阻塞。 `StateFuture<T>` 还提供了条件版本的 `thenAccept`, 
+`thenApply`, `thenCompose` 和 `thenCombine`,用于后续逻辑依赖 
状态访问返回值来选择不同分支的情景。这些方法的条件版本是:
+`thenConditionallyAccept`, `thenConditionallyApply`, 
`thenConditionallyCompose` 和 `thenConditionallyCombine`。
+
+`StateIterator<T>` 是一个迭代器,可用来迭代状态中的元素。它提供了以下方法:
+* `boolean isEmpty()` : 当迭代器没有元素时返回 `true`,否则返回 `false`,是一个同步方法。
+* `StateFuture<Void> onNext(Consumer<T>)` : 该方法接受一个 `Consumer`作为参数,`Consumer` 
会在状态访问完成时与下一个
+   元素一起被调用。它返回一个 `StateFuture<Void>`,在 `Consumer` 执行完时完成。同样,`onNext` 也提供了 
`Function`
+   作为参数的版本:`StateFuture<Collection<R>> onNext(Function<T, R>)`。该方法接受一个 
`Function` 作为参数,
+   会在状态访问完成时与下一个元素一起被调用。`Function` 的返回值会被收集到一个集合中作为返回值 `StateFuture`的内部
+   结果,返回值在 `Function` 执行完时完成。
+
+我们也提供了 `StateFutureUtils` 类,其中包含一些用于处理 `StateFuture` 的实用方法。这些方法是:
+* `StateFuture<T> completedFuture(T)`: 该方法返回一个已经完成的 `StateFuture`,该 
`StateFuture` 的返回值为给定的值。
+* `StateFuture<Void> completedVoidFuture()`: 该方法返回一个已经完成的 `StateFuture`,该 
`StateFuture` 的返回值为 `null`,
+   是 `completedFuture` 的 void 返回值版本。
+* `StateFuture<Collection<T>> combineAll(Collection<StateFuture<T>>)` : 
该方法接受一个 `StateFuture` 集合
+   作为参数,返回一个 `StateFuture`,返回值 `StateFuture` 在所有的 `StateFuture` 都完成后完成。返回值 
`StateFuture` 
+   的内部结果是输入的 `StateFuture` 的结果的集合。该方法在想组合多个 `StateFuture` 时的结果时非常有用。
+* `StateFuture<Iterable<T>> toIterable(StateFuture<StateIterator<T>>)` : 
该方法接受一个结果为 `StateIterator` 
+   的`StateFuture` 作为参数,返回一个 `Iterable` 作为结果的 `StateFuture`。 返回值 `StateFuture` 
的内部结果 
+   `Iterable` 包含了 `StateIterator` 的所有元素。该函数在想把 `StateIterator` 转换为 `Iterable` 
时非常有用。 
+   但没有充分的理由这样做,因为这可能会禁用延迟加载的功能。只有当进一步的计算取决于迭代器的整个数据时才有用。

Review Comment:
   ```suggestion
      但这可能会禁用延迟加载的功能,如果没有充分理由这样做,建议不这样使用。本方法只有当下一步的计算依赖于迭代器的全部数据时才有用。
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to