Skip to content

Commit

Permalink
fix issue #81 - incorrect partition id in sst mode (#82)
Browse files Browse the repository at this point in the history
* fix issue #81

* take care of endianess when converting byte array to long

* take care of endieness in a good way
  • Loading branch information
xiajingchun authored Jun 29, 2022
1 parent d6bc88c commit 3506fd5
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3506fd5

Please sign in to comment.