Skip to content

Commit

Permalink
Avoid some copy constructions. (#7)
Browse files Browse the repository at this point in the history
starrysky9959 committed Oct 7, 2023
1 parent 96d9521 commit b2ba69d
Showing 7 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/mongo/db/concurrency/monograph_locker_noop.h
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ class MonographLockerNoop : public Locker {

bool hasMaxLockTimeout() override {
// MONGO_UNREACHABLE;
return false;
}

void unsetMaxLockTimeout() override {
@@ -168,7 +169,7 @@ class MonographLockerNoop : public Locker {
}

bool isLockHeldForMode(ResourceId resId, LockMode mode) const override {
return true;
return isModeCovered(mode, getLockMode(resId));
}

bool isDbLockedForMode(StringData dbName, LockMode mode) const override {
4 changes: 4 additions & 0 deletions src/mongo/db/namespace_string.h
Original file line number Diff line number Diff line change
@@ -194,6 +194,10 @@ class NamespaceString {
const std::string& toString() const {
return ns();
}

const StringData toStringData() const {
return StringData(_ns);
}

size_t size() const {
return _ns.size();
4 changes: 2 additions & 2 deletions src/mongo/db/storage/bson_collection_catalog_entry.cpp
Original file line number Diff line number Diff line change
@@ -337,10 +337,10 @@ void BSONCollectionCatalogEntry::MetaData::parse(const BSONObj& obj) {
auto bgSecondary = BSONElement(idx["backgroundSecondary"]);
// Opt-in to rebuilding behavior for old-format index catalog objects.
imd.isBackgroundSecondaryBuild = bgSecondary.eoo() || bgSecondary.trueValue();
indexes.push_back(imd);
indexes.push_back(std::move(imd));
}
}

prefix = KVPrefix::fromBSONElement(obj["prefix"]);
}
}
} // namespace mongo
3 changes: 2 additions & 1 deletion src/mongo/db/storage/kv/kv_catalog.h
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
#include <map>
#include <memory>
#include <string>
#include <utility>

#include "mongo/base/string_data.h"
#include "mongo/db/catalog/collection_options.h"
@@ -144,7 +145,7 @@ class KVCatalog {

struct Entry {
Entry() {}
Entry(std::string i, RecordId l) : ident(i), storedLoc(l) {}
Entry(std::string i, RecordId l) : ident(std::move(i)), storedLoc(std::move(l)) {}
std::string ident;
RecordId storedLoc;
};
5 changes: 3 additions & 2 deletions src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp
Original file line number Diff line number Diff line change
@@ -292,6 +292,7 @@ void KVCollectionCatalogEntry::updateCappedSize(OperationContext* opCtx, long lo

BSONCollectionCatalogEntry::MetaData KVCollectionCatalogEntry::_getMetaData(
OperationContext* opCtx) const {
return _catalog->getMetaData(opCtx, ns().toString());
}
// return _catalog->getMetaData(opCtx, ns().toString());
return _catalog->getMetaData(opCtx, ns().toStringData());
}
} // namespace mongo
13 changes: 8 additions & 5 deletions src/mongo/transport/service_executor_coroutine.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "mongo/base/string_data.h"
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kExecutor;

#include "mongo/transport/service_executor_coroutine.h"
#include "mongo/db/server_parameters.h"
#include "mongo/transport/service_entry_point_utils.h"
#include "mongo/transport/service_executor_coroutine.h"
#include "mongo/transport/service_executor_task_names.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
@@ -65,7 +66,7 @@ void ThreadGroup::TrySleep() {
_is_sleep.store(false, std::memory_order_relaxed);
return;
}

_sleep_cv.wait(lk, [this] { return !IsIdle(); });

// Woken up from sleep.
@@ -106,10 +107,11 @@ Status ServiceExecutorCoroutine::start() {
Status ServiceExecutorCoroutine::_startWorker(uint16_t groupId) {
MONGO_LOG(0) << "Starting new worker thread for " << _name << " service executor. "
<< " group id: " << groupId;

return launchServiceWorkerThread([this, threadGroupId = groupId] {
std::string threadName("thread_group_");
threadName += std::to_string(threadGroupId);
setThreadName(threadName);
std::string threadName("thread_group_" + std::to_string(threadGroupId));
StringData threadNameSD(threadName);

stdx::unique_lock<stdx::mutex> lk(_mutex);
_numRunningWorkerThreads.addAndFetch(1);
auto numRunningGuard = MakeGuard([&] {
@@ -160,6 +162,7 @@ Status ServiceExecutorCoroutine::_startWorker(uint16_t groupId) {
while (!_localWorkQueue.empty() && _stillRunning.load(std::memory_order_relaxed)) {
// _localRecursionDepth = 1;
// MONGO_LOG(1) << "thread " << threadGroupId << " do task";
setThreadName(threadNameSD);
_localWorkQueue.front()();
// MONGO_LOG(1) << "thread " << threadGroupId << " do task done";
_localWorkQueue.pop_front();
16 changes: 8 additions & 8 deletions src/mongo/transport/service_state_machine.cpp
Original file line number Diff line number Diff line change
@@ -118,11 +118,11 @@ class ServiceStateMachine::ThreadGuard {
#endif

// Set up the thread name
auto oldThreadName = getThreadName();
if (oldThreadName != _ssm->_threadName) {
_ssm->_oldThreadName = getThreadName().toString();
setThreadName(_ssm->_threadName);
}
// auto oldThreadName = getThreadName();
// if (oldThreadName != _ssm->_threadName) {
// _ssm->_oldThreadName = getThreadName().toString();
// setThreadName(_ssm->_threadName);
// }

// Swap the current Client so calls to cc() work as expected
Client::setCurrent(std::move(_ssm->_dbClient));
@@ -183,9 +183,9 @@ class ServiceStateMachine::ThreadGuard {
_ssm->_dbClient = Client::releaseCurrent();
}

if (!_ssm->_oldThreadName.empty()) {
setThreadName(_ssm->_oldThreadName);
}
// if (!_ssm->_oldThreadName.empty()) {
// setThreadName(_ssm->_oldThreadName);
// }
}

// If the session has ended, then it's unsafe to do anything but call the cleanup hook.

0 comments on commit b2ba69d

Please sign in to comment.