Skip to content

Commit 0357610

Browse files
authored
Removed TopicDataType unnecessary code (#180)
* [#24333] Removed TopicDataType unnecessary code and factorized deterministic instance-handle generation for mcap and sql Signed-off-by: danipiza <dpizarrogallego@gmail.com> * [#24333] Removed 'TopicDataType.hpp' unnecessary code Signed-off-by: danipiza <dpizarrogallego@gmail.com> * [#24333] Applied revision Signed-off-by: danipiza <dpizarrogallego@gmail.com> --------- Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent 29eb074 commit 0357610

2 files changed

Lines changed: 11 additions & 148 deletions

File tree

ddspipe_participants/include/ddspipe_participants/types/dds/TopicDataType.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
#pragma once
1616

1717
#include <memory>
18-
#include <mutex>
1918
#include <string>
2019

2120
#include <fastdds/dds/core/policy/QosPolicies.hpp>
2221
#include <fastdds/dds/core/ReturnCode.hpp>
2322
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
2423
#include <fastdds/dds/topic/TopicDataType.hpp>
25-
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>
2624
#include <fastdds/dds/xtypes/type_representation/detail/dds_xtypes_typeobject.hpp>
2725
#include <fastdds/rtps/common/InstanceHandle.hpp>
2826
#include <fastdds/rtps/common/SerializedPayload.hpp>
@@ -105,16 +103,6 @@ class TopicDataType : public fastdds::dds::TopicDataType
105103

106104
std::shared_ptr<core::PayloadPool> payload_pool_;
107105

108-
//! Lazily created dynamic type used to compute key from serialized payload.
109-
mutable fastdds::dds::DynamicType::_ref_type dynamic_type_{};
110-
mutable std::mutex dynamic_type_mtx_;
111-
//! Set to true if dynamic type initialization permanently failed due to structural errors.
112-
//! Missing dependencies are treated as transient and retried.
113-
mutable bool dynamic_type_init_failed_{false};
114-
115-
DDSPIPE_PARTICIPANTS_DllAPI
116-
bool initialize_dynamic_type_() const;
117-
118106
};
119107

120108
} /* namespace dds */

ddspipe_participants/src/cpp/types/dds/TopicDataType.cpp

Lines changed: 11 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
#include <fastcdr/FastBuffer.h>
2020
#include <fastcdr/Cdr.h>
21-
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
22-
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
23-
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
2421

2522
#include <ddspipe_participants/types/dds/TopicDataType.hpp>
2623

@@ -49,16 +46,6 @@ TopicDataType::TopicDataType(
4946

5047
// Set Type Identifiers
5148
type_identifiers_ = type_identifiers;
52-
53-
// Eagerly try to build the dynamic type for keyed topics
54-
// This may fail transiently if dependency TypeObjects have not been received yet
55-
// Keep key capability enabled and retry later on demand
56-
if (keyed_ && !initialize_dynamic_type_())
57-
{
58-
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
59-
"Cannot build dynamic type for keyed topic "
60-
<< type_name_ << " yet. Will retry when needed.");
61-
}
6249
}
6350

6451
TopicDataType::~TopicDataType()
@@ -118,142 +105,30 @@ uint32_t TopicDataType::calculate_serialized_size(
118105
bool TopicDataType::compute_key(
119106
fastdds::rtps::SerializedPayload_t& payload,
120107
fastdds::rtps::InstanceHandle_t& handle,
121-
bool force_md5)
108+
bool /* = false */)
122109
{
123-
if (!is_compute_key_provided)
124-
{
125-
return false;
126-
}
127-
128-
if (!initialize_dynamic_type_())
129-
{
130-
// Dynamic type is not available yet (or permanently failed due to structural errors)
131-
// Keep capability enabled so future calls can retry when dependencies arrive
132-
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
133-
"Cannot compute key for type "
134-
<< type_name_ << ": dynamic type unavailable.");
135-
return false;
136-
}
137-
138-
fastdds::dds::DynamicPubSubType pub_sub_type(dynamic_type_);
139-
return pub_sub_type.compute_key(payload, handle, force_md5);
110+
// NOTE: This method returns false because Fast DDS always sends the KEY_HASH in inline QoS.
111+
// As a result, the reader will never call this method when communicating with a Fast DDS writer.
112+
// This would only be needed if receiving data from another DDS vendor that omits the KEY_HASH.
113+
// Workaround in that case (different DDS vendor that omits KEY_HASH): set expects_inline_qos_ to
114+
// true in DataReaderQos
115+
return false;
140116
}
141117

142118
bool TopicDataType::compute_key(
143119
const void* const data,
144120
fastdds::rtps::InstanceHandle_t& handle,
145-
bool force_md5)
121+
bool /* = false */)
146122
{
147123
if (is_compute_key_provided)
148124
{
125+
// Load the instanceHandle from data into handle
149126
const auto p = static_cast<const DataType*>(data);
150-
151-
// Fast path: key already available in routing data.
152-
if (p->instanceHandle.isDefined())
153-
{
154-
handle = p->instanceHandle;
155-
return true;
156-
}
157-
158-
// Fallback path: compute key from serialized payload when handle is not present.
159-
if (p->payload.data != nullptr && p->payload.length > 0)
160-
{
161-
fastdds::rtps::SerializedPayload_t payload(p->payload.length);
162-
if (!payload.copy(&p->payload))
163-
{
164-
return false;
165-
}
166-
167-
return compute_key(payload, handle, force_md5);
168-
}
169-
170-
return false;
171-
}
172-
173-
return false;
174-
}
175-
176-
bool TopicDataType::initialize_dynamic_type_() const
177-
{
178-
std::lock_guard<std::mutex> lock(dynamic_type_mtx_);
179-
180-
// Another thread may have initialized or permanently failed initialization
181-
// before this thread acquired the mutex
182-
if (dynamic_type_)
183-
{
127+
handle = p->instanceHandle;
184128
return true;
185129
}
186130

187-
if (dynamic_type_init_failed_)
188-
{
189-
return false;
190-
}
191-
192-
fastdds::dds::xtypes::TypeInformation type_information;
193-
194-
auto& registry = fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry();
195-
196-
auto try_get_type_information = [&](const fastdds::dds::xtypes::TypeIdentifierPair& identifiers) -> bool
197-
{
198-
return fastdds::dds::RETCODE_OK == registry.get_type_information(identifiers, type_information);
199-
};
200-
201-
if (!try_get_type_information(type_identifiers_))
202-
{
203-
fastdds::dds::xtypes::TypeIdentifierPair complete_only;
204-
complete_only.type_identifier1(type_identifiers_.type_identifier1());
205-
206-
if (!try_get_type_information(complete_only))
207-
{
208-
fastdds::dds::xtypes::TypeIdentifierPair minimal_only;
209-
minimal_only.type_identifier2(type_identifiers_.type_identifier2());
210-
211-
if (!try_get_type_information(minimal_only))
212-
{
213-
// Missing type information may be transient while dependency types are still arriving
214-
return false;
215-
}
216-
}
217-
}
218-
219-
const auto complete_type_identifier = type_information.complete().typeid_with_size().type_id();
220-
fastdds::dds::xtypes::TypeObject type_object;
221-
if (fastdds::dds::RETCODE_OK != registry.get_type_object(complete_type_identifier, type_object))
222-
{
223-
// Missing type object may be transient while dependency types are still arriving
224-
return false;
225-
}
226-
227-
// Pre-check consistency before calling create_type_w_type_object
228-
// If dependencies are missing from the registry, skip type creation entirely
229-
// to avoid noisy error logs from internal FastDDS type creation functions
230-
try
231-
{
232-
fastdds::dds::xtypes::TypeObjectUtils::type_object_consistency(type_object);
233-
}
234-
catch (const fastdds::dds::xtypes::InvalidArgumentError&)
235-
{
236-
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
237-
"TypeObject for "
238-
<< type_name_ << " has unresolvable dependencies. "
239-
<< "Skipping dynamic type creation for now.");
240-
return false;
241-
}
242-
243-
auto dyn_type_builder = fastdds::dds::DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object(
244-
type_object);
245-
if (!dyn_type_builder)
246-
{
247-
dynamic_type_init_failed_ = true;
248-
return false;
249-
}
250-
251-
dynamic_type_ = dyn_type_builder->build();
252-
if (!dynamic_type_)
253-
{
254-
dynamic_type_init_failed_ = true;
255-
}
256-
return dynamic_type_ != nullptr;
131+
return false;
257132
}
258133

259134
void* TopicDataType::create_data()

0 commit comments

Comments
 (0)