Skip to content

Commit 01e094b

Browse files
Translation of documentation (#4918)
1 parent ae312b3 commit 01e094b

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

ydb/docs/en/core/concepts/_includes/transactions.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ For more information about YQL support in {{ ydb-short-name }}, see the [YQL doc
4747

4848
## Distributed transactions {#distributed-tx}
4949

50-
A database table in {{ ydb-short-name }} can be sharded by the range of the primary key values. Different table shards can be served by different distributed database servers (including ones in different locations). They can also move independently between servers to enable rebalancing or ensure shard operability if servers or network equipment goes offline.
50+
A database [table](../datamodel/table.md) in {{ ydb-short-name }} can be sharded by the range of the primary key values. Different table shards can be served by different distributed database servers (including ones in different locations). They can also move independently between servers to enable rebalancing or ensure shard operability if servers or network equipment goes offline.
5151

52-
{{ ydb-short-name }} supports distributed transactions. Distributed transactions are transactions that affect more than one shard of one or more tables. They require more resources and take more time. While point reads and writes may take up to 10 ms in 99 percentile, distributed transactions typically take from 20 to 500 ms.
52+
A [topic](../topic.md) in {{ ydb-short-name }} can be sharded into several partitions. Different topic partitions, similar to table shards, can be served by different distributed database servers.
53+
54+
{{ ydb-short-name }} supports distributed transactions. Distributed transactions are transactions that affect more than one shard of one or more tables and topics. They require more resources and take more time. While point reads and writes may take up to 10 ms in the 99th percentile, distributed transactions typically take from 20 to 500 ms.

ydb/docs/en/core/reference/ydb-sdk/topic.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,8 @@ You can read messages without a [commit](#no-commit) as well. In this case, all
11671167

11681168
Information about which messages have already been processed can be [saved on the client side](#client-commit) by sending the starting consumer offset to the server when creating a new connection. This does not change the consumer offset on the server.
11691169

1170+
Data from topics can be read in the context of [transactions](#read-tx). In this case, the reading offset will only advance when the transaction is committed. On reconnect, all uncommitted messages will be read again.
1171+
11701172
{% list tabs %}
11711173

11721174
- C++
@@ -1572,6 +1574,60 @@ Reading progress is usually saved on a server for each Consumer. However, such p
15721574

15731575
{% list tabs %}
15741576

1577+
- C++
1578+
1579+
Before reading messages, the client code must pass a transaction object reference to the reading session settings.
1580+
1581+
```cpp
1582+
ReadSession->WaitEvent().Wait(TDuration::Seconds(1));
1583+
1584+
auto tableSettings = NYdb::NTable::TTxSettings::SerializableRW();
1585+
auto transactionResult = TableSession->BeginTransaction(tableSettings).GetValueSync();
1586+
auto Transaction = transactionResult.GetTransaction();
1587+
1588+
NYdb::NTopic::TReadSessionGetEventSettings topicSettings;
1589+
topicSettings.Block(false);
1590+
topicSettings.Tx(Transaction);
1591+
1592+
auto events = ReadSession->GetEvents(topicSettings);
1593+
1594+
for (auto& event : events) {
1595+
// process the event and write results to a table
1596+
}
1597+
1598+
NYdb::NTable::TCommitTxSettings commitSettings;
1599+
auto commitResult = Transaction.Commit(commitSettings).GetValueSync();
1600+
```
1601+
1602+
{% note warning %}
1603+
1604+
When processing `events`, you do not need to confirm processing for `TDataReceivedEvent` events explicitly.
1605+
1606+
{% endnote %}
1607+
1608+
Confirmation of the `TStopPartitionSessionEvent` event processing must be done after calling `Commit`.
1609+
1610+
```cpp
1611+
std::optional<TStopPartitionSessionEvent> stopPartitionSession;
1612+
1613+
auto events = ReadSession->GetEvents(topicSettings);
1614+
1615+
for (auto& event : events) {
1616+
if (auto* e = std::get_if<TStopPartitionSessionEvent>(&event) {
1617+
stopPartitionSessionEvent = std::move(*e);
1618+
} else {
1619+
// process the event and write results to a table
1620+
}
1621+
}
1622+
1623+
NYdb::NTable::TCommitTxSettings commitSettings;
1624+
auto commitResult = Transaction.Commit(commitSettings).GetValueSync();
1625+
1626+
if (stopPartitionSessionEvent) {
1627+
stopPartitionSessionEvent->Commit();
1628+
}
1629+
```
1630+
15751631
- Java (sync)
15761632

15771633
[Example on GitHub](https://github.com/ydb-platform/ydb-java-examples/blob/develop/ydb-cookbook/src/main/java/tech/ydb/examples/topic/transactions/TransactionReadSync.java)

0 commit comments

Comments
 (0)