Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Revert "SERVER-14995 Move operation id, lockState and client fields t…
Browse files Browse the repository at this point in the history
…o OperationContext."

This reverts commit 4ea38c3.
  • Loading branch information
stbrody committed May 29, 2015
1 parent c6a542c commit e181ea3
Show file tree
Hide file tree
Showing 46 changed files with 255 additions and 222 deletions.
1 change: 0 additions & 1 deletion src/mongo/db/SConscript
Expand Up @@ -387,7 +387,6 @@ env.Library(
source=[
'client.cpp',
'client_basic.cpp',
'operation_context.cpp',
'service_context.cpp',
'service_context_noop.cpp',
],
Expand Down
3 changes: 1 addition & 2 deletions src/mongo/db/catalog/index_create.cpp
Expand Up @@ -42,7 +42,6 @@
#include "mongo/db/audit.h"
#include "mongo/db/background.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
Expand Down Expand Up @@ -229,7 +228,7 @@ namespace mongo {
invariant(_indexes.size() == 1);
invariant(_buildInBackground);
IndexDescriptor* descriptor = _indexes[0].block->getEntry()->descriptor();
_collection->getIndexCatalog()->registerIndexBuild(descriptor, _txn->getOpID());
_collection->getIndexCatalog()->registerIndexBuild(descriptor, CurOp::get(_txn)->opNum());
return descriptor;
}

Expand Down
8 changes: 3 additions & 5 deletions src/mongo/db/clientcursor.cpp
Expand Up @@ -293,11 +293,9 @@ namespace mongo {
Timer t;
const int Secs = 4;
while (!inShutdown()) {
{
OperationContextImpl txn;
cursorStatsTimedOut.increment(
CursorManager::timeoutCursorsGlobal(&txn, t.millisReset()));
}
OperationContextImpl txn;
cursorStatsTimedOut.increment(
CursorManager::timeoutCursorsGlobal(&txn, t.millisReset()));
sleepsecs(Secs);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/mongo/db/clientlistplugin.cpp
Expand Up @@ -101,8 +101,8 @@ namespace {

ss << "<tr><td>" << client->desc() << "</td>";

tablecell(ss, txn->getOpID());
tablecell(ss, true);
tablecell(ss, curOp->opNum());
tablecell(ss, curOp->active());

// LockState
{
Expand All @@ -115,7 +115,12 @@ namespace {
tablecell(ss, lockerInfoBuilder.obj());
}

tablecell(ss, curOp->elapsedSeconds());
if (curOp->active()) {
tablecell(ss, curOp->elapsedSeconds());
}
else {
tablecell(ss, "");
}

tablecell(ss, curOp->getOp());
tablecell(ss, html::escape(curOp->getNS()));
Expand Down Expand Up @@ -205,9 +210,7 @@ namespace {
client->reportState(b);

const OperationContext* txn = client->getOperationContext();
b.appendBool("active", static_cast<bool>(txn));
if (txn) {
b.append("opid", txn->getOpID());

// CurOp
if (CurOp::get(txn)) {
Expand Down
9 changes: 7 additions & 2 deletions src/mongo/db/commands/current_op.cpp
Expand Up @@ -113,6 +113,9 @@ namespace mongo {
// Skip over inactive connections.
if (!opCtx)
continue;
auto curOp = CurOp::get(opCtx);
if (!curOp || !curOp->active())
continue;
}

BSONObjBuilder infoBuilder;
Expand All @@ -121,9 +124,7 @@ namespace mongo {
client->reportState(infoBuilder);

// Operation context specific information
infoBuilder.appendBool("active", static_cast<bool>(opCtx));
if (opCtx) {
infoBuilder.append("opid", opCtx->getOpID());
// CurOp
if (CurOp::get(opCtx)) {
CurOp::get(opCtx)->reportState(&infoBuilder);
Expand All @@ -134,6 +135,10 @@ namespace mongo {
opCtx->lockState()->getLockerInfo(&lockerInfo);
fillLockerInfo(lockerInfo, infoBuilder);
}
else {
// If no operation context, mark the operation as inactive
infoBuilder.append("active", false);
}

infoBuilder.done();

Expand Down
6 changes: 2 additions & 4 deletions src/mongo/db/commands/getmore_cmd.cpp
Expand Up @@ -37,18 +37,16 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/cursor_manager.h"
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/cursor_responses.h"
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/global_timestamp.h"
#include "mongo/db/query/find.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/service_context.h"
#include "mongo/db/query/find.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/stats/counters.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
Expand Down
9 changes: 3 additions & 6 deletions src/mongo/db/commands/write_commands/batch_executor.cpp
Expand Up @@ -896,8 +896,7 @@ namespace mongo {
WriteErrorDetail** error ) {

// BEGIN CURRENT OP
CurOp currentOp(_txn);
currentOp.setOp(dbUpdate);
CurOp currentOp(_txn->getClient(), dbUpdate);
beginCurrentOp( &currentOp, _txn->getClient(), updateItem );
incOpStats( updateItem );

Expand Down Expand Up @@ -941,8 +940,7 @@ namespace mongo {
// Removes are similar to updates, but page faults are handled externally

// BEGIN CURRENT OP
CurOp currentOp(_txn);
currentOp.setOp(dbDelete);
CurOp currentOp(_txn->getClient(), dbDelete);
beginCurrentOp( &currentOp, _txn->getClient(), removeItem );
incOpStats( removeItem );

Expand Down Expand Up @@ -1137,8 +1135,7 @@ namespace mongo {

void WriteBatchExecutor::execOneInsert(ExecInsertsState* state, WriteErrorDetail** error) {
BatchItemRef currInsertItem(state->request, state->currIndex);
CurOp currentOp(_txn);
currentOp.setOp(dbInsert);
CurOp currentOp(_txn->getClient(), dbInsert);
beginCurrentOp( &currentOp, _txn->getClient(), currInsertItem );
incOpStats(currInsertItem);

Expand Down
77 changes: 53 additions & 24 deletions src/mongo/db/curop.cpp
Expand Up @@ -56,10 +56,10 @@ namespace mongo {
*
* The stack itself is represented in the _parent pointers of the CurOp class.
*/
class CurOp::CurOpStack {
MONGO_DISALLOW_COPYING(CurOpStack);
class CurOp::ClientCuropStack {
MONGO_DISALLOW_COPYING(ClientCuropStack);
public:
CurOpStack() : _base(nullptr, this) {}
ClientCuropStack() : _base(nullptr, this) {}

/**
* Returns the top of the CurOp stack.
Expand All @@ -69,15 +69,15 @@ namespace mongo {
/**
* Adds "curOp" to the top of the CurOp stack for a client. Called by CurOp's constructor.
*/
void push(OperationContext* opCtx, CurOp* curOp) {
invariant(opCtx);
if (_opCtx) {
invariant(_opCtx == opCtx);
void push(Client* client, CurOp* curOp) {
invariant(client);
if (_client) {
invariant(_client == client);
}
else {
_opCtx = opCtx;
_client = client;
}
boost::lock_guard<Client> lk(*_opCtx->getClient());
boost::lock_guard<Client> lk(*_client);
push_nolock(curOp);
}

Expand All @@ -101,20 +101,20 @@ namespace mongo {
// the client during the final pop.
const bool shouldLock = _top->_parent;
if (shouldLock) {
invariant(_opCtx);
_opCtx->getClient()->lock();
invariant(_client);
_client->lock();
}
invariant(_top);
CurOp* retval = _top;
_top = _top->_parent;
if (shouldLock) {
_opCtx->getClient()->unlock();
_client->unlock();
}
return retval;
}

private:
OperationContext* _opCtx = nullptr;
Client* _client = nullptr;

// Top of the stack of CurOps for a Client.
CurOp* _top = nullptr;
Expand All @@ -123,8 +123,8 @@ namespace mongo {
const CurOp _base;
};

const OperationContext::Decoration<CurOp::CurOpStack> CurOp::_curopStack =
OperationContext::declareDecoration<CurOp::CurOpStack>();
const Client::Decoration<CurOp::ClientCuropStack> CurOp::_curopStack =
Client::declareDecoration<CurOp::ClientCuropStack>();

// Enabling the maxTimeAlwaysTimeOut fail point will cause any query or command run with a
// valid non-zero max time to fail immediately. Any getmore operation on a cursor already
Expand All @@ -146,18 +146,33 @@ namespace mongo {

CurOp* CurOp::get(const OperationContext* opCtx) { return get(*opCtx); }

CurOp* CurOp::get(const OperationContext& opCtx) { return _curopStack(opCtx).top(); }
CurOp* CurOp::get(const OperationContext& opCtx) {
return _curopStack(opCtx.getClient()).top();
}

CurOp::CurOp(OperationContext* opCtx) : CurOp(opCtx, &_curopStack(opCtx)) {}
CurOp::CurOp(Client* client) : CurOp(client, &_curopStack(client)) {}

CurOp::CurOp(OperationContext* opCtx, CurOpStack* stack) : _stack(stack) {
if (opCtx) {
_stack->push(opCtx, this);
CurOp::CurOp(Client* client, ClientCuropStack* stack) : _stack(stack) {
if (client) {
_stack->push(client, this);
}
else {
_stack->push_nolock(this);
}
_start = 0;
_active = false;
_reset();
_op = 0;
_opNum = _nextOpNum.fetchAndAdd(1);
_command = NULL;
}

CurOp::CurOp(Client* client, int op) : CurOp(client, &_curopStack(client)) {
_op = op;
_active = true;
}

void CurOp::_reset() {
_isCommand = false;
_dbprofile = 0;
_end = 0;
Expand All @@ -168,11 +183,20 @@ namespace mongo {
_killPending.store(0);
_numYields = 0;
_expectedLatencyMs = 0;
_op = 0;
_command = NULL;
}

void CurOp::setOp(int op) {
void CurOp::reset() {
_reset();
_start = 0;
_opNum = _nextOpNum.fetchAndAdd(1);
_ns = "";
_debug.reset();
_query.reset();
_active = true; // this should be last for ui clarity
}

void CurOp::reset(int op) {
reset();
_op = op;
}

Expand Down Expand Up @@ -230,8 +254,11 @@ namespace mongo {
}

void CurOp::reportState(BSONObjBuilder* builder) {
builder->append("opid", _opNum);
bool a = _active && _start;
builder->append("active", a);

if (_start) {
if( a ) {
builder->append("secs_running", elapsedSeconds() );
builder->append("microsecs_running", static_cast<long long int>(elapsedMicros()) );
}
Expand Down Expand Up @@ -385,6 +412,8 @@ namespace mongo {
}


AtomicUInt32 CurOp::_nextOpNum;

static Counter64 returnedCounter;
static Counter64 insertedCounter;
static Counter64 updatedCounter;
Expand Down

0 comments on commit e181ea3

Please sign in to comment.