[ 
https://issues.apache.org/jira/browse/GEODE-9753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17496385#comment-17496385
 ] 

ASF GitHub Bot commented on GEODE-9753:
---------------------------------------

pivotal-jbarrett commented on a change in pull request #891:
URL: https://github.com/apache/geode-native/pull/891#discussion_r812447039



##########
File path: cppcache/src/PdxHelper.cpp
##########
@@ -137,28 +136,18 @@ void PdxHelper::serializePdx(
     // so we don't know whether user has used those or not;; Can we do some
     // trick here?
 
-    auto createPdxRemoteWriter = [&]() -> PdxRemoteWriter {
-      if (auto pd = pdxTypeRegistry->getPreserveData(pdxObject)) {
-        auto mergedPdxType = 
pdxTypeRegistry->getPdxType(pd->getMergedTypeId());
-        return PdxRemoteWriter(output, mergedPdxType, pd, pdxTypeRegistry);
-      } else {
-        return PdxRemoteWriter(output, className, pdxTypeRegistry);
-      }
-    };
+    auto prw = cacheImpl->getPdxRemoteWriterFactory().create(
+        output, pdxObject, pdxTypeRegistry, localPdxType);
 
-    PdxRemoteWriter prw = createPdxRemoteWriter();
-
-    pdxObject->toData(prw);
-    prw.endObjectWriting();
+    pdxObject->toData(*prw);
+    prw->endObjectWriting();
 
     //[ToDo] need to write bytes for stats
-    if (cacheImpl != nullptr) {
-      uint8_t* stPos = const_cast<uint8_t*>(output.getBuffer()) +
-                       prw.getStartPositionOffset();
-      int pdxLen = PdxHelper::readInt32(stPos);
-      cachePerfStats.incPdxSerialization(
-          pdxLen + 1 + 2 * 4);  // pdxLen + 93 DSID + len + typeID
-    }
+    uint8_t* stPos = const_cast<uint8_t*>(output.getBuffer()) +

Review comment:
       Any idea why there was a `nullptr` check here?

##########
File path: cppcache/src/PdxHelper.cpp
##########
@@ -121,13 +122,11 @@ void PdxHelper::serializePdx(
     pdxTypeRegistry->addLocalPdxType(className, nType);
     pdxTypeRegistry->addPdxType(nTypeId, nType);
 
-    if (cacheImpl != nullptr) {
-      uint8_t* stPos = const_cast<uint8_t*>(output.getBuffer()) +
-                       ptc.getStartPositionOffset();
-      int pdxLen = PdxHelper::readInt32(stPos);
-      cachePerfStats.incPdxSerialization(
-          pdxLen + 1 + 2 * 4);  // pdxLen + 93 DSID + len + typeID
-    }
+    uint8_t* stPos =

Review comment:
       `auto`

##########
File path: cppcache/src/PdxRemoteWriter.cpp
##########
@@ -49,18 +49,18 @@ PdxRemoteWriter::PdxRemoteWriter(
 }
 
 PdxRemoteWriter::PdxRemoteWriter(
-    DataOutput& output, std::string pdxClassName,
+    DataOutput& output, std::shared_ptr<PdxType> pdxType,
     std::shared_ptr<PdxTypeRegistry> pdxTypeRegistry)
-    : PdxLocalWriter(output, nullptr, pdxClassName, pdxTypeRegistry),
+    : PdxLocalWriter(output, pdxType, pdxTypeRegistry),
       m_preserveDataIdx(0),
       m_currentDataIdx(-1),
       m_remoteTolocalMapLength(0) {
-  m_preserveData = nullptr;
   if (m_pdxType != nullptr) {
-    m_remoteTolocalMapLength = m_pdxType->getTotalFields();
     m_remoteTolocalMap = m_pdxType->getRemoteToLocalMap();
+    m_remoteTolocalMapLength = m_pdxType->getTotalFields();
   }
-  initialize();
+
+  m_pdxClassName = pdxType->getPdxClassName();

Review comment:
       If `pdxType` is nullable then this line will throw.

##########
File path: cppcache/src/PdxRemoteWriterFactoryImpl.cpp
##########
@@ -0,0 +1,47 @@
+/*
+ * 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 "PdxRemoteWriterFactoryImpl.hpp"
+
+#include "PdxRemoteWriter.hpp"
+#include "PdxType.hpp"
+#include "PdxTypeRegistry.hpp"
+#include "util/cxx_extensions.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+PdxRemoteWriterFactoryImpl::~PdxRemoteWriterFactoryImpl() = default;
+
+std::unique_ptr<PdxRemoteWriter> PdxRemoteWriterFactoryImpl::create(

Review comment:
       It really seems like you could test this at unit level by mocking 
`PdxTypeRegistery` and `PdxType`. Make this a member function back from where 
it came and test it a the unit level. This avoids the creation of this factory, 
the exporting of internal symbols, and the interdiction of artificial behavior 
into the production implementation, via overriding this implementation.

##########
File path: cppcache/src/PdxHelper.cpp
##########
@@ -137,28 +136,18 @@ void PdxHelper::serializePdx(
     // so we don't know whether user has used those or not;; Can we do some
     // trick here?
 
-    auto createPdxRemoteWriter = [&]() -> PdxRemoteWriter {
-      if (auto pd = pdxTypeRegistry->getPreserveData(pdxObject)) {
-        auto mergedPdxType = 
pdxTypeRegistry->getPdxType(pd->getMergedTypeId());
-        return PdxRemoteWriter(output, mergedPdxType, pd, pdxTypeRegistry);
-      } else {
-        return PdxRemoteWriter(output, className, pdxTypeRegistry);
-      }
-    };
+    auto prw = cacheImpl->getPdxRemoteWriterFactory().create(
+        output, pdxObject, pdxTypeRegistry, localPdxType);
 
-    PdxRemoteWriter prw = createPdxRemoteWriter();
-
-    pdxObject->toData(prw);
-    prw.endObjectWriting();
+    pdxObject->toData(*prw);
+    prw->endObjectWriting();
 
     //[ToDo] need to write bytes for stats
-    if (cacheImpl != nullptr) {
-      uint8_t* stPos = const_cast<uint8_t*>(output.getBuffer()) +
-                       prw.getStartPositionOffset();
-      int pdxLen = PdxHelper::readInt32(stPos);
-      cachePerfStats.incPdxSerialization(
-          pdxLen + 1 + 2 * 4);  // pdxLen + 93 DSID + len + typeID
-    }
+    uint8_t* stPos = const_cast<uint8_t*>(output.getBuffer()) +

Review comment:
       `auto`

##########
File path: cppcache/src/PdxRemoteWriter.cpp
##########
@@ -49,18 +49,18 @@ PdxRemoteWriter::PdxRemoteWriter(
 }
 
 PdxRemoteWriter::PdxRemoteWriter(
-    DataOutput& output, std::string pdxClassName,
+    DataOutput& output, std::shared_ptr<PdxType> pdxType,
     std::shared_ptr<PdxTypeRegistry> pdxTypeRegistry)
-    : PdxLocalWriter(output, nullptr, pdxClassName, pdxTypeRegistry),
+    : PdxLocalWriter(output, pdxType, pdxTypeRegistry),
       m_preserveDataIdx(0),
       m_currentDataIdx(-1),
       m_remoteTolocalMapLength(0) {
-  m_preserveData = nullptr;
   if (m_pdxType != nullptr) {

Review comment:
       If `pdxType` is not nullable then this check is unnecessary. 

##########
File path: cppcache/src/PdxRemoteWriter.hpp
##########
@@ -45,10 +47,10 @@ class PdxRemoteWriter : public PdxLocalWriter {
   PdxRemoteWriter() = default;
 
   PdxRemoteWriter(DataOutput& output, std::shared_ptr<PdxType> pdxType,
-                  std::shared_ptr<PdxRemotePreservedData> preservedData,
                   std::shared_ptr<PdxTypeRegistry> pdxTypeRegistry);
 
-  PdxRemoteWriter(DataOutput& output, std::string pdxClassName,
+  PdxRemoteWriter(DataOutput& output, std::shared_ptr<PdxType> pdxType,
+                  std::shared_ptr<PdxRemotePreservedData> preservedData,

Review comment:
       It this really feels like an extension of the other constructor with the 
optional `preservedData` parameters to maybe re-order the parameters to look 
like that.




-- 
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-unsubscr...@geode.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Coredump during PdxSerializable object serialization
> ----------------------------------------------------
>
>                 Key: GEODE-9753
>                 URL: https://issues.apache.org/jira/browse/GEODE-9753
>             Project: Geode
>          Issue Type: Bug
>          Components: native client
>            Reporter: Mario Salazar de Torres
>            Assignee: Mario Salazar de Torres
>            Priority: Major
>              Labels: needsTriage, pull-request-available
>
> *GIVEN*  **a  single server and locator cluster with 1 PdxSerializable class 
> registered, named Order
>    *AND* a geode-native client with 1 PdxSerializable 1 PdxSerializable class 
> registered, named Order
>  *WHEN* a Order object is tried to be serialized
>    *WHILE* the cluster is being restarted
> *THEN* a coredump happens due to PdxType=nullptr
> —
> *Additional information*. As seen by early troubleshooting, the coredump 
> happens because the pdx type is tried to be fetched from the PdxTypeRegist by 
> its class name, but the PdxTypeRegistry is cleaned up during serialization 
> given that subscription redundancy was lost.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to