From 3506fd5eacea101a4c4bcb8aa13e4a7212d85a4f Mon Sep 17 00:00:00 2001 From: "jingchun.xia" <6269380+xiajingchun@users.noreply.github.com> Date: Wed, 29 Jun 2022 17:25:39 +0800 Subject: [PATCH] fix issue #81 - incorrect partition id in sst mode (#82) * fix issue #81 * take care of endianess when converting byte array to long * take care of endieness in a good way --- .../vesoft/exchange/common/utils/NebulaUtils.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/exchange-common/src/main/scala/com/vesoft/exchange/common/utils/NebulaUtils.scala b/exchange-common/src/main/scala/com/vesoft/exchange/common/utils/NebulaUtils.scala index 9aea2295..68573b86 100644 --- a/exchange-common/src/main/scala/com/vesoft/exchange/common/utils/NebulaUtils.scala +++ b/exchange-common/src/main/scala/com/vesoft/exchange/common/utils/NebulaUtils.scala @@ -6,6 +6,9 @@ package com.vesoft.exchange.common.utils import java.nio.charset.Charset +import java.nio.ByteBuffer +import java.nio.ByteOrder + import com.google.common.primitives.UnsignedLong import com.vesoft.exchange.common.MetaProvider @@ -85,11 +88,18 @@ object NebulaUtils { s } + + def getPartitionId(id: String, partitionSize: Int, vidType: VidType.Value): Int = { val hashValue: Long = if (vidType == VidType.STRING) { // todo charset must be the same with Nebula Space val byteId = id.getBytes(Charset.forName("UTF-8")) - MurmurHash2.hash64(byteId, byteId.length, 0xc70f6907) + if (byteId.length == 8) { + //byte array to long, need to take care of endianess + ByteBuffer.wrap(byteId).order(ByteOrder.nativeOrder).getLong + } else { + MurmurHash2.hash64(byteId, byteId.length, 0xc70f6907) + } } else { id.toLong }