Hello,

I am working on a PoC in which we are using MongoDB as our datastore.
The solution will be implemented in Java and we are using Spring
MongoDB to interact with MongoDB.Currently we are using Spring MongoDB
1.0.0.M5 version which internally use mongodb java driver version
2.6.5. Last two days I have been trying to setup replication but
facing some weird issues. Let me share with you how I am setting
replication and what all issues I am facing.

Setting up Replication

I am setting up 3 machine replica set where 1 machine acts as primary,
2nd acts as secondary and 3rd as Arbiter. The primary and secondary
machines are 64 bit Ubuntu 11.04 with 4 GB RAM. The arbiter machine is
32 bit with 4 GB RAM and Ubuntu 10.10 version. MongoDB version I am
using is 2.0.1. Running MongoDB in replication mode was very easy and
I didn't faced any issue doing it.

Writing Data using Spring MongoDB 1.0.0.M5

I am using Spring MongoTemplate to write objects to MongoDB. Please
find at the bottom the sample Spring application context file.

Data Loss

While the data is being written to MongoDB I kill the primary node so
that secondary node becomes primary.After few seconds I bring back the
old primary up and now the primary becomes secondary because the old
secondary had become primary. After all the inserts are done when I
check the count of messages I find some messages are missing. Sometime
missing message count is 50 sometimes 100. Its also written in MongoDB
documentation that the data which was not replicated to secondary will
be written in Rollback folder. When I run the bsondump utility over
the rollback bson file I get some messages but still there are lot of
messages missing.

It would be great if someone could help in setting up a durable
replication.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:cloud="http://schema.cloudfoundry.org/spring"
xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mongo="http://www.springframework.org/schema/data/mongo"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://
www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
                http://schema.cloudfoundry.org/spring
http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd
                http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <mongo:db-factory dbname="${mongo.database}" id="mongoDbFactory"
                mongo-ref="mongo" />

        <mongo:mongo replica-
set="192.168.2.24:40002,192.168.2.25:40000,192.168.2.26:40001"
                host="${mongo.host}" id="mongo" port="${mongo.port}" >
                <mongo:options connections-per-host="8"
                   threads-allowed-to-block-for-connection-
multiplier="4"
                   connect-timeout="1000"
                   max-wait-time="1500"
                   auto-connect-retry="true"
                   socket-keep-alive="true"
                   socket-timeout="1500"
                   write-number="-1"
                   write-timeout="5000"
                   />

        </mongo:mongo>

        <mongo:repositories base-package="com.hi.cdi" />

        <context:annotation-config />

        <bean class="org.springframework.data.mongodb.core.MongoTemplate"
                id="mongoTemplate">
                <constructor-arg ref="mongoDbFactory" />
        </bean>

</beans>