@@ -31,7 +31,8 @@ namespace {
31
31
void mergeInto (
32
32
type::Schema& dst,
33
33
type::Schema&& src,
34
- std::unordered_set<type::ProgramId>& includedPrograms) {
34
+ std::unordered_set<type::ProgramId>& includedPrograms,
35
+ bool allowDuplicateDefinitionKeys) {
35
36
for (auto & program : *src.programs ()) {
36
37
auto id = *program.id ();
37
38
if (!includedPrograms.insert (id).second ) {
@@ -51,7 +52,8 @@ void mergeInto(
51
52
dst.definitionsMap ()->insert (
52
53
std::make_move_iterator (src.definitionsMap ()->begin ()),
53
54
std::make_move_iterator (src.definitionsMap ()->end ()));
54
- if (dst.definitionsMap ()->size () != ndefs + src.definitionsMap ()->size ()) {
55
+ if (!allowDuplicateDefinitionKeys &&
56
+ dst.definitionsMap ()->size () != ndefs + src.definitionsMap ()->size ()) {
55
57
throw std::runtime_error (" DefinitionKey collision" );
56
58
}
57
59
}
@@ -85,7 +87,11 @@ SchemaRegistry::Ptr SchemaRegistry::getMergedSchema() {
85
87
mergedSchema_ = std::make_shared<type::Schema>();
86
88
for (auto & [name, data] : base_.rawSchemas_ ) {
87
89
if (auto schema = readSchema (data.data )) {
88
- mergeInto (*mergedSchema_, std::move (*schema), includedPrograms_);
90
+ mergeInto (
91
+ *mergedSchema_,
92
+ std::move (*schema),
93
+ includedPrograms_,
94
+ /* allowDuplicateDefinitionKeys*/ false );
89
95
}
90
96
}
91
97
@@ -98,7 +104,11 @@ SchemaRegistry::Ptr SchemaRegistry::getMergedSchema() {
98
104
}
99
105
100
106
if (auto schema = readSchema (data)) {
101
- mergeInto (*mergedSchema_, std::move (*schema), includedPrograms_);
107
+ mergeInto (
108
+ *mergedSchema_,
109
+ std::move (*schema),
110
+ includedPrograms_,
111
+ /* allowDuplicateDefinitionKeys*/ false );
102
112
}
103
113
};
104
114
@@ -113,7 +123,11 @@ type::Schema SchemaRegistry::mergeSchemas(
113
123
114
124
for (const auto & data : schemas) {
115
125
if (auto schema = readSchema (data)) {
116
- mergeInto (mergedSchema, std::move (*schema), includedPrograms);
126
+ mergeInto (
127
+ mergedSchema,
128
+ std::move (*schema),
129
+ includedPrograms,
130
+ /* allowDuplicateDefinitionKeys*/ false );
117
131
}
118
132
}
119
133
@@ -125,7 +139,18 @@ type::Schema SchemaRegistry::mergeSchemas(std::vector<type::Schema>&& schemas) {
125
139
std::unordered_set<type::ProgramId> includedPrograms;
126
140
127
141
for (auto & schema : schemas) {
128
- mergeInto (mergedSchema, std::move (schema), includedPrograms);
142
+ /*
143
+ * allowDuplicateDefinitionKeys is true here because this is called by
144
+ * MultiplexAsyncProcessor, which may hold services with a shared base
145
+ * service.
146
+ * Additionally, since this function accepts deserialized schemas
147
+ * those schemas were probably already checked for duplicates earlier.
148
+ */
149
+ mergeInto (
150
+ mergedSchema,
151
+ std::move (schema),
152
+ includedPrograms,
153
+ /* allowDuplicateDefinitionKeys*/ true );
129
154
}
130
155
131
156
return mergedSchema;
0 commit comments