MongoDB specific configuration: WriteConcern valid values
I want to set a specific write concern in my xml file for MongoDB. As described in https://github.com/impetus-opensource/Kundera/wiki/MongoDB-Specific-Features
I found the constant "write.concern" for this property. However now I'm wondering, what are the values I can set for this property?
<property name="write.concern" value="?"></property>
I was also wondering what the <name>mongo</name> tag means.
I assume it's the database name?
@vreniers Please find the below mentioned test case: https://github.com/impetus-opensource/Kundera/blob/273c13342ddd1aceed0cd23504649926ce8fdb84/src/kundera-mongo/src/test/java/com/impetus/client/mongodb/config/OperationLevelPropertiesTest.java#L83
For property "write.concern" you can set values ACKNOWLEDGED, UNACKNOWLEDGED, etc. Please have a look on this for more details http://api.mongodb.org/java/current/com/mongodb/WriteConcern.html
Since, the "write.concern" property is an EntityManager level property. Hence kundera doesn't support defining it in persistence.xml or clientProperties.xml.
In order to tell Kundera to read the properties mentioned as MongoDB client's properties you need to add <name>mongo<name> tag in xml file.
I don't think the property value is working for me. I made sure I checked the logging to check that my mongoDB specific config xml file is found.
This is what I have:
<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
<datastores>
<dataStore>
<name>mongo</name>
<connection>
<properties>
<property name="read.preference" value="primary"></property>
<property name="write.concern" value="ACKNOWLEDGED"></property>
</properties>
</connection>
</dataStore>
</datastores>
</clientProperties>
Now I've tested it by using ACKNOWLEDGED and UNACKNOWLEDGED like you said. But my benchmark results for inserting the records were the same for both values. Which does not make sense.
ACKNOWLEDGED value [OVERALL], RunTime(ms), 17665.0 [OVERALL], Throughput(ops/sec), 5660.911406736484
UNACKNOWLEDGED value [OVERALL], RunTime(ms), 17965.0 [OVERALL], Throughput(ops/sec), 5566.379070414695
Then I've commented the property line out and just set it operationally using:
em.setProperty(MongoDBClientProperties.WRITE_CONCERN, WriteConcern.UNACKNOWLEDGED);
or
em.setProperty(MongoDBClientProperties.WRITE_CONCERN, WriteConcern.ACKNOWLEDGED);
These are the results I got:
ACKNOWLEDGED [OVERALL], RunTime(ms), 33442.0 [OVERALL], Throughput(ops/sec), 2990.2517791998084
UNACKNOWLEDGED [OVERALL], RunTime(ms), 17368.0 [OVERALL], Throughput(ops/sec), 5757.715338553662
As expected, the acknowledged property takes a lot longer. I set the property each time I make a new EntityManager. But I prefer to have it as a property in the xml file, so I dont have to set it each time in my code and on multiple locations. Am I doing something wrong, or is this property not working?
@vreniers Please find my updated comment.
Since, you dont want to replicate the code of setting the property everytime you create an entitymanager instance, you can create an utility method which would serve your purpose. You can call the method each time you want to instantiate an entitymanager object.