1
0
Fork 0

do not use dynamic_pointer_cast in release

This commit is contained in:
Andrey Abramov 2018-03-27 21:26:21 +03:00
parent 65ea2bfbb9
commit e2a6e751ed
3 changed files with 60 additions and 22 deletions

View File

@ -366,6 +366,7 @@ class IResearchView final: public arangodb::DBServerLogicalView,
std::function<void(arangodb::TransactionState& state)> _trxWriteCallback; // for insert(...)/remove(...)
std::atomic<bool> _inRecovery;
// FIXME came from "LogicalView", check whether it needs to be there
mutable basics::ReadWriteLock _infoLock; // lock protecting the properties
};

View File

@ -99,8 +99,8 @@ class LogicalView : public LogicalDataSource {
LogicalView(TRI_vocbase_t* vocbase, velocypack::Slice const& definition);
private:
// FIXME seems to be ugly
friend struct ::TRI_vocbase_t;
mutable basics::ReadWriteLock _lock;
}; // LogicalView

View File

@ -895,12 +895,20 @@ std::vector<std::string> TRI_vocbase_t::collectionNames() {
result.reserve(_dataSourceByName.size());
for (auto& entry: _dataSourceByName) {
auto collection =
std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(entry.second);
if (entry.second->category() != LogicalCollection::category()) {
continue;
}
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto view = std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(view);
#else
auto view = std::static_pointer_cast<arangodb::LogicalCollection>(entry.second);
#endif
if (collection) {
result.emplace_back(entry.first);
}
}
return result;
@ -1337,10 +1345,12 @@ int TRI_vocbase_t::renameView(
auto itr1 = _dataSourceByName.find(oldName);
if (itr1 == _dataSourceByName.end()
|| !std::dynamic_pointer_cast<arangodb::LogicalView>(itr1->second)) {
|| arangodb::LogicalView::category() == itr1->second->category()) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(std::dynamic_pointer_cast<arangodb::LogicalView>(itr1->second));
_dataSourceByName.emplace(newName, view);
_dataSourceByName.erase(oldName);
@ -1446,10 +1456,12 @@ int TRI_vocbase_t::renameCollection(
auto itr1 = _dataSourceByName.find(oldName);
if (itr1 == _dataSourceByName.end()
|| !std::dynamic_pointer_cast<arangodb::LogicalCollection>(itr1->second)) {
|| arangodb::LogicalCollection::category() != itr1->second->category()) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
TRI_ASSERT(std::dynamic_pointer_cast<arangodb::LogicalCollection>(itr1->second));
auto* databaseFeature =
application_features::ApplicationServer::getFeature<DatabaseFeature>("Database");
TRI_ASSERT(databaseFeature);
@ -1519,9 +1531,10 @@ arangodb::LogicalCollection* TRI_vocbase_t::useCollection(
auto it = _dataSourceByName.find(name);
if (it != _dataSourceByName.end()) {
collection =
std::dynamic_pointer_cast<arangodb::LogicalCollection>(it->second).get();
if (it != _dataSourceByName.end()
&& it->second->category() == LogicalCollection::category()) {
TRI_ASSERT(std::dynamic_pointer_cast<LogicalCollection>(it->second));
collection = static_cast<LogicalCollection*>(it->second.get());
}
}
@ -1934,12 +1947,20 @@ std::vector<std::shared_ptr<arangodb::LogicalView>> TRI_vocbase_t::views() {
views.reserve(_dataSourceById.size());
for (auto& entry: _dataSourceById) {
auto view =
std::dynamic_pointer_cast<arangodb::LogicalView>(entry.second);
TRI_ASSERT(entry.second);
if (view) {
views.emplace_back(view);
if (entry.second->category() != LogicalView::category()) {
continue;
}
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto view = std::dynamic_pointer_cast<arangodb::LogicalView>(entry.second);
TRI_ASSERT(view);
#else
auto view = std::static_pointer_cast<arangodb::LogicalView>(entry.second);
#endif
views.emplace_back(view);
}
}
@ -1956,12 +1977,20 @@ void TRI_vocbase_t::processCollections(
}
} else {
for (auto& entry: _dataSourceById) {
auto collection =
std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(entry.second);
if (collection) {
cb(collection.get());
if (entry.second->category() != LogicalCollection::category()) {
continue;
}
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto collection = std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(collection);
#else
auto collection = std::static_pointer_cast<arangodb::LogicalCollection>(entry.second);
#endif
cb(collection.get());
}
}
}
@ -1984,12 +2013,20 @@ std::vector<arangodb::LogicalCollection*> TRI_vocbase_t::collections(
collections.reserve(_dataSourceById.size());
for (auto& entry: _dataSourceById) {
auto collection =
std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(entry.second);
if (collection) {
collections.emplace_back(collection.get());
if (entry.second->category() != LogicalCollection::category()) {
continue;
}
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
auto collection = std::dynamic_pointer_cast<arangodb::LogicalCollection>(entry.second);
TRI_ASSERT(collection);
#else
auto collection = std::static_pointer_cast<arangodb::LogicalCollection>(entry.second);
#endif
collections.emplace_back(collection.get());
}
}
}