From 9e5e6f2e98e157ce29e040b6c7166ce955dcab91 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 17 Aug 2020 15:17:09 +0800 Subject: [PATCH] fix(guid): compatible with OTP 23 --- src/emqx_guid.erl | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/emqx_guid.erl b/src/emqx_guid.erl index d7f1785e8..79e445d73 100644 --- a/src/emqx_guid.erl +++ b/src/emqx_guid.erl @@ -39,6 +39,10 @@ , from_base62/1 ]). +-define(TAG_VERSION, 131). +-define(PID_EXT, 103). +-define(NEW_PID_EXT, 88). + -define(MAX_SEQ, 16#FFFF). -type(guid() :: <<_:128>>). @@ -77,17 +81,28 @@ npid() -> NodeD16, NodeD17, NodeD18, NodeD19, NodeD20>> = crypto:hash(sha, erlang:list_to_binary(erlang:atom_to_list(node()))), - % later, when the pid format changes, handle the different format - ExternalTermFormatVersion = 131, - PidExtType = 103, - <> = erlang:term_to_binary(self()), - % 72 bits for the Erlang pid + PidBin = + case erlang:term_to_binary(self()) of + <> -> + binary:part(B, erlang:byte_size(B), -9); + % format supported in Erlang/OTP 19.0-rc1 + % required for Erlang/OTP 23.0 (and Erlang/OTP 22.0-rc2) + <> -> + binary:part(B, erlang:byte_size(B), -12) + end, + + % 72/86 bits for the Erlang pid <> = binary:part(PidBin, erlang:byte_size(PidBin), -9), + PidCreation/binary % Node Creation Count + >> = PidBin, + + PidCR1 = case PidCreation of + <> -> + D1; + <> -> + D1 bxor D2 bxor D3 bxor D4 + end, % reduce the 160 bit NodeData checksum to 16 bits NodeByte1 = ((((((((NodeD01 bxor NodeD02)