From 186540c112df9c1a2e467fe99b36d0cc13256535 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 15 Dec 2023 20:20:46 +0800 Subject: [PATCH] cls/queue: always set member variables in ctor 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 --- src/cls/2pc_queue/cls_2pc_queue_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cls/2pc_queue/cls_2pc_queue_types.h b/src/cls/2pc_queue/cls_2pc_queue_types.h index b270c9d6e790b..093b69cb193d3 100644 --- a/src/cls/2pc_queue/cls_2pc_queue_types.h +++ b/src/cls/2pc_queue/cls_2pc_queue_types.h @@ -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) {} -- 2.39.5