jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1547390 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java
Date Tue, 03 Dec 2013 13:48:36 GMT
Author: thomasm
Date: Tue Dec  3 13:48:36 2013
New Revision: 1547390

URL: http://svn.apache.org/r1547390
Log:
OAK-760 MongoBlobStore: read from a secondary member when possible

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java?rev=1547390&r1=1547389&r2=1547390&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/blob/MongoBlobStore.java
Tue Dec  3 13:48:36 2013
@@ -29,6 +29,7 @@ import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
 import com.mongodb.MongoException;
 import com.mongodb.QueryBuilder;
+import com.mongodb.ReadPreference;
 import com.mongodb.WriteResult;
 
 /**
@@ -160,7 +161,19 @@ public class MongoBlobStore extends Abst
 
     private MongoBlob getBlob(String id, long lastMod) {
         DBObject query = getBlobQuery(id, lastMod);
-        return (MongoBlob) getBlobCollection().findOne(query);
+        
+        // try the secondary first
+        // TODO add a configuration option for whether to try reading from secondary
+        ReadPreference pref = ReadPreference.secondaryPreferred();
+        DBObject fields = new BasicDBObject();
+        fields.put(MongoBlob.KEY_DATA, 1);
+        MongoBlob blob = (MongoBlob) getBlobCollection().findOne(query, fields, pref);
+        if (blob == null) {
+            // not found in the secondary: try the primary
+            pref = ReadPreference.primary();
+            blob = (MongoBlob) getBlobCollection().findOne(query, fields, pref);
+        }
+        return blob;
     }
 
     private static DBObject getBlobQuery(String id, long lastMod) {



Mime
View raw message