Skip to content

Commit 74307b6

Browse files
committed
JAVA-613: Added numDocuments property to InUseConnectionInfo to provide more info for batch inserts
1 parent 481fe05 commit 74307b6

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ private synchronized Response go(OutMessage msg, DBCollection coll, boolean forc
110110
throw new IllegalStateException( "_out shouldn't be null" );
111111

112112
try {
113-
_activeState = new ActiveState(msg);
114113
msg.prepare();
114+
_activeState = new ActiveState(msg);
115115
msg.pipe( _out );
116116

117117
if ( _pool != null )

src/main/com/mongodb/InUseConnectionInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ public class InUseConnectionInfo {
2828
opCode = null;
2929
query = null;
3030
threadName = null;
31+
numDocuments = 0;
3132
}
3233
else {
3334
durationMS = (System.nanoTime() - activeState.startTime) / 1000000;
3435
namespace = activeState.outMessage.getNamespace();
3536
opCode = activeState.outMessage.getOpCode();
3637
query = activeState.outMessage.getQuery() != null ? activeState.outMessage.getQuery().toString() : null;
3738
threadName = activeState.threadName;
39+
numDocuments = activeState.outMessage.getNumDocuments();
3840
}
3941
localPort = port.getLocalPort();
4042
}
@@ -63,10 +65,15 @@ public String getThreadName() {
6365
return threadName;
6466
}
6567

68+
public int getNumDocuments() {
69+
return numDocuments;
70+
}
71+
6672
private final String namespace;
6773
private final OutMessage.OpCode opCode;
6874
private final String query;
6975
private final int localPort;
7076
private final long durationMS;
7177
private final String threadName;
78+
private final int numDocuments;
7279
}

src/main/com/mongodb/OutMessage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,18 @@ String getNamespace() {
257257
return _collection != null ? _collection.getFullName() : null;
258258
}
259259

260+
synchronized int getNumDocuments() {
261+
return _numDocuments;
262+
}
263+
260264
@Override
261-
public int putObject(BSONObject o) {
265+
public synchronized int putObject(BSONObject o) {
262266
// check max size
263267
int objectSize = _encoder.writeObject(_buf, o);
264268
if (objectSize > Math.max(_mongo.getConnector().getMaxBsonObjectSize(), Bytes.MAX_OBJECT_SIZE)) {
265269
throw new MongoInternalException("DBObject of size " + objectSize + " is over Max BSON size " + _mongo.getMaxBsonObjectSize());
266270
}
271+
_numDocuments++;
267272
return objectSize;
268273
}
269274

@@ -275,4 +280,5 @@ public int putObject(BSONObject o) {
275280
private final int _queryOptions;
276281
private final DBObject _query;
277282
private final DBEncoder _encoder;
283+
private int _numDocuments;
278284
}

src/main/com/mongodb/tools/ConnectionPoolStat.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,20 @@ private static void printUsage() {
148148
System.out.println(" -n [ --rowcount ] arg number of times to print stats (0 for indefinite)");
149149
System.out.println();
150150
System.out.println("Fields");
151-
System.out.println(" objectName - name of the JMX bean for this connection pool");
152-
System.out.println(" host - host of the mongod/mongos server");
153-
System.out.println(" port - port of the mongod/mongos server");
154-
System.out.println(" size - max # of connections allowed");
155-
System.out.println(" total - # of connections allocated");
156-
System.out.println(" inUse - # of connections in use");
157-
System.out.println(" inUseConnections - list of all in use connections");
158-
System.out.println(" inUseConnections.namespace - namespace on which connection is operating");
159-
System.out.println(" inUseConnections.opCode - operation connection is executing");
160-
System.out.println(" inUseConnections.query - query the connection is executing (for query/update/remove)");
161-
System.out.println(" inUseConnections.threadName - name of thread on which connection is executing");
162-
System.out.println(" inUseConnections.durationMS - duration that the operation has been executing so far");
163-
System.out.println(" inUseConnections.localPort - local port of the connection");
151+
System.out.println(" objectName - name of the JMX bean for this connection pool");
152+
System.out.println(" host - host of the mongod/mongos server");
153+
System.out.println(" port - port of the mongod/mongos server");
154+
System.out.println(" size - max # of connections allowed");
155+
System.out.println(" total - # of connections allocated");
156+
System.out.println(" inUse - # of connections in use");
157+
System.out.println(" inUseConnections - list of all in use connections");
158+
System.out.println(" inUseConnections.namespace - namespace on which connection is operating");
159+
System.out.println(" inUseConnections.opCode - operation connection is executing");
160+
System.out.println(" inUseConnections.query - query the connection is executing (for query/update/remove)");
161+
System.out.println(" inUseConnections.numDocuments - # of documents in the message (mostly relevant for batch inserts)");
162+
System.out.println(" inUseConnections.threadName - name of thread on which connection is executing");
163+
System.out.println(" inUseConnections.durationMS - duration that the operation has been executing so far");
164+
System.out.println(" inUseConnections.localPort - local port of the connection");
164165
}
165166

166167
private void print(PrintWriter pw) throws JMException, IOException {
@@ -197,6 +198,7 @@ private void printInUseConnections(final ObjectName objectName, final PrintWrite
197198
printCompositeDataAttribute("namespace", compositeData, pw);
198199
printCompositeDataAttribute("opCode", compositeData, pw);
199200
printCompositeDataAttribute("query", compositeData, pw, StringType.JSON);
201+
printCompositeDataAttribute("numDocuments", compositeData, pw);
200202
printCompositeDataAttribute("threadName", compositeData, pw);
201203
printCompositeDataAttribute("durationMS", compositeData, pw);
202204
printCompositeDataAttribute("localPort", compositeData, pw, Position.LAST);

0 commit comments

Comments
 (0)