|
22 | 22 | **/ |
23 | 23 | public class MongoDBStack extends CoreStack { |
24 | 24 |
|
| 25 | + /// Internal self used logger |
| 26 | + private static Logger LOGGER = Logger.getLogger(MongoDBStack.class.getName()); |
| 27 | + |
25 | 28 | /** |
26 | 29 | * The internal MongoClient connection |
27 | 30 | */ |
@@ -54,11 +57,28 @@ public static String getFullConnectionURL(GenericConvertMap<String, Object> conf |
54 | 57 | String pass = config.getString("pass", null); |
55 | 58 | String host = config.getString("host", "localhost"); |
56 | 59 | 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" |
61 | 63 |
|
| 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 | + |
62 | 82 | // In the future we may want to support opt_map |
63 | 83 | // GenericConvertMap<String,Object> optMap = config.getGenericConvertStringMap("opt_map", "{}"); |
64 | 84 |
|
|
0 commit comments