You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/05/10 14:05:14 UTC
[GitHub] [geode-native] gaussianrecurrence opened a new pull request, #969: GEODE-10276: Refactor PDX (de)serialization code
gaussianrecurrence opened a new pull request, #969:
URL: https://github.com/apache/geode-native/pull/969
- Code related to PDX de(serialization) has been refactored and aligned
(in all possible means) to the Java client, solving the following
issues:
* GEODE-9968 - Fix deserialization for new fields in PdxSerializable
class
* GEODE-9753 - Coredump during PdxSerializable object serialization
* GEODE-10220 - Coredump while initializing PdxType remoteToLocal
* GEODE-10255 - PdxSerializable not working correctly for multiple
versions of the same class
- Reverted GEODE-8212, to solve potential issues during (de)serialization.
This is due to the fact that the server orders PdxType fields
sequentially, rather than alphabetically.
- In order to achieve what was originally intended with GEODE-8212,
now PdxInstances fields are written in alphabetical order, rather
than in the order writeXX is called.
- Also, code now should be easier to understand
- Several tests modified to adapt to code changes
- Added several UTs to further incrase coverage on PDX (de)serialization code.
- Added several ITs to verify PDX (de)serialization scenarios.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] pivotal-jbarrett commented on pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on PR #969:
URL: https://github.com/apache/geode-native/pull/969#issuecomment-1122447052
OMG! Awesome effort!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] pivotal-jbarrett commented on a diff in pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #969:
URL: https://github.com/apache/geode-native/pull/969#discussion_r869292240
##########
cppcache/src/CacheableObjectArray.cpp:
##########
@@ -53,6 +54,18 @@ size_t CacheableObjectArray::objectSize() const {
}
return size;
}
+
+std::string CacheableObjectArray::getClassName() const {
+ if (!empty()) {
+ auto&& item = *begin();
+
+ if (auto pdx = dynamic_cast<PdxSerializable*>(item.get())) {
+ return pdx->getClassName();
+ }
+ }
+
+ return "java.lang.Object";
Review Comment:
What if we make this string a `const` value in this compilation unit and change the return type of this method to return `const std::string&` so we aren't copy constructing strings on return.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] gaussianrecurrence commented on a diff in pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
gaussianrecurrence commented on code in PR #969:
URL: https://github.com/apache/geode-native/pull/969#discussion_r869351686
##########
cppcache/integration/test/PdxInstanceTest.cpp:
##########
@@ -268,7 +268,7 @@ TEST(PdxInstanceTest, testPdxInstance) {
pdxTypeFromPdxTypeInstance->equals(*pdxTypeFromPdxTypeInstanceGet, false))
<< "PdxObjects should be equal.";
- EXPECT_EQ(-960665662, pdxTypeInstance->hashcode())
+ EXPECT_EQ(514863279, pdxTypeInstance->hashcode())
Review Comment:
Damn, I did not thought of the fact that it was possible to use a PdxInstance as a key. Really thanks for pointing this out,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] pivotal-jbarrett commented on a diff in pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #969:
URL: https://github.com/apache/geode-native/pull/969#discussion_r869330026
##########
cppcache/integration/test/PdxInstanceTest.cpp:
##########
@@ -268,7 +268,7 @@ TEST(PdxInstanceTest, testPdxInstance) {
pdxTypeFromPdxTypeInstance->equals(*pdxTypeFromPdxTypeInstanceGet, false))
<< "PdxObjects should be equal.";
- EXPECT_EQ(-960665662, pdxTypeInstance->hashcode())
+ EXPECT_EQ(514863279, pdxTypeInstance->hashcode())
Review Comment:
Why did this hash code change? Are we certain it matches the same hash that the server produces for it? If not this can lead to really bad single hop performance.
##########
tests/javaobject/PdxTests/DeliveryAddress.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package PdxTests;
+
+import java.util.Vector;
+import org.apache.geode.pdx.PdxReader;
+import org.apache.geode.pdx.PdxSerializable;
+import org.apache.geode.pdx.PdxWriter;
+
+public class DeliveryAddress implements PdxSerializable
+{
+ String _addressLine;
Review Comment:
Geode's Java conventions come from the Google Java Style Guide. Please don't prefix member variables. Also please make this private.
##########
cppcache/integration/test/PdxSerializableTest.cpp:
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <framework/Cluster.h>
+
+#include <iostream>
+#include <memory>
+
+#include <gtest/gtest.h>
+
+#include <geode/Cache.hpp>
+#include <geode/FunctionService.hpp>
+#include <geode/PdxWrapper.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+#include <geode/TypeRegistry.hpp>
+
+#include "DeliveryAddress.hpp"
+
+namespace {
+
+using apache::geode::client::Cache;
+using apache::geode::client::Cacheable;
+using apache::geode::client::CacheableString;
+using apache::geode::client::CacheableVector;
+using apache::geode::client::FunctionService;
+using apache::geode::client::PdxReader;
+using apache::geode::client::PdxSerializable;
+using apache::geode::client::PdxWriter;
+using apache::geode::client::Region;
+using apache::geode::client::RegionShortcut;
+
+using PdxTests::DeliveryAddress;
+
+std::shared_ptr<Region> setupRegion(Cache& cache) {
+ auto region = cache.createRegionFactory(RegionShortcut::PROXY)
+ .setPoolName("default")
+ .create("region");
+
+ return region;
+}
+
+/**
+ * This test perform the following steps:
+ * 1. Writes a version 1 entry of DeliveryAddress named 'entry.v1'
+ * 2. From another cache, fetches the entry 'entry.v1'
+ * 3. From the same cache as step 2, it call function PutDeliveryAddress that
+ * writes a version 2 entry of DeliveryAddress named 'entry.v2'
+ * 4. From another cache, try to fetch the entry 'entry.v2' and it should match
+ * the entry written in step 3
+ *
+ * The purpose of this test is to verify that even if there are 2 versions of
+ * the same PdxSerializable class, the right PdxType will be used during
+ * (de)serialization
+ */
+TEST(PdxSerializableTest, testRightPdxTypeForDiffPdxVersions) {
+ Cluster cluster{LocatorCount{1}, ServerCount{1}};
+ cluster.start([&]() {
+ cluster.getGfsh()
+ .deploy()
+ .jar(getFrameworkString(FrameworkVariable::JavaObjectJarPath))
+ .execute();
+ });
+ cluster.getGfsh()
+ .create()
+ .region()
+ .withName("region")
+ .withType("REPLICATE")
+ .execute();
+
+ std::shared_ptr<DeliveryAddress> entryV1;
+ std::shared_ptr<DeliveryAddress> entryV2;
+
+ {
+ auto cache = cluster.createCache();
+ auto region = setupRegion(cache);
+ cache.getTypeRegistry().registerPdxType(
+ DeliveryAddress::createDeserializable);
+
+ DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1);
+ entryV1 = std::make_shared<DeliveryAddress>(
+ "Some address line", "Some city", "Some country", std::string{},
+ std::shared_ptr<CacheableVector>{});
+
+ region->put("entry.v1", entryV1);
+ }
+
+ {
+ auto cache = cluster.createCache();
+ auto region = setupRegion(cache);
+ cache.getTypeRegistry().registerPdxType(
+ DeliveryAddress::createDeserializable);
+
+ DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1);
+ auto entry = region->get("entry.v1");
+ EXPECT_TRUE(entry);
+
+ auto address = std::dynamic_pointer_cast<DeliveryAddress>(entry);
+ EXPECT_TRUE(address);
+ EXPECT_EQ(*entryV1, *address);
Review Comment:
Please use the `EXPECT_THAT` or `ASSERT_THAT` form over the older `EXPECT_*` and `ASSERT_*` macros.
```c++
EXPECT_THAT(*entryV1, Eq(*address));
```
https://google.github.io/googletest/reference/matchers.html
##########
cppcache/src/CacheImpl.hpp:
##########
@@ -134,6 +134,12 @@ class APACHE_GEODE_EXPORT CacheImpl {
*/
DistributedSystem& getDistributedSystem();
Review Comment:
Any chance this non `const` version can be refactored out?
##########
cppcache/integration/test/PdxSerializableTest.cpp:
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <framework/Cluster.h>
+
+#include <iostream>
+#include <memory>
+
+#include <gtest/gtest.h>
+
+#include <geode/Cache.hpp>
+#include <geode/FunctionService.hpp>
+#include <geode/PdxWrapper.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+#include <geode/TypeRegistry.hpp>
+
+#include "DeliveryAddress.hpp"
+
+namespace {
+
+using apache::geode::client::Cache;
+using apache::geode::client::Cacheable;
+using apache::geode::client::CacheableString;
+using apache::geode::client::CacheableVector;
+using apache::geode::client::FunctionService;
+using apache::geode::client::PdxReader;
+using apache::geode::client::PdxSerializable;
+using apache::geode::client::PdxWriter;
+using apache::geode::client::Region;
+using apache::geode::client::RegionShortcut;
+
+using PdxTests::DeliveryAddress;
+
+std::shared_ptr<Region> setupRegion(Cache& cache) {
+ auto region = cache.createRegionFactory(RegionShortcut::PROXY)
+ .setPoolName("default")
+ .create("region");
+
+ return region;
+}
+
+/**
+ * This test perform the following steps:
+ * 1. Writes a version 1 entry of DeliveryAddress named 'entry.v1'
+ * 2. From another cache, fetches the entry 'entry.v1'
+ * 3. From the same cache as step 2, it call function PutDeliveryAddress that
+ * writes a version 2 entry of DeliveryAddress named 'entry.v2'
+ * 4. From another cache, try to fetch the entry 'entry.v2' and it should match
+ * the entry written in step 3
+ *
+ * The purpose of this test is to verify that even if there are 2 versions of
+ * the same PdxSerializable class, the right PdxType will be used during
+ * (de)serialization
+ */
+TEST(PdxSerializableTest, testRightPdxTypeForDiffPdxVersions) {
+ Cluster cluster{LocatorCount{1}, ServerCount{1}};
+ cluster.start([&]() {
+ cluster.getGfsh()
+ .deploy()
+ .jar(getFrameworkString(FrameworkVariable::JavaObjectJarPath))
+ .execute();
+ });
+ cluster.getGfsh()
+ .create()
+ .region()
+ .withName("region")
+ .withType("REPLICATE")
+ .execute();
+
+ std::shared_ptr<DeliveryAddress> entryV1;
+ std::shared_ptr<DeliveryAddress> entryV2;
+
+ {
+ auto cache = cluster.createCache();
+ auto region = setupRegion(cache);
+ cache.getTypeRegistry().registerPdxType(
+ DeliveryAddress::createDeserializable);
+
+ DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1);
+ entryV1 = std::make_shared<DeliveryAddress>(
+ "Some address line", "Some city", "Some country", std::string{},
+ std::shared_ptr<CacheableVector>{});
+
+ region->put("entry.v1", entryV1);
+ }
+
+ {
+ auto cache = cluster.createCache();
+ auto region = setupRegion(cache);
+ cache.getTypeRegistry().registerPdxType(
+ DeliveryAddress::createDeserializable);
+
+ DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1);
+ auto entry = region->get("entry.v1");
+ EXPECT_TRUE(entry);
+
+ auto address = std::dynamic_pointer_cast<DeliveryAddress>(entry);
+ EXPECT_TRUE(address);
+ EXPECT_EQ(*entryV1, *address);
+
+ DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_2);
+ entryV2 = std::make_shared<DeliveryAddress>(
+ "Some address line", "Some city", "Some country", "Some instructions",
+ std::shared_ptr<CacheableVector>{});
+
+ auto args = CacheableVector::create();
+ args->push_back(CacheableString::create("region"));
+ args->push_back(CacheableString::create("entry.v2"));
+ args->push_back(CacheableString::create("Some address line"));
+ args->push_back(CacheableString::create("Some city"));
+ args->push_back(CacheableString::create("Some country"));
+ args->push_back(CacheableString::create("Some instructions"));
+
+ auto collector = FunctionService::onServer(region->getRegionService())
+ .withArgs(args)
+ .execute("PutDeliveryAddress");
+ EXPECT_TRUE(collector);
+
+ auto resultSet = collector->getResult();
+ EXPECT_TRUE(resultSet);
+
+ auto result = std::dynamic_pointer_cast<CacheableString>((*resultSet)[0]);
+ std::cerr << result->toString() << std::endl;
+ }
+
+ {
+ auto cache = cluster.createCache();
+ auto region = setupRegion(cache);
+ cache.getTypeRegistry().registerPdxType(
+ DeliveryAddress::createDeserializable);
+
+ auto entry = region->get("entry.v2");
+ EXPECT_TRUE(entry);
Review Comment:
This, and all the other `std::shared_ptr` nullability checks, should be `EXPECT_THAT(entry, IsNotNull())`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] gaussianrecurrence commented on a diff in pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
gaussianrecurrence commented on code in PR #969:
URL: https://github.com/apache/geode-native/pull/969#discussion_r869428049
##########
cppcache/src/CacheImpl.hpp:
##########
@@ -134,6 +134,12 @@ class APACHE_GEODE_EXPORT CacheImpl {
*/
DistributedSystem& getDistributedSystem();
Review Comment:
Seems feasible :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] gaussianrecurrence commented on pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
gaussianrecurrence commented on PR #969:
URL: https://github.com/apache/geode-native/pull/969#issuecomment-1122476087
> I realize this is a draft but was excited to take a peek and noticed this one right away.
Yes, this is a WIP, there are some minor changes i yet want to make, and whole lot more of tests that I want to add, given the size of the change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GEODE-10276: Refactor PDX (de)serialization code [geode-native]
Posted by "gaussianrecurrence (via GitHub)" <gi...@apache.org>.
gaussianrecurrence commented on PR #969:
URL: https://github.com/apache/geode-native/pull/969#issuecomment-1816770033
I haven't had the time to work on this for a long time or I think I'll have the opportunity to in the near future, hence I am closing this PR, if anyone wants to tackle this issue can take it up from its latest state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] gaussianrecurrence commented on a diff in pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
gaussianrecurrence commented on code in PR #969:
URL: https://github.com/apache/geode-native/pull/969#discussion_r869302660
##########
cppcache/src/CacheableObjectArray.cpp:
##########
@@ -53,6 +54,18 @@ size_t CacheableObjectArray::objectSize() const {
}
return size;
}
+
+std::string CacheableObjectArray::getClassName() const {
+ if (!empty()) {
+ auto&& item = *begin();
+
+ if (auto pdx = dynamic_cast<PdxSerializable*>(item.get())) {
+ return pdx->getClassName();
+ }
+ }
+
+ return "java.lang.Object";
Review Comment:
Thanks for pointing it out :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode-native] gaussianrecurrence commented on pull request #969: GEODE-10276: Refactor PDX (de)serialization code
Posted by GitBox <gi...@apache.org>.
gaussianrecurrence commented on PR #969:
URL: https://github.com/apache/geode-native/pull/969#issuecomment-1130249492
@pivotal-jbarrett I've addressed all of your comments, plus I've fixed some logic issues and introduced some changes, mostly to cover all edge cases. Additionally, added a bunch of new tests to verify the functionality refactored by the change. So long store sort, I've marked the PR as ready for review, any comments are welcomed :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GEODE-10276: Refactor PDX (de)serialization code [geode-native]
Posted by "gaussianrecurrence (via GitHub)" <gi...@apache.org>.
gaussianrecurrence closed pull request #969: GEODE-10276: Refactor PDX (de)serialization code
URL: https://github.com/apache/geode-native/pull/969
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org