Skip to content

Commit 9e584f5

Browse files
Nikita-tech-writerMmuzaf
authored andcommitted
IGNITE-14144 Document C++ thin client transactions (#8777)
1 parent 2472e55 commit 9e584f5

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

docs/_docs/thin-clients/cpp-thin-client.adoc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,60 @@ Configure link:security/authentication[authentication on the cluster side] and p
115115
include::code-snippets/cpp/src/thin_authentication.cpp[tag=thin-authentication,indent=0]
116116
----
117117

118+
=== Transactions
119+
120+
121+
Client transactions are supported for caches with `AtomicityMode.TRANSACTIONAL` mode.
122+
123+
124+
==== Executing Transactions
125+
126+
127+
To start a transaction, obtain the `ClientTransactions` object from `IgniteClient`.
128+
`ClientTransactions` has a number of `txStart(...)` methods, each of which starts a new transaction and returns an object (`ClientTransaction`) that represents the transaction.
129+
Use this object to commit or rollback the transaction.
130+
131+
132+
[source, cpp]
133+
----
134+
cache::CacheClient<int, int> cache = client.GetCache<int, int>("my_transactional_cache");
135+
136+
transactions::ClientTransactions transactions = client.ClientTransactions();
137+
138+
transactions::ClientTransaction tx = transactions.TxStart();
139+
140+
cache.Put(2, 20);
141+
142+
tx.Commit();
143+
----
144+
145+
146+
==== Transaction Configuration
147+
148+
149+
Client transactions can have different concurrency modes, isolation levels, and execution timeout, which can be set for all transactions or on a per transaction basis.
150+
151+
You can specify the concurrency mode, isolation level, and timeout when starting an individual transaction. In this case, the provided values override the default settings.
152+
153+
154+
[source, cpp]
155+
----
156+
transactions::ClientTransactions transactions = client.ClientTransactions();
157+
158+
const uint32_t TX_TIMEOUT = 200;
159+
160+
transactions::ClientTransaction tx = transactions.TxStart(TransactionConcurrency::OPTIMISTIC, TransactionIsolation::SERIALIZABLE, TX_TIMEOUT);
161+
162+
cache.Put(1, 20);
163+
164+
tx.Commit();
165+
----
166+
167+
You can also perform transactions with labels:
168+
169+
[source, cpp]
170+
----
171+
transactions::ClientTransaction tx = transactions.withLabel(label).TxStart();
172+
173+
transactions::ClientTransaction tx = transactions.withLabel(label).TxStart(TransactionConcurrency::OPTIMISTIC, TransactionIsolation::SERIALIZABLE, TX_TIMEOUT);
174+
----

0 commit comments

Comments
 (0)