Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring mongodb write-concern values

Tags:

spring

mongodb

I have the following core mongo options configuration in spring:

<mongo:mongo host="${db.hostname}" >
  <mongo:options
    connections-per-host="40"
    threads-allowed-to-block-for-connection-multiplier="1500"
    connect-timeout="15000"
    auto-connect-retry="true"
    socket-timeout="60000"
    write-number="1"
    write-fsync="false"/>
</mongo:mongo>

What I want to know is about different write-number options which is relevant to write concern like none, normal, safe etc.

Can I assume the mapping of write-number to writeconcern as below?

NONE: -1
NORMAL: 0
SAFE: 1 (default)
FSYNC_SAFE: 2
REPLICAS_SAFE: 3
JOURNAL_SAFE: 4
MAJORITY: 5  

Following link has provided a good help to set mongo options in spring, but not specific enough for write-number values: How to configure MongoDB Java driver MongoOptions for production use?

like image 278
inkriti Avatar asked Oct 08 '22 12:10

inkriti


1 Answers

The write-concern number is the value of "w" which maps to the number of replicas that the write must propagate to before being considered successful when w > 1.

FSYNC_SAFE maps to setting write-fsync (true or false) and since JOURNAL_SAFE is also a boolean value, I suspect there is a similar boolean setting in Spring but I couldn't find it in any of their docs.

If you have everything installed to test this out empirically, just try several configurations and check the actual setting of the resultant write concern with something like:

       WriteConcern wc = new WriteConcern(); // should get your default write concern
       System.out.println(wc.getJ());
       System.out.println(wc.getFsync());
       System.out.println(wc.getW());

That should show you Journal setting, Fsync setting (both boolean), W (as an int).

like image 82
Asya Kamsky Avatar answered Oct 12 '22 23:10

Asya Kamsky