Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

MongoDB replication doesn't work using Java driver

$
0
0

I have a three instance replica set and i am using the following code to insert values in my mongodb database constantly.

 MongoClient client = new MongoClient(Arrays.asList(
            new ServerAddress("AKhurramL2", 27017),
            new ServerAddress("AKhurramL2", 27018),
            new ServerAddress("AKhurramL2", 27019)));

    MongoDatabase database = client.getDatabase("test");
    MongoCollection<Document> collection =    database.getCollection("recharge");
    collection.drop();
    try{
    for(int i=0;i<100000;i++){
      Document doc = new Document("reference",""+i);
      collection.insertOne(doc);
      Helper.printJson(doc);
      try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {e.printStackTrace();}

If i now shutdown my primary i get the following exception and my java program exits whereas it should continue inserting the values after the election, whereas the replica set has got a new primary which i can see using the mongo shell.

May 06, 2016 2:25:23 PM com.mongodb.diagnostics.logging.JULLogger log
WARNING: Got socket exception on connection [connectionId{localValue:5, serverValue:99}] to akhurraml2:27020. All connections to akhurraml2:27020 will be closed.
May 06, 2016 2:25:23 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Closed connection [connectionId{localValue:5, serverValue:99}] to akhurraml2:27020 because there was a socket exception raised by this connection.
Exception in thread "main" com.mongodb.MongoSocketReadException: Exception receiving message
    at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:480)
    at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:225)
    at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:102)
    at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:435)
    at com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:234)
    at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
    at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67)
    at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37)
    at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
    at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286)
    at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:115)
    at com.mongodb.operation.MixedBulkWriteOperation$Run$2.executeWriteCommandProtocol(MixedBulkWriteOperation.java:455)
    at com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:646)
    at com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:401)
    at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:179)
    at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:168)
    at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:230)
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
    at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:168)
    at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:74)
    at com.mongodb.Mongo.execute(Mongo.java:781)
    at com.mongodb.Mongo$2.execute(Mongo.java:764)
    at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
    at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:306)
    at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:297)
    at com.nextcontrols.App.main(App.java:35)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:170)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
    at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:491)
    at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:221)
    ... 24 more

Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>