mirror of
https://github.com/wassname/ray.git
synced 2026-08-08 11:25:28 +08:00
Fix reusing the cached hash of nil ID (#7753)
This commit is contained in:
@@ -372,7 +372,7 @@ ObjectID ObjectID::GenerateObjectId(const std::string &task_id_binary,
|
||||
ObjectIDFlagsType flags,
|
||||
ObjectIDIndexType object_index) {
|
||||
RAY_CHECK(task_id_binary.size() == TaskID::Size());
|
||||
ObjectID ret = ObjectID::Nil();
|
||||
ObjectID ret;
|
||||
std::memcpy(ret.id_, task_id_binary.c_str(), TaskID::kLength);
|
||||
std::memcpy(ret.id_ + TaskID::kLength, &flags, sizeof(flags));
|
||||
std::memcpy(ret.id_ + TaskID::kLength + kFlagsBytesLength, &object_index,
|
||||
|
||||
+1
-1
@@ -455,7 +455,7 @@ template <typename T>
|
||||
T BaseID<T>::FromBinary(const std::string &binary) {
|
||||
RAY_CHECK(binary.size() == T::Size() || binary.size() == 0)
|
||||
<< "expected size is " << T::Size() << ", but got " << binary.size();
|
||||
T t = T::Nil();
|
||||
T t;
|
||||
std::memcpy(t.MutableData(), binary.data(), binary.size());
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,16 @@ TEST(NilTest, TestIsNil) {
|
||||
ASSERT_TRUE(ObjectID::Nil().IsNil());
|
||||
}
|
||||
|
||||
TEST(HashTest, TestNilHash) {
|
||||
// Manually trigger the hash calculation of the static global nil ID.
|
||||
auto nil_hash = ObjectID::Nil().Hash();
|
||||
ObjectID id1 = ObjectID::FromRandom();
|
||||
ASSERT_NE(nil_hash, id1.Hash());
|
||||
ObjectID id2 = ObjectID::FromBinary(ObjectID::FromRandom().Binary());
|
||||
ASSERT_NE(nil_hash, id2.Hash());
|
||||
ASSERT_NE(id1.Hash(), id2.Hash());
|
||||
}
|
||||
|
||||
} // namespace ray
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user