Vous avez raison de dire que run_command
ne supporte pas de faire un currentOp
directement. Cependant, si nous regardons la mise en œuvre de db.currentOp
dans la coquille mongo
, nous pouvons voir comment il fonctionne sous le capot:
> db.currentOp
function (arg) {
var q = {};
if (arg) {
if (typeof arg == "object") {
Object.extend(q, arg);
} else if (arg) {
q.$all = true;
}
}
return this.$cmd.sys.inprog.findOne(q);
}
On peut donc interroger la collection spéciale $cmd.sys.inprog
sur le côté Perl pour obtenir le même tableau inprog
cela serait retourné dans la coquille.
use strict;
use warnings;
use MongoDB;
my $db = MongoDB::MongoClient->new->get_database('test');
my $current_op = $db->get_collection('$cmd.sys.inprog')->find_one;
Lorsque le serveur est pas verrouillé, il retournera une structure $current_op
qui ressemble à ceci:
{
'inprog' => [
{
'connectionId' => 53,
'insert' => {},
'active' => bless(do{\(my $o = 0)}, 'boolean'),
'lockStats' => {
'timeAcquiringMicros' => {
'w' => 1,
'r' => 0
},
'timeLockedMicros' => {
'w' => 9,
'r' => 0
}
},
'numYields' => 0,
'locks' => {
'^' => 'w',
'^test' => 'W'
},
'waitingForLock' => $VAR1->{'inprog'}[0]{'active'},
'ns' => 'test.fnoof',
'client' => '127.0.0.1:50186',
'threadId' => '0x105a81000',
'desc' => 'conn53',
'opid' => 7152352,
'op' => 'insert'
}
]
};
Au cours d'une fsyncLock()
, vous obtiendrez un tableau inprog
vide mais vous aura un champ utile info
et le fsyncLock
booléen attendu:
{
'info' => 'use db.fsyncUnlock() to terminate the fsync write/snapshot lock',
'fsyncLock' => bless(do{\(my $o = 1)}, 'boolean'), # <--- that's true
'inprog' => []
};
Donc, mettre tous ensemble, nous obtenons:
use strict;
use warnings;
use MongoDB;
my $db = MongoDB::MongoClient->new->get_database('fnarf');
my $current_op = $db->get_collection('$cmd.sys.inprog')->find_one;
if ($current_op->{fsyncLock}) {
print "fsync lock is currently ON\n";
} else {
print "fsync lock is currently OFF\n";
}
Eh bien, c'est une réponse étonnamment précis qui fonctionne comme un charme. Merci beaucoup! –