Skip to content

Commit c82e0dc

Browse files
committed
Disable read concern by default (due to error for single nodes)
1 parent 885b2d8 commit c82e0dc

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDBStack.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
**/
2323
public class MongoDBStack extends CoreStack {
2424

25+
/// Internal self used logger
26+
private static Logger LOGGER = Logger.getLogger(MongoDBStack.class.getName());
27+
2528
/**
2629
* The internal MongoClient connection
2730
*/
@@ -54,11 +57,28 @@ public static String getFullConnectionURL(GenericConvertMap<String, Object> conf
5457
String pass = config.getString("pass", null);
5558
String host = config.getString("host", "localhost");
5659
int port = config.getInt("port", 27017);
57-
String opts = config.getString("opt_str",
58-
"w=majority&retryWrites=true&retryReads=true&"+
59-
"maxPoolSize=10&compressors=zstd&"+
60-
"readPreference=nearest&readConcernLevel=linearizable");
60+
String opts = config.getString("opt_str", "w=majority&retryWrites=true&retryReads=true"
61+
+ "&maxPoolSize=10&compressors=zstd");
62+
// "&readPreference=nearest&readConcernLevel=linearizable"
6163

64+
// Lets do a logging, for missing read concern if its not configured
65+
if( opts.indexOf("readConcernLevel") < 0 ) {
66+
//
67+
// readConcernLevel is a complicated topic, do consider reading up
68+
// https://jepsen.io/analyses/mongodb-4.2.6
69+
// https://www.mongodb.com/blog/post/performance-best-practices-transactions-and-read--write-concerns
70+
// https://www.mongodb.com/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-
71+
//
72+
// This option was removed by default, as an error will be thrown when its applied to single node clusters
73+
//
74+
// Unless you know what your doing from a performance standpoint, it is strongly recommended to use
75+
// `readConcernLevel=linearizable`
76+
//
77+
LOGGER.warning("MongoDB is configured without readConcernLevel, "+
78+
"this is alright for a single node, but `readConcernLevel=linearizable`"+
79+
"is highly recommended for replica clusters to ensure read after write consistency.");
80+
}
81+
6282
// In the future we may want to support opt_map
6383
// GenericConvertMap<String,Object> optMap = config.getGenericConvertStringMap("opt_map", "{}");
6484

0 commit comments

Comments
 (0)