From 73647e57157a60999dd92c1f2d02d74b32e1238d Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Mon, 10 May 2021 12:59:57 -0700 Subject: [PATCH] wal_service: fix NodeId order/endian issues Add fixes suggested in code review. In a previous commit, I changed the NodeId field order and types to try to preserve the exact serialization that was happening. Unfortunately, that serialization was incorrect and the original struct was mostly correct. Change uuid to be a [u8; 16] as it was intended to be a byte array; that will clearly indicate to serde serializers that no endian swaps will ever be needed. --- walkeeper/src/wal_service.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/walkeeper/src/wal_service.rs b/walkeeper/src/wal_service.rs index f53b4418c0..ec97deded4 100644 --- a/walkeeper/src/wal_service.rs +++ b/walkeeper/src/wal_service.rs @@ -80,8 +80,8 @@ fn read_into(r: &mut impl Read, buf: &mut BytesMut) -> io::Result { /// Unique node identifier used by Paxos #[derive(Debug, Clone, Copy, Ord, PartialOrd, PartialEq, Eq, Serialize, Deserialize)] struct NodeId { - uuid: u128, - term: [u8; 8], + term: u64, + uuid: [u8; 16], } #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] @@ -227,8 +227,8 @@ impl SafeKeeperInfo { protocol_version: SK_PROTOCOL_VERSION, /* proxy-safekeeper protocol version */ pg_version: UNKNOWN_SERVER_VERSION, /* Postgres server version */ node_id: NodeId { - term: [0; 8], - uuid: 0, + term: 0, + uuid: [0; 16], }, system_id: 0, /* Postgres system identifier */ timeline_id: ZTimelineId::from([0u8; 16]), @@ -555,8 +555,8 @@ impl Connection { self.send()?; bail!( "Reject connection attempt with term {} because my term is {}", - hex::encode(prop.node_id.term), - hex::encode(my_info.server.node_id.term) + prop.node_id.term, + my_info.server.node_id.term, ); } my_info.server.node_id = prop.node_id;