@@ -143,6 +143,8 @@ The IPROTO constants that appear within requests or responses that we will descr
143
143
IPROTO_RAFT_VCLOCK=0x03
144
144
IPROTO_VERSION=0x54
145
145
IPROTO_FEATURES=0x55
146
+ IPROTO_TIMEOUT=0x56
147
+ IPROTO_TXN_ISOLATION = 0x59
146
148
147
149
148
150
To denote message descriptions we will say ``msgpack(...) `` and within it we will use modified
@@ -706,6 +708,96 @@ IPROTO_SQL_TEXT (0x40) and statement-text (string) if executing an SQL string.
706
708
Thus the IPROTO_PREPARE map item is the same as the first item of the
707
709
:ref: `IPROTO_EXECUTE <box_protocol-execute >` body.
708
710
711
+ .. _box_protocol-begin :
712
+
713
+ IPROTO_BEGIN = 0x0e
714
+ ~~~~~~~~~~~~~~~~~~~~~
715
+
716
+ Begin a transaction in the specified stream.
717
+ See :ref: `stream:begin() <net_box-stream_begin >`.
718
+ The body is optional and can contain two items:
719
+
720
+ .. cssclass :: highlight
721
+ .. parsed-literal ::
722
+
723
+ # <size>
724
+ msgpack(:samp: `{ {MP_UINT unsigned integer = size(<header>) + size(<body>) } } `)
725
+ # <header>
726
+ msgpack({
727
+ IPROTO_REQUEST_TYPE: IPROTO_BEGIN,
728
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer } } `,
729
+ IPROTO_STREAM_ID: :samp: `{ {MP_UINT unsigned integer } } `
730
+ })
731
+ # <body>
732
+ msgpack({
733
+ IPROTO_TIMEOUT: :samp: `{ {MP_DOUBLE } } `,
734
+ IPROTO_TXN_ISOLATION: :samp: `{ {MP_UINT unsigned integer } } `
735
+ })
736
+
737
+ IPROTO_TIMEOUT is an optional timeout (in seconds). After it expires,
738
+ the transaction will be rolled back automatically.
739
+
740
+ .. // TODO: add link to transaction isolation docs once they're ready
741
+ IPROTO_TXN_ISOLATION is the transaction isolation level. It can take
742
+ the following values:
743
+
744
+ .. // TODO: provide links to level descriptions
745
+ - ``TXN_ISOLATION_DEFAULT = 0 `` -- use the global default level (default value)
746
+ - ``TXN_ISOLATION_READ_COMMITTED = 1 `` -- read changes that are committed but not confirmed yet
747
+ - ``TXN_ISOLATION_READ_CONFIRMED = 2 `` -- read confirmed changes
748
+ - ``TXN_ISOLATION_BEST_EFFORT = 3 `` -- determine isolation level automatically
749
+
750
+ See :ref: `Binary protocol -- streams <box_protocol-streams >` to learn more about
751
+ stream transactions in the binary protocol.
752
+
753
+
754
+ .. _box_protocol-commit :
755
+
756
+ IPROTO_COMMIT = 0x0f
757
+ ~~~~~~~~~~~~~~~~~~~~~
758
+
759
+ Commit the transaction in the specified stream.
760
+ See :ref: `stream:commit() <net_box-stream_commit >`.
761
+
762
+ .. cssclass :: highlight
763
+ .. parsed-literal ::
764
+
765
+ # <size>
766
+ msgpack(7)
767
+ # <header>
768
+ msgpack({
769
+ IPROTO_REQUEST_TYPE: IPROTO_COMMIT,
770
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer } } `,
771
+ IPROTO_STREAM_ID: :samp: `{ {MP_UINT unsigned integer } } `
772
+ })
773
+
774
+ See :ref: `Binary protocol -- streams <box_protocol-streams >` to learn more about
775
+ stream transactions in the binary protocol.
776
+
777
+
778
+ .. _box_protocol-rollback :
779
+
780
+ IPROTO_ROLLBACK = 0x10
781
+ ~~~~~~~~~~~~~~~~~~~~~
782
+
783
+ Rollback the transaction in the specified stream.
784
+ See :ref: `stream:rollback() <net_box-stream_rollback >`.
785
+
786
+ .. cssclass :: highlight
787
+ .. parsed-literal ::
788
+
789
+ # <size>
790
+ msgpack(7)
791
+ # <header>
792
+ msgpack({
793
+ IPROTO_REQUEST_TYPE: IPROTO_ROLLBACK,
794
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer } } `,
795
+ IPROTO_STREAM_ID: :samp: `{ {MP_UINT unsigned integer } } `
796
+ })
797
+
798
+ See :ref: `Binary protocol -- streams <box_protocol-streams >` to learn more about
799
+ stream transactions in the binary protocol.
800
+
709
801
710
802
.. _box_protocol-ping :
711
803
@@ -746,9 +838,9 @@ Tarantool nodes in :ref:`synchronous replication <repl_sync>`.
746
838
The messages are not supposed to be used by any client applications in their
747
839
regular connections.
748
840
749
- .. _box_protocol-confirm :
841
+ .. _box_protocol-raft_confirm :
750
842
751
- IPROTO_CONFIRM = 0x28
843
+ IPROTO_RAFT_CONFIRM = 0x28
752
844
~~~~~~~~~~~~~~~~~~~~~
753
845
754
846
This message confirms that the transactions originated from the instance
@@ -775,9 +867,9 @@ The body is a 2-item map:
775
867
})
776
868
777
869
778
- .. _box_protocol-rollback :
870
+ .. _box_protocol-raft_rollback :
779
871
780
- IPROTO_ROLLBACK = 0x29
872
+ IPROTO_RAFT_ROLLBACK = 0x29
781
873
~~~~~~~~~~~~~~~~~~~~~~
782
874
783
875
This message says that the transactions originated from the instance
@@ -1281,16 +1373,18 @@ each call to conn:new_stream() assigns a new number, starting with 1.
1281
1373
.. _box_protocol-stream_transactions :
1282
1374
1283
1375
The client makes stream transactions by sending, in order:
1284
- IPROTO_BEGIN, the transaction data-change and query requests,
1285
- IPROTO_COMMIT or IPROTO_ROLLBACK.
1286
- Each request must contain the same IPROTO_STREAM_ID value.
1287
- With streaming there is no need to add
1288
- :ref: `IPROTO_FLAGS <box_protocol-flags >` and IPROTO_FLAG_COMMIT
1289
- in the header of the last request of a transaction.
1290
- Rollback will be automatic if disconnect occurs before commit is possible.
1376
+
1377
+ 1. IPROTO_BEGIN with an optional transaction timeout in the IPROTO_TIMEOUT field of the request body.
1378
+ 2. The transaction data-change and query requests.
1379
+ 3. IPROTO_COMMIT or IPROTO_ROLLBACK.
1380
+
1381
+ All these requests must contain the same IPROTO_STREAM_ID value.
1382
+
1383
+ A rollback will happen automatically if
1384
+ a disconnect occurs or the transaction timeout expires before the commit is possible.
1291
1385
1292
1386
Thus there are now multiple ways to do transactions:
1293
- with net_box and stream:begin() and stream:commit() or stream:rollback()
1387
+ with `` net_box `` `` stream:begin() `` and `` stream:commit() `` or `` stream:rollback() ``
1294
1388
which cause IPROTO_BEGIN and IPROTO_COMMIT or IPROTO_ROLLBACK with
1295
1389
the current value of stream.stream_id;
1296
1390
with :ref: `box.begin() <box-begin >` and :ref: `box.commit() <box-commit >` or :ref: `box.rollback() <box-rollback >`;
0 commit comments