[Tarantool-patches] [PATCH v2 1/9] wal: enrich row's meta information with sync replication flags

Serge Petrenko sergepetrenko at tarantool.org
Tue Apr 13 16:51:52 MSK 2021



13.04.2021 14:50, Cyrill Gorcunov пишет:
> On Mon, Apr 12, 2021 at 10:40:14PM +0300, Serge Petrenko wrote:
>> Introduce two new flags to xrow_header: `wait_ack` and `wait_sync`.
>> These flags are set for rows belonging to synchronous transactions in
>> addition to `is_commit`.
>>
>> The new flags help to define whether the rows belong to a synchronous
>> transaction or not without parsing them all and checking whether any of
>> the rows touches a synchronous space.
>>
>> This will be used in applier once it is taught to filter synchronous
>> transactions based on whether they are coming from a raft leader or not.
>>
>> P.S. These flags will also be useful once we allow to turn any transaction
>> synchronous. Once this is done, the flags in row header will be the only
>> source of information on whether the transaction is synchronous or not.
>>
>> Prerequisite #5445
> Serge, here is a one addition: lets verify bitfields order. While their
> use indeed is suitable we should eliminate ourself from unpredicted results.
> The test is for c++ and probably we need one for plain c compiler as well?

Thanks for the help! I've added your tests with some changes.
What do you think?

===========================
diff --git a/test/unit/xrow.cc b/test/unit/xrow.cc
index ea1ee1767..3d7d8bee1 100644
--- a/test/unit/xrow.cc
+++ b/test/unit/xrow.cc
@@ -297,12 +297,49 @@ test_request_str()
      check_plan();
  }

+/**
+ * The compiler doesn't have to preserve bitfields order,
+ * still we rely on it for convenience sake.
+ */
+static void
+test_xrow_opt_field()
+{
+    plan(6);
+
+    struct xrow_header header;
+
+    memset(&header, 0, sizeof(header));
+
+    header.is_commit = true;
+    is(header.opt_flags, IPROTO_FLAG_COMMIT, "header.is_commit -> COMMIT");
+    header.is_commit = false;
+
+    header.wait_sync = true;
+    is(header.opt_flags, IPROTO_FLAG_WAIT_SYNC, "header.wait_sync -> 
WAIT_SYNC");
+    header.wait_sync = false;
+
+    header.wait_ack = true;
+    is(header.opt_flags, IPROTO_FLAG_WAIT_ACK, "header.wait_ack -> 
WAIT_ACK");
+    header.wait_ack = false;
+
+    header.opt_flags = IPROTO_FLAG_COMMIT;
+    ok(header.is_commit && !header.wait_sync && !header.wait_ack, 
"COMMIT -> header.is_commit");
+
+    header.opt_flags = IPROTO_FLAG_WAIT_SYNC;
+    ok(!header.is_commit && header.wait_sync && !header.wait_ack, 
"WAIT_SYNC -> header.wait_sync");
+
+    header.opt_flags = IPROTO_FLAG_WAIT_ACK;
+    ok(!header.is_commit && !header.wait_sync && header.wait_ack, 
"WAIT_ACK -> header.wait_ack");
+
+    check_plan();
+}
+
  int
  main(void)
  {
      memory_init();
      fiber_init(fiber_c_invoke);
-    plan(3);
+    plan(4);

      random_init();

@@ -310,6 +347,7 @@ main(void)
      test_greeting();
      test_xrow_header_encode_decode();
      test_request_str();
+    test_xrow_opt_field();

      random_free();
      fiber_free();
diff --git a/test/unit/xrow.result b/test/unit/xrow.result
index e06ba5261..3b705d5ba 100644
--- a/test/unit/xrow.result
+++ b/test/unit/xrow.result
@@ -1,4 +1,4 @@
-1..3
+1..4
      1..40
      ok 1 - round trip
      ok 2 - roundtrip.version_id
@@ -159,3 +159,11 @@ ok 2 - subtests
      1..1
      ok 1 - request_str
  ok 3 - subtests
+    1..6
+    ok 1 - header.is_commit -> COMMIT
+    ok 2 - header.wait_sync -> WAIT_SYNC
+    ok 3 - header.wait_ack -> WAIT_ACK
+    ok 4 - COMMIT -> header.is_commit
+    ok 5 - WAIT_SYNC -> header.wait_sync
+    ok 6 - WAIT_ACK -> header.wait_ack
+ok 4 - subtests

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list