]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/queue: always set member variables in ctor 54920/head
authorKefu Chai <tchaikov@gmail.com>
Fri, 15 Dec 2023 12:20:46 +0000 (20:20 +0800)
committerKefu Chai <tchaikov@gmail.com>
Fri, 15 Dec 2023 14:24:31 +0000 (22:24 +0800)
this should address the test failures like

```
/tmp/typ-WWFeFl6yK /tmp/typ-sMfwoaGMU differ: byte 24, line 1
**** cls_2pc_reservation test 2 binary reencode check failed ****
   ceph-dencoder type cls_2pc_reservation select_test 2 encode export /tmp/typ-WWFeFl6yK
   ceph-dencoder type cls_2pc_reservation select_test 2 encode decode encode export /tmp/typ-sMfwoaGMU
2c2
00000010  00 00 00 00 00 00 c0 c6  92 10                    |..........|
---
00000010  00 00 00 00 00 00 c0 e6  cd 53                    |.........S|
```

where we
1. encode the 2nd sample created by `generate_test_instances()`,
2. encode, decode, and encode again, the same sample

and compare the encoded blobs.

but if we fail to set any of the fields in `cls_2pc_reservation`,
we are at the mercy of the random bits on stack/heap.

in this change, all bits are initialized.

the flaky test was introduced by 1d7cabf3

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/cls/2pc_queue/cls_2pc_queue_types.h

index b270c9d6e790b45abb71f5f99e6fa04df2440f51..093b69cb193d31685633c7fada12069a05114ccc 100644 (file)
@@ -8,9 +8,9 @@ struct cls_2pc_reservation
 {
   using id_t = uint32_t;
   inline static const id_t NO_ID{0};
-  uint64_t size;                     // how much size to reserve (bytes)
+  uint64_t size = 0;                 // how much size to reserve (bytes)
   ceph::coarse_real_time timestamp;  // when the reservation was done (used for cleaning stale reservations)
-  uint32_t entries;                  // how many entries are reserved
+  uint32_t entries = 0;              // how many entries are reserved
 
   cls_2pc_reservation(uint64_t _size, ceph::coarse_real_time _timestamp, uint32_t _entries) :
       size(_size), timestamp(_timestamp), entries(_entries) {}