[
https://issues.apache.org/jira/browse/GEODE-9968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17478784#comment-17478784
]
ASF GitHub Bot commented on GEODE-9968:
---------------------------------------
pivotal-jbarrett commented on a change in pull request #910:
URL: https://github.com/apache/geode-native/pull/910#discussion_r787880338
##########
File path: cppcache/integration/test/PdxSerializableTest.cpp
##########
@@ -0,0 +1,178 @@
+/*
+ * 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 <gmock/gmock.h>
+
+#include <memory>
+#include <random>
+
+#include <gtest/gtest.h>
+
+#include <geode/Cache.hpp>
+#include <geode/CacheableDate.hpp>
+#include <geode/EntryEvent.hpp>
+#include <geode/PdxWrapper.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionEvent.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+
+#include "CacheImpl.hpp"
+#include "CacheRegionHelper.hpp"
+#include "testobject/PdxType.hpp"
+
+namespace {
+
+using apache::geode::client::Cache;
+using apache::geode::client::CacheableDate;
+using apache::geode::client::CacheableString;
+using apache::geode::client::CacheFactory;
+using apache::geode::client::CacheRegionHelper;
+using apache::geode::client::PdxReader;
+using apache::geode::client::PdxSerializable;
+using apache::geode::client::Region;
+using apache::geode::client::RegionEvent;
+using apache::geode::client::RegionShortcut;
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+
+using PdxTests::DynamicFieldsType;
+
+namespace {
+constexpr auto DYNAMIC_FIELDS_TYPE_MODIFIERS_COUNT = 22;
+std::function<void(DynamicFieldsType&)>
+ DYNAMIC_FIELDS_TYPE_MODIFIERS[DYNAMIC_FIELDS_TYPE_MODIFIERS_COUNT] = {
+ [](DynamicFieldsType& obj) { obj.setChar('a'); },
+ [](DynamicFieldsType& obj) { obj.setBoolean(false); },
+ [](DynamicFieldsType& obj) { obj.setByte(1); },
+ [](DynamicFieldsType& obj) { obj.setShort(2); },
+ [](DynamicFieldsType& obj) { obj.setInt(3); },
+ [](DynamicFieldsType& obj) { obj.setLong(5); },
+ [](DynamicFieldsType& obj) { obj.setFloat(8.f); },
+ [](DynamicFieldsType& obj) { obj.setDouble(13.); },
+ [](DynamicFieldsType& obj) { obj.setString("Test string"); },
+ [](DynamicFieldsType& obj) {
+ obj.setDate(CacheableDate::create(CacheableDate::clock::now()));
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setDate(CacheableDate::create(CacheableDate::clock::now()));
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setObject(CacheableString::create("An object string"));
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setCharArray({'a', 'b', 'c'});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setBooleanArray({false, true, false});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setByteArray({21, 34, 55});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setByteArray({21, 34, 55});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setShortArray({89, 144, 233});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setIntArray({377, 610, 987});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setLongArray({1597, 2584, 4181});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setFloatArray({7402.f, 11583.f, 18985.f});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setDoubleArray({30568., 49553., 80121.});
+ },
+ [](DynamicFieldsType& obj) {
+ obj.setStringArray({"A test string", "Another test string",
+ "Yet another test string"});
+ },
+};
+} // namespace
+
+Cache createTestCache() {
+ CacheFactory cacheFactory;
+ return cacheFactory.set("log-level", "none")
+ .set("statistic-sampling-enabled", "false")
+ .create();
+}
+
+TEST(PdxSerializableTest, deserializeNewFields) {
+ Cluster cluster{LocatorCount{1}, ServerCount{1}};
+ cluster.start();
+
+ auto& gfsh = cluster.getGfsh();
+ gfsh.create().region().withName("region").withType("REPLICATE").execute();
+
+ auto cache = createTestCache();
+ {
+ auto poolFactory = cache.getPoolManager().createFactory();
+ cluster.applyLocators(poolFactory);
+ poolFactory.create("default");
+ }
+
+ auto region = cache.createRegionFactory(RegionShortcut::CACHING_PROXY)
+ .setPoolName("default")
+ .create("region");
+
+ cache.getTypeRegistry().registerPdxType(
+ DynamicFieldsType::createDeserializable);
+
+ auto entry = std::make_shared<DynamicFieldsType>(2, "Line 1", "Line 2");
+ region->put("1", entry);
+
+ auto entryFetched = region->get("1");
+ ASSERT_TRUE(entryFetched);
+
+ auto address = std::dynamic_pointer_cast<DynamicFieldsType>(entryFetched);
+ ASSERT_TRUE(address);
+
+ ASSERT_EQ(*entry, *address);
+
+ // This mechanism guarantees that a different set of fields
+ // are introduced each execution in order ensure a proper behaviour
+ std::mt19937 generator{std::random_device{}()};
+ std::uniform_int_distribution<uint32_t> distribution(
+ 1, 1 << DYNAMIC_FIELDS_TYPE_MODIFIERS_COUNT);
+
+ entry = std::make_shared<DynamicFieldsType>(3, "Line 1", "Line 2");
+ auto mask = distribution(generator);
+ for (auto i = 0; i < DYNAMIC_FIELDS_TYPE_MODIFIERS_COUNT; ++i) {
+ if ((mask & (1ULL << i)) != 0) {
+ DYNAMIC_FIELDS_TYPE_MODIFIERS[i](*entry);
+ }
+ }
+
+ region->put("2", entry);
+
+ entryFetched = region->get("2");
+ ASSERT_TRUE(entryFetched);
+
+ address = std::dynamic_pointer_cast<DynamicFieldsType>(entryFetched);
+ ASSERT_TRUE(address);
+
+ ASSERT_EQ(*entry, *address);
+}
+
+} // namespace
Review comment:
Trailing new line needed.
##########
File path: cppcache/src/PdxRemoteReader.cpp
##########
@@ -34,571 +34,391 @@ PdxRemoteReader::~PdxRemoteReader() {
}
char16_t PdxRemoteReader::readChar(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2:
- return PdxLocalReader::readChar(fieldName); // in same order
- case -1: {
- return '\0'; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- auto retVal = PdxLocalReader::readChar(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return '\0';
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readChar(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
bool PdxRemoteReader::readBoolean(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readBoolean(fieldName); // in same order
- }
- case -1: {
- return 0; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- bool retVal = PdxLocalReader::readBoolean(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- } else {
- return 0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return false;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ bool result = PdxLocalReader::readBoolean(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
int8_t PdxRemoteReader::readByte(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readByte(fieldName); // in same order
- }
- case -1: {
- return 0;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- int8_t retValue;
- retValue = PdxLocalReader::readByte(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retValue;
- } else {
- return 0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readByte(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
int16_t PdxRemoteReader::readShort(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readShort(fieldName); // in same order
- }
- case -1: {
- return 0; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- int16_t value;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- value = PdxLocalReader::readShort(fieldName);
- PdxLocalReader::resettoPdxHead();
- return value;
- } else {
- return 0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readShort(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
int32_t PdxRemoteReader::readInt(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readInt(fieldName); // in same order
- }
- case -1: {
- return 0; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- int32_t value;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- value = PdxLocalReader::readInt(fieldName);
- PdxLocalReader::resettoPdxHead();
- return value;
- } else {
- return 0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readInt(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
int64_t PdxRemoteReader::readLong(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readLong(fieldName); // in same order
- }
- case -1: {
- return 0; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- int64_t value;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- value = PdxLocalReader::readLong(fieldName);
- PdxLocalReader::resettoPdxHead();
- return value;
- } else {
- return 0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readLong(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
float PdxRemoteReader::readFloat(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readFloat(fieldName); // in same order
- }
- case -1: {
- return 0.0f; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- float value;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- value = PdxLocalReader::readFloat(fieldName);
- PdxLocalReader::resettoPdxHead();
- return value;
- } else {
- return 0.0f; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0.f;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readFloat(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
double PdxRemoteReader::readDouble(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readDouble(fieldName); // in same order
- }
- case -1: {
- return 0.0; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- double value;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- value = PdxLocalReader::readDouble(fieldName);
- PdxLocalReader::resettoPdxHead();
- return value;
- } else {
- return 0.0; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return 0.;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readDouble(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::string PdxRemoteReader::readString(const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readString(fieldName);
- }
- case -1: {
- return std::string();
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- auto retVal = PdxLocalReader::readString(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- } else {
- static std::string emptyString;
- return emptyString;
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readString(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::shared_ptr<Serializable> PdxRemoteReader::readObject(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readObject(fieldName); // in same order
- }
- case -1: {
- return nullptr;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- std::shared_ptr<Serializable> ptr;
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- ptr = PdxLocalReader::readObject(fieldName);
- PdxLocalReader::resettoPdxHead();
- return ptr;
- } else {
- return nullptr; // null value
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return nullptr;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readObject(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<char16_t> PdxRemoteReader::readCharArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<char16_t> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readCharArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readCharArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readCharArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<bool> PdxRemoteReader::readBooleanArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<bool> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readBooleanArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readBooleanArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readBooleanArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<int8_t> PdxRemoteReader::readByteArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<int8_t> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readByteArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readByteArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readByteArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<int16_t> PdxRemoteReader::readShortArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<int16_t> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readShortArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readShortArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readShortArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<int32_t> PdxRemoteReader::readIntArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<int32_t> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readIntArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readIntArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readIntArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<int64_t> PdxRemoteReader::readLongArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<int64_t> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readLongArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readLongArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readLongArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<float> PdxRemoteReader::readFloatArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<float> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readFloatArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readFloatArray(fieldName); // in same order
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readFloatArray(fieldName); // in same order
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<double> PdxRemoteReader::readDoubleArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- std::vector<double> array;
- switch (choice) {
- case -2: {
- array = PdxLocalReader::readDoubleArray(fieldName); // in same order
- break;
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- array = PdxLocalReader::readDoubleArray(fieldName); // in same order
- PdxLocalReader::resettoPdxHead();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
- return array;
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readDoubleArray(fieldName); // in same order
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::vector<std::string> PdxRemoteReader::readStringArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2: {
- return PdxLocalReader::readStringArray(fieldName);
- }
- case -1: {
- return std::vector<std::string>();
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- if (position != -1) {
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- auto strArray = PdxLocalReader::readStringArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- return strArray;
- } else {
- return std::vector<std::string>();
- }
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readStringArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+
+ return result;
}
std::shared_ptr<CacheableObjectArray> PdxRemoteReader::readObjectArray(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2:
- return PdxLocalReader::readObjectArray(fieldName); // in same order
- case -1: {
- return nullptr; // null value
- }
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- auto retVal = PdxLocalReader::readObjectArray(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return {};
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readObjectArray(fieldName);
+ PdxLocalReader::resettoPdxHead();
+ return result;
}
int8_t** PdxRemoteReader::readArrayOfByteArrays(const std::string& fieldName,
int32_t& arrayLength,
int32_t** elementLength) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2:
- return PdxLocalReader::readArrayOfByteArrays(
- fieldName, arrayLength, elementLength); // in same order
- case -1:
- return nullptr; // null value
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- int8_t** retVal = PdxLocalReader::readArrayOfByteArrays(
- fieldName, arrayLength, elementLength);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
+ return nullptr;
}
+
+ PdxLocalReader::resettoPdxHead();
+ m_dataInput->advanceCursor(position);
+
+ auto result = PdxLocalReader::readArrayOfByteArrays(fieldName, arrayLength,
+ elementLength);
+
+ PdxLocalReader::resettoPdxHead();
+ return result;
}
std::shared_ptr<CacheableDate> PdxRemoteReader::readDate(
const std::string& fieldName) {
- int choice = m_localToRemoteMap[m_currentIndex++];
-
- switch (choice) {
- case -2:
- return PdxLocalReader::readDate(fieldName); // in same order
- case -1:
- return nullptr;
- default: {
- // sequence id read field and then update
- int position = m_pdxType->getFieldPosition(
- choice, m_offsetsBuffer, m_offsetSize, m_serializedLength);
- PdxLocalReader::resettoPdxHead();
- m_dataInput->advanceCursor(position);
- auto retVal = PdxLocalReader::readDate(fieldName);
- PdxLocalReader::resettoPdxHead();
- return retVal;
- }
+ int position = m_pdxType->getFieldPosition(fieldName, m_offsetsBuffer,
+ m_offsetSize, m_serializedLength);
+
+ if (position == -1) {
Review comment:
I wonder, if with all this refactoring, we should define a `constexpr`
for this `-1` sentinel value. If you make further changes I would suggest you
do this too, otherwise something to keep in your mind for later.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Fix deserialization for new fields in PdxSerializable class
> -----------------------------------------------------------
>
> Key: GEODE-9968
> URL: https://issues.apache.org/jira/browse/GEODE-9968
> 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* an implementation of a PdxSerializable class
> *WHEN* a set of entries have been written for this class
> *AND* after a while, the implementation changes, adding new fields
> *AND* a new set of entries are written containing some of the added fields
> *AND* all of the region entries are read
> *THEN* added fields of the latest entries are empty or contain garbage instead
> ----
> *Additional information.* After analyzing Java implementation for
> PdxSerializable deserialization, it seems that the client fetches the
> PdxFields from the remote PdxType, but instead for the C++ implementation,
> code is different as it uses a mapping called "Local2Remote" (which I suppose
> it's an optimization). And the current use of this "Local2Remote" mapping is
> not working correctly under the described scenario.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)