本文整理汇总了C++中AuthorizationSession::checkAuthForKillCursors方法的典型用法代码示例。如果您正苦于以下问题:C++ AuthorizationSession::checkAuthForKillCursors方法的具体用法?C++ AuthorizationSession::checkAuthForKillCursors怎么用?C++ AuthorizationSession::checkAuthForKillCursors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthorizationSession
的用法示例。
在下文中一共展示了AuthorizationSession::checkAuthForKillCursors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: killCursors
void Strategy::killCursors(OperationContext* txn, Request& request) {
if (!useClusterClientCursor) {
cursorCache.gotKillCursors(request.m());
return;
}
DbMessage& dbMessage = request.d();
const int numCursors = dbMessage.pullInt();
massert(28793,
str::stream() << "Invalid killCursors message. numCursors: " << numCursors
<< ", message size: " << dbMessage.msg().dataSize() << ".",
dbMessage.msg().dataSize() == 8 + (8 * numCursors));
uassert(28794,
str::stream() << "numCursors must be between 1 and 29999. numCursors: " << numCursors
<< ".",
numCursors >= 1 && numCursors < 30000);
ConstDataCursor cursors(dbMessage.getArray(numCursors));
Client* client = txn->getClient();
AuthorizationSession* authSession = AuthorizationSession::get(client);
ClusterCursorManager* manager = grid.getCursorManager();
for (int i = 0; i < numCursors; ++i) {
CursorId cursorId = cursors.readAndAdvance<LittleEndian<int64_t>>();
boost::optional<NamespaceString> nss = manager->getNamespaceForCursorId(cursorId);
if (!nss) {
LOG(3) << "Can't find cursor to kill. Cursor id: " << cursorId << ".";
continue;
}
Status authorizationStatus = authSession->checkAuthForKillCursors(*nss, cursorId);
audit::logKillCursorsAuthzCheck(client,
*nss,
cursorId,
authorizationStatus.isOK() ? ErrorCodes::OK
: ErrorCodes::Unauthorized);
if (!authorizationStatus.isOK()) {
LOG(3) << "Not authorized to kill cursor. Namespace: '" << *nss
<< "', cursor id: " << cursorId << ".";
continue;
}
Status killCursorStatus = manager->killCursor(*nss, cursorId);
if (!killCursorStatus.isOK()) {
LOG(3) << "Can't find cursor to kill. Namespace: '" << *nss
<< "', cursor id: " << cursorId << ".";
continue;
}
LOG(3) << "Killed cursor. Namespace: '" << *nss << "', cursor id: " << cursorId << ".";
}
}
示例2: gotKillCursors
void CursorCache::gotKillCursors(Message& m) {
LastError::get(cc()).disable();
DbMessage dbmessage(m);
int n = dbmessage.pullInt();
if (n > 2000) {
(n < 30000 ? warning() : error()) << "receivedKillCursors, n=" << n << endl;
}
uassert(13286, "sent 0 cursors to kill", n >= 1);
uassert(13287, "too many cursors to kill", n < 30000);
massert(18632,
str::stream() << "bad kill cursors size: " << m.dataSize(),
m.dataSize() == 8 + (8 * n));
ConstDataCursor cursors(dbmessage.getArray(n));
ClientBasic* client = ClientBasic::getCurrent();
AuthorizationSession* authSession = AuthorizationSession::get(client);
for (int i = 0; i < n; i++) {
long long id = cursors.readAndAdvance<LittleEndian<int64_t>>();
LOG(_myLogLevel) << "CursorCache::gotKillCursors id: " << id << endl;
if (!id) {
warning() << " got cursor id of 0 to kill" << endl;
continue;
}
string server;
{
stdx::lock_guard<stdx::mutex> lk(_mutex);
MapSharded::iterator i = _cursors.find(id);
if (i != _cursors.end()) {
Status authorizationStatus =
authSession->checkAuthForKillCursors(NamespaceString(i->second->getNS()), id);
audit::logKillCursorsAuthzCheck(
client,
NamespaceString(i->second->getNS()),
id,
authorizationStatus.isOK() ? ErrorCodes::OK : ErrorCodes::Unauthorized);
if (authorizationStatus.isOK()) {
_cursorsMaxTimeMS.erase(i->second->getId());
_cursors.erase(i);
}
continue;
}
MapNormal::iterator refsIt = _refs.find(id);
MapNormal::iterator refsNSIt = _refsNS.find(id);
if (refsIt == _refs.end()) {
warning() << "can't find cursor: " << id << endl;
continue;
}
verify(refsNSIt != _refsNS.end());
Status authorizationStatus =
authSession->checkAuthForKillCursors(NamespaceString(refsNSIt->second), id);
audit::logKillCursorsAuthzCheck(client,
NamespaceString(refsNSIt->second),
id,
authorizationStatus.isOK() ? ErrorCodes::OK
: ErrorCodes::Unauthorized);
if (!authorizationStatus.isOK()) {
continue;
}
server = refsIt->second;
_refs.erase(refsIt);
_refsNS.erase(refsNSIt);
cursorStatsSingleTarget.decrement();
}
LOG(_myLogLevel) << "CursorCache::found gotKillCursors id: " << id << " server: " << server
<< endl;
verify(server.size());
ScopedDbConnection conn(server);
conn->killCursor(id);
conn.done();
}
}