You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by dr...@apache.org on 2020/03/25 21:07:13 UTC

[gora] branch GORA-649-replace-deprecated-mongo-api updated (c2807e6 -> 1516198)

This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a change to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git.


    from c2807e6  GORA-649 Use new MongoDatabase and MongoCollection API
     new 92c6578  GORA-649 Use com.mongodb.client.MongoClient interface
     new 1516198  GORA-649 MongoStore#flush is now no-op

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/gora/mongodb/store/MongoStore.java  | 42 ++++++++--------------
 1 file changed, 15 insertions(+), 27 deletions(-)


[gora] 01/02: GORA-649 Use com.mongodb.client.MongoClient interface

Posted by dr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 92c6578259f6612ac7de2a2ae9fdaaa79cb35d26
Author: Damien Raude-Morvan <dr...@drazzib.com>
AuthorDate: Wed Mar 25 22:01:30 2020 +0100

    GORA-649 Use com.mongodb.client.MongoClient interface
    
    This interface, while similar to the existing com.mongodb.MongoClient class
    in that it is a factory for com.mongodb.client.MongoDatabase instances,
    does not support the legacy com.mongodb.DBCollection-based API :
    http://mongodb.github.io/mongo-java-driver/3.12/whats-new/#new-entry-point
---
 .../org/apache/gora/mongodb/store/MongoStore.java  | 32 ++++++++++------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
index 26680a5..05ca503 100644
--- a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
@@ -19,10 +19,7 @@ package org.apache.gora.mongodb.store;
 
 import com.google.common.base.Splitter;
 import com.mongodb.*;
-import com.mongodb.client.FindIterable;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-import com.mongodb.client.MongoIterable;
+import com.mongodb.client.*;
 import com.mongodb.client.model.CountOptions;
 import com.mongodb.client.model.CreateCollectionOptions;
 import com.mongodb.client.model.UpdateOptions;
@@ -93,7 +90,7 @@ DataStoreBase<K, T> {
   /**
    * MongoDB client
    */
-  private static ConcurrentHashMap<String, MongoClient> mapsOfClients = new ConcurrentHashMap<>();
+  private static ConcurrentHashMap<String, com.mongodb.client.MongoClient> mapsOfClients = new ConcurrentHashMap<>();
 
   private MongoDatabase mongoClientDB;
 
@@ -151,27 +148,25 @@ DataStoreBase<K, T> {
    *
    * @param params This value should specify the host:port (at least one) for
    *               connecting to remote MongoDB.
-   * @return a {@link Mongo} instance connected to the server
-   * @throws UnknownHostException
+   * @return a {@link com.mongodb.client.MongoClient} instance connected to the server
    */
-  private MongoClient getClient(MongoStoreParameters params)
-      throws UnknownHostException {
+  private com.mongodb.client.MongoClient getClient(MongoStoreParameters params) {
 
     // Utf8 serialization!
     CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
-            MongoClient.getDefaultCodecRegistry(),
+            MongoClientSettings.getDefaultCodecRegistry(),
             CodecRegistries.fromCodecs(new Utf8Codec())
     );
     // Configure options
-    MongoClientOptions.Builder optBuilder = new MongoClientOptions.Builder();
-    optBuilder.codecRegistry(codecRegistry);
+    MongoClientSettings.Builder settings = MongoClientSettings.builder();
+    settings.codecRegistry(codecRegistry);
     if (params.getReadPreference() != null) {
-      optBuilder.readPreference(ReadPreference.valueOf(params.getReadPreference()));
+      settings.readPreference(ReadPreference.valueOf(params.getReadPreference()));
     }
     if (params.getWriteConcern() != null) {
-      optBuilder.writeConcern(WriteConcern.valueOf(params.getWriteConcern()));
+      settings.writeConcern(WriteConcern.valueOf(params.getWriteConcern()));
     }
-    MongoClientOptions options = optBuilder.build();
+
 
     // Build server address
     List<ServerAddress> seeds = new ArrayList<>();
@@ -191,14 +186,15 @@ DataStoreBase<K, T> {
         }
       }
     }
+    settings.applyToClusterSettings(builder -> builder.hosts(seeds));
 
     // If configuration contains a login + secret, try to authenticated with DB
     if (params.getLogin() != null && params.getSecret() != null) {
       MongoCredential credential = createCredential(params.getAuthenticationType(), params.getLogin(), params.getDbname(), params.getSecret());
-      return new MongoClient(seeds, credential, options);
-    } else {
-      return new MongoClient(seeds, options);
+      settings.credential(credential);
     }
+
+    return MongoClients.create(settings.build());
   }
 
   /**


[gora] 02/02: GORA-649 MongoStore#flush is now no-op

Posted by dr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 1516198635fd7eb3856b5bce8346c121a4bb9cfe
Author: Damien Raude-Morvan <dr...@drazzib.com>
AuthorDate: Wed Mar 25 22:07:04 2020 +0100

    GORA-649 MongoStore#flush is now no-op
    
    Remove fsync handling since its deprecated upstream and should be replaced by proper WriteConcern
---
 .../main/java/org/apache/gora/mongodb/store/MongoStore.java    | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
index 05ca503..295a675 100644
--- a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
@@ -321,15 +321,7 @@ DataStoreBase<K, T> {
    */
   @Override
   public void flush() throws GoraException {
-    try {
-      for (MongoClient client : mapsOfClients.values()) {
-        client.fsync(false);
-        LOG.debug("Forced synced of database for Mongo instance {}.",
-            new Object[] { client });
-      }
-    } catch (Exception e) {
-      throw new GoraException(e);
-    }
+    // no-op
   }
 
   /**