E5F3 fix pitfall for comdat folding (#15467) · strogo/arangodb@09f39f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09f39f0

Browse files
jsteemanngnusi
andauthored
fix pitfall for comdat folding (arangodb#15467)
Co-authored-by: Andrey Abramov <andrey@arangodb.com>
1 parent ee13389 commit 09f39f0

14 files changed

+191
-170
lines changed

arangod/Aql/Ast.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ auto doNothingVisitor = [](AstNode const*) {};
8787
* @return The Category of this datasource (Collection or View), and a reference
8888
* to the translated name (cid => name if required).
8989
*/
90-
LogicalDataSource::Category const* injectDataSourceInQuery(
90+
LogicalDataSource::Category injectDataSourceInQuery(
9191
Ast& ast, arangodb::CollectionNameResolver const& resolver,
9292
AccessMode::Type accessType, bool failIfDoesNotExist,
9393
std::string_view& nameRef) {
@@ -110,7 +110,7 @@ LogicalDataSource::Category const* injectDataSourceInQuery(
110110
ast.query().collections().add(name, accessType,
111111
aql::Collection::Hint::None);
112112

113-
return LogicalCollection::category();
113+
return LogicalDataSource::Category::kCollection;
114114
}
115115

116116
// query actual name from datasource... this may be different to the
@@ -126,7 +126,7 @@ LogicalDataSource::Category const* injectDataSourceInQuery(
126126
nameRef = std::string_view(p, dataSourceName.size());
127127
}
128128

129-
if (dataSource->category() == LogicalCollection::category()) {
129+
if (dataSource->category() == LogicalDataSource::Category::kCollection) {
130130
// it's a collection!
131131
// add datasource to query
132132
aql::Collection::Hint hint = aql::Collection::Hint::Collection;
@@ -138,7 +138,7 @@ LogicalDataSource::Category const* injectDataSourceInQuery(
138138
ast.query().collections().add(name, accessType,
139139
hint); // Add collection by ID as well
140140
}
141-
} else if (dataSource->category() == LogicalView::category()) {
141+
} else if (dataSource->category() == LogicalDataSource::Category::kView) {
142142
// it's a view!
143143
// add views to the collection list
144144
// to register them with transaction as well
@@ -778,13 +778,13 @@ AstNode* Ast::createNodeDataSource(
778778
// will throw if validation fails
779779
validateDataSourceName(name, validateName);
780780
// this call may update name
781-
LogicalCollection::Category const* category = injectDataSourceInQuery(
781+
LogicalCollection::Category category = injectDataSourceInQuery(
782782
*this, resolver, accessType, failIfDoesNotExist, name);
783783

784-
if (category == LogicalCollection::category()) {
784+
if (category == LogicalDataSource::Category::kCollection) {
785785
return createNodeCollectionNoValidation(name, accessType);
786786
}
787-
if (category == LogicalView::category()) {
787+
if (category == LogicalDataSource::Category::kView) {
788788
AstNode* node = createNode(NODE_TYPE_VIEW);
789789
node->setStringValue(name.data(), name.size());
790790
return node;
@@ -803,10 +803,10 @@ AstNode* Ast::createNodeCollection(
803803
// will throw if validation fails
804804
validateDataSourceName(name, true);
805805
// this call may update name
806-
LogicalCollection::Category const* category =
806+
LogicalCollection::Category category =
807807
injectDataSourceInQuery(*this, resolver, accessType, false, name);
808808

809-
if (category == LogicalCollection::category()) {
809+
if (category == LogicalDataSource::Category::kCollection) {
810810
// add collection to query
811811
_query.collections().add(std::string(name), accessType,
812812
Collection::Hint::Collection);
@@ -1391,9 +1391,9 @@ AstNode* Ast::createNodeWithCollections(
13911391
std::string const name = c->getString();
13921392
std::string_view nameRef(name);
13931393
// this call may update nameRef, but it doesn't matter
1394-
LogicalDataSource::Category const* category = injectDataSourceInQuery(
1394+
LogicalDataSource::Category category = injectDataSourceInQuery(
13951395
*this, resolver, AccessMode::Type::READ, false, nameRef);
1396-
if (category == LogicalCollection::category()) {
1396+
if (category == LogicalDataSource::Category::kCollection) {
13971397
_query.collections().add(name, AccessMode::Type::READ,
13981398
Collection::Hint::Collection);
13991399

@@ -1411,11 +1411,12 @@ AstNode* Ast::createNodeWithCollections(
14111411

14121412
for (auto const& n : names) {
14131413
std::string_view shardsNameRef(n);
1414-
LogicalDataSource::Category const* shardsCategory =
1414+
LogicalDataSource::Category shardsCategory =
14151415
injectDataSourceInQuery(*this, resolver,
14161416
AccessMode::Type::READ, false,
14171417
shardsNameRef);
1418-
TRI_ASSERT(shardsCategory == LogicalCollection::category());
1418+
TRI_ASSERT(shardsCategory ==
1419+
LogicalDataSource::Category::kCollection);
14191420
}
14201421
}
14211422
}
@@ -1443,9 +1444,9 @@ AstNode* Ast::createNodeCollectionList(AstNode const* edgeCollections,
14431444
auto ss = ServerState::instance();
14441445
auto doTheAdd = [&](std::string const& name) {
14451446
std::string_view nameRef(name);
1446-
LogicalDataSource::Category const* category = injectDataSourceInQuery(
1447+
LogicalDataSource::Category category = injectDataSourceInQuery(
14471448
*this, resolver, AccessMode::Type::READ, false, nameRef);
1448-
if (category == LogicalCollection::category()) {
1449+
if (category == LogicalDataSource::Category::kCollection) {
14491450
if (ss->isCoordinator()) {
14501451
auto& ci = _query.vocbase()
14511452
.server()
@@ -1457,10 +1458,11 @@ AstNode* Ast::createNodeCollectionList(AstNode const* edgeCollect 10000 ions,
14571458

14581459
for (auto const& n : names) {
14591460
std::string_view shardsNameRef(n);
1460-
LogicalDataSource::Category const* shardsCategory =
1461+
LogicalDataSource::Category shardsCategory =
14611462
injectDataSourceInQuery(*this, resolver, AccessMode::Type::READ,
14621463
false, shardsNameRef);
1463-
TRI_ASSERT(shardsCategory == LogicalCollection::category());
1464+
TRI_ASSERT(shardsCategory ==
1465+
LogicalDataSource::Category::kCollection);
14641466
}
14651467
} // else { TODO Should we really not react? }
14661468
}

arangod/Aql/IResearchViewNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ IResearchViewNode::IResearchViewNode(
10011001
_scorers(std::move(scorers)) {
10021002
TRI_ASSERT(_view);
10031003
TRI_ASSERT(iresearch::DATA_SOURCE_TYPE == _view->type());
1004-
TRI_ASSERT(LogicalView::category() == _view->category());
1004+
TRI_ASSERT(LogicalDataSource::Category::kView == _view->category());
10051005

10061006
auto* ast = plan.getAst();
10071007

arangod/RestServer/DatabaseFeature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ ErrorCode DatabaseFeature::dropDatabase(std::string const& name,
833833
[&res, &vocbase](arangodb::LogicalDataSource& dataSource) -> bool {
834834
// skip LogicalCollection since their internal state is always in the
835835
// StorageEngine (optimization)
836-
if (arangodb::LogicalCollection::category() == dataSource.category()) {
836+
if (arangodb::LogicalDataSource::Category::kCollection ==
837+
dataSource.category()) {
837838
return true;
838839
}
839840

arangod/Utils/CollectionNameResolver.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollection(
5757
#else
5858
auto dataSource = getDataSource(id);
5959

60-
return dataSource && dataSource->category() == LogicalCollection::category()
60+
return dataSource && dataSource->category() ==
61+
LogicalDataSource::Category::kCollection
6162
? std::static_pointer_cast<LogicalCollection>(dataSource)
6263
: nullptr;
6364
#endif
@@ -70,7 +71,8 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollection(
7071
#else
7172
auto dataSource = getDataSource(nameOrId);
7273

73-
return dataSource && dataSource->category() == LogicalCollection::category()
74+
return dataSource && dataSource->category() ==
75+
LogicalDataSource::Category::kCollection
7476
? std::static_pointer_cast<LogicalCollection>(dataSource)
7577
: nullptr;
7678
#endif
@@ -337,7 +339,8 @@ std::shared_ptr<LogicalView> CollectionNameResolver::getView(
337339
#else
338340
auto dataSource = getDataSource(id);
339341

340-
return dataSource && dataSource->category() == LogicalView::category()
342+
return dataSource &&
343+
dataSource->category() == LogicalDataSource::Category::kView
341344
? std::static_pointer_cast<LogicalView>(dataSource)
342345
: nullptr;
343346
#endif
@@ -350,7 +353,8 @@ std::shared_ptr<LogicalView> CollectionNameResolver::getView(
350353
#else
351354
auto dataSource = getDataSource(nameOrId);
352355

353-
return dataSource && dataSource->category() == LogicalView::category()
356+
return dataSource &&
357+
dataSource->category() == LogicalDataSource::Category::kView
354358
? std::static_pointer_cast<LogicalView>(dataSource)
355359
: nullptr;
356360
#endif
@@ -365,7 +369,7 @@ bool CollectionNameResolver::visitCollections(
365369
return false; // no way to determine what to visit
366370
}
367371

368-
if (LogicalCollection::category() == dataSource->category()) {
372+
if (LogicalDataSource::Category::kCollection == dataSource->category()) {
369373
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
370374
auto collection = std::dynamic_pointer_cast<LogicalCollection>(dataSource);
371375
TRI_ASSERT(collection);
@@ -377,7 +381,7 @@ bool CollectionNameResolver::visitCollections(
377381
return visitor(*collection);
378382
}
379383

380-
if (LogicalView::category() == dataSource->category()) {
384+
if (LogicalDataSource::Category::kView == dataSource->category()) {
381385
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
382386
auto view = std::dynamic_pointer_cast<LogicalView>(dataSource);
383387
#else

arangod/VocBase/LogicalCollection.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ arangodb::LogicalDataSource::Type const& readType(
143143
LogicalCollection::LogicalCollection(TRI_vocbase_t& vocbase, VPackSlice info,
144144
bool isAStub)
145145
: LogicalDataSource(
146-
LogicalCollection::category(),
146+
*this,
147147
::readType(info, StaticStrings::DataSourceType, TRI_COL_TYPE_UNKNOWN),
148148
vocbase, DataSourceId{Helper::extractIdValue(info)},
149149
::readGloballyUniqueId(info),
@@ -299,13 +299,6 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t& vocbase, VPackSlice info,
299299
decorateWithInternalValidators();
300300
}
301301

302-
/*static*/ LogicalDataSource::Category const&
303-
LogicalCollection::category() noexcept {
304-
static const Category category;
305-
306-
return category;
307-
}
308-
309302
Result LogicalCollection::updateSchema(VPackSlice schema) {
310303
using namespace std::literals::string_literals;
311304
if (schema.isNone()) {

arangod/VocBase/LogicalCollection.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class LogicalCollection : public LogicalDataSource {
8585

8686
enum class Version { v30 = 5, v31 = 6, v33 = 7, v34 = 8, v37 = 9 };
8787

88+
constexpr static Category category() noexcept {
89+
return Category::kCollection;
90+
}
91+
8892
/*
8993
* @brief Available types of internal validators. These validators
9094
* are managed by the database, and bound to features of collections.
@@ -104,9 +108,6 @@ class LogicalCollection : public LogicalDataSource {
104108
SatToSmartEdge = 16,
105109
};
106110

107-
/// @brief the category representing a logical collection
108-
static Category const& category() noexcept;
109-
110111
/// @brief hard-coded minimum version number for collections
111112
static constexpr Version minimumVersion() { return Version::v30; }
112113
/// @brief current version for collections

arangod/VocBase/LogicalDataSource.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@
3636
#include "RestServer/ServerIdFeature.h"
3737
#include "Utilities/NameValidator.h"
3838
#include "VocBase/LogicalCollection.h"
39+
#include "VocBase/LogicalView.h"
3940
#include "VocBase/ticks.h"
4041

4142
#include "Logger/Logger.h"
4243

4344
namespace {
4445

45-
std::string ensureGuid(std::string&& guid, arangodb::DataSourceId id,
46-
arangodb::DataSourceId planId, std::string const& name,
47-
bool isSystem) {
46+
[[maybe_unused]] std::string ensureGuid(std::string&& guid,
47+
arangodb::DataSourceId id,
48+
arangodb::DataSourceId planId,
49+
std::string const& name,
50+
bool isSystem) {
4851
if (!guid.empty()) {
4952
return std::move(guid);
5053
}
@@ -84,8 +87,8 @@ std::string ensureGuid(std::string&& guid, arangodb::DataSourceId id,
8487
return std::move(guid);
8588
}
8689

87-
arangodb::DataSourceId ensureId(TRI_vocbase_t& vocbase,
88-
arangodb::DataSourceId id) {
90+
[[maybe_unused]] arangodb::DataSourceId ensureId(TRI_vocbase_t& vocbase,
91+
arangodb::DataSourceId id) {
8992
if (id) {
9093
return id;
9194
}
@@ -114,7 +117,7 @@ arangodb::DataSourceId ensureId(TRI_vocbase_t& vocbase,
114117
return id;
115118
}
116119

117-
bool readIsSystem(arangodb::velocypack::Slice definition) {
120+
[[maybe_unused]] bool readIsSystem(arangodb::velocypack::Slice definition) {
118121
if (!definition.isObject()) {
119122
return false;
120123
}
@@ -144,6 +147,11 @@ arangodb::velocypack::ValuePair toValuePair(std::string const& value) {
144147

145148
namespace arangodb {
146149

150+
static_assert(LogicalDataSource::Category::kCollection ==
151+
LogicalCollection::category());
152+
static_assert(LogicalDataSource::Category::kView ==
153+
arangodb::LogicalView::category());
154+
147155
/*static*/ LogicalDataSource::Type const& LogicalDataSource::Type::emplace(
148156
std::string_view name) {
149157
static std::mutex mutex;
@@ -160,9 +168,9 @@ namespace arangodb {
160168
return itr.first->second;
161169
}
162170

163-
LogicalDataSource::LogicalDataSource(Category const& category, Type const& type,
171+
LogicalDataSource::LogicalDataSource(Category category, Type const& type,
164172
TRI_vocbase_t& vocbase,
165-
velocypack::Slice const& definition)
173+
velocypack::Slice definition)
166174
: LogicalDataSource(
167175
category, type, vocbase,
168176
DataSourceId{basics::VelocyPackHelper::extractIdValue(definition)},
@@ -176,24 +184,28 @@ LogicalDataSource::LogicalDataSource(Category const& category, Type const& type,
176184
basics::VelocyPackHelper::getBooleanValue(
177185
definition, StaticStrings::DataSourceDeleted, false)) {}
178186

179-
LogicalDataSource::LogicalDataSource(Category const& category, Type const& type,
187+
LogicalDataSource::LogicalDataSource(Category category, Type const& type,
180188
TRI_vocbase_t& vocbase, DataSourceId id,
181189
std::string&& guid, DataSourceId planId,
182190
std::string&& name, bool system,
183191
bool deleted)
184192
: _name(std::move(name)),
185-
_category(category),
186193
_type(type),
187194
_vocbase(vocbase),
188195
_id(ensureId(vocbase, id)),
189196
_planId(planId ? planId : _id),
190197
_guid(ensureGuid(std::move(guid), _id, _planId, _name, system)),
191198
_deleted(deleted),
199+
_category(category),
192200
_system(system) {
193201
TRI_ASSERT(_id);
194202
TRI_ASSERT(!_guid.empty());
195203
}
196204

205+
LogicalDataSource::Category LogicalDataSource::category() const noexcept {
206+
return _category;
207+
}
208+
197209
Result LogicalDataSource::properties(velocypack::Builder& builder,
198210
Serialization context) const {
199211
if (!builder.isOpenObject()) {

0 commit comments

Comments
 (0)
0