jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1559951 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/mongomk/ main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/ main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/ test/java/org/apach...
Date Tue, 21 Jan 2014 09:23:21 GMT
Author: thomasm
Date: Tue Jan 21 09:23:21 2014
New Revision: 1559951

URL: http://svn.apache.org/r1559951
Log:
OAK-759 MongoMK: read from a secondary member when possible (allow changing the read preference
/ write concern at runtime)

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterInfoTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfo.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfoDocument.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/SynchronizingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/TimingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterJoinTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfo.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfo.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfo.java
Tue Jan 21 09:23:21 2014
@@ -65,6 +65,11 @@ public class ClusterNodeInfo {
     private static final String INFO_KEY = "info";
     
     /**
+     * The read/write mode key.
+     */
+    private static final String READ_WRITE_MODE_KEY = "readWriteMode";
+
+    /**
      * The unique machine id (the MAC address if available).
      */
     private static final String MACHINE_ID = getMachineId();
@@ -120,6 +125,11 @@ public class ClusterNodeInfo {
      */
     private long leaseEndTime;
     
+    /**
+     * The read/write mode.
+     */
+    private String readWriteMode;
+    
     ClusterNodeInfo(int id, DocumentStore store, String machineId, String instanceId) {
         this.id = id;
         this.startTime = System.currentTimeMillis();
@@ -234,7 +244,12 @@ public class ClusterNodeInfo {
         UpdateOp update = new UpdateOp("" + id, true);
         leaseEndTime = now + leaseTime;
         update.set(LEASE_END_KEY, leaseEndTime);
-        store.createOrUpdate(Collection.CLUSTER_NODES, update);
+        ClusterNodeInfoDocument doc = store.createOrUpdate(Collection.CLUSTER_NODES, update);
+        String mode = (String) doc.get(READ_WRITE_MODE_KEY);
+        if (mode != null && !mode.equals(readWriteMode)) {
+            readWriteMode = mode;
+            store.setReadWriteMode(mode);
+        }
     }
     
     public void setLeaseTime(long leaseTime) {
@@ -258,7 +273,8 @@ public class ClusterNodeInfo {
                 "machineId: " + machineId + ",\n" +
                 "instanceId: " + instanceId + ",\n" +
                 "pid: " + PROCESS_ID + ",\n" +
-                "uuid: " + uuid +"\n";
+                "uuid: " + uuid +",\n" +
+                "readWriteMode: " + readWriteMode;
     }
         
     private static long getProcessId() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfoDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfoDocument.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfoDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterNodeInfoDocument.java
Tue Jan 21 09:23:21 2014
@@ -20,7 +20,7 @@ package org.apache.jackrabbit.oak.plugin
  * A document storing cluster node info. See also {@link ClusterNodeInfo}.
  */
 public class ClusterNodeInfoDocument extends Document {
-    
+
     // marker interface
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentStore.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/DocumentStore.java
Tue Jan 21 09:23:21 2014
@@ -188,4 +188,12 @@ public interface DocumentStore {
      */
     @CheckForNull
     <T extends Document> T getIfCached(Collection<T> collection, String key);
+
+    /**
+     * Set the level of guarantee for read and write operations, if supported by this backend.
+     * 
+     * @param readWriteMode the read/write mode
+     */
+    void setReadWriteMode(String readWriteMode);
+    
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MemoryDocumentStore.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MemoryDocumentStore.java
Tue Jan 21 09:23:21 2014
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.locks.Lock;
@@ -30,6 +31,10 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 
+import com.google.common.base.Splitter;
+import com.mongodb.ReadPreference;
+import com.mongodb.WriteConcern;
+
 /**
  * Emulates a MongoDB store (possibly consisting of multiple shards and
  * replicas).
@@ -56,6 +61,12 @@ public class MemoryDocumentStore impleme
      */
     private final Comparator<Revision> comparator = StableRevisionComparator.REVERSE;
 
+    private ReadPreference readPreference;
+
+    private WriteConcern writeConcern;
+
+    private Object lastReadWriteMode;
+
     @Override
     public <T extends Document> T find(Collection<T> collection, String key,
int maxCacheAge) {
         return find(collection, key);
@@ -177,7 +188,7 @@ public class MemoryDocumentStore impleme
             } else {
                 oldDoc.deepCopy(doc);
             }
-            if (checkConditions && ! UpdateUtils.checkConditions(doc, update)) {
+            if (checkConditions && !UpdateUtils.checkConditions(doc, update)) {
                 return null;
             }
             // update the document
@@ -265,4 +276,39 @@ public class MemoryDocumentStore impleme
         // ignore
     }
 
+    @Override
+    public void setReadWriteMode(String readWriteMode) {
+        if (readWriteMode == null || readWriteMode.equals(lastReadWriteMode)) {
+            return;
+        }
+        lastReadWriteMode = readWriteMode;        
+        try {
+            Map<String, String> map = Splitter.on(", ").withKeyValueSeparator(":").split(readWriteMode);
+            String read = map.get("read");
+            if (read != null) {
+                ReadPreference readPref = ReadPreference.valueOf(read);
+                if (!readPref.equals(this.readPreference)) {
+                    this.readPreference = readPref;
+                }
+            } 
+            String write = map.get("write");
+            if (write != null) {
+                WriteConcern writeConcern = WriteConcern.valueOf(write);
+                if (!writeConcern.equals(this.writeConcern)) {
+                    this.writeConcern = writeConcern;
+                }
+            }
+        } catch (Exception e) {
+            // unsupported or parse error - ignore
+        }
+    }
+    
+    public ReadPreference getReadPreference() {
+        return readPreference;
+    }
+
+    public WriteConcern getWriteConcern() {
+        return writeConcern;
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoDocumentStore.java
Tue Jan 21 09:23:21 2014
@@ -33,12 +33,14 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.oak.plugins.mongomk.UpdateOp.Operation;
 import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.plugins.mongomk.UpdateOp.Key;
+import org.apache.jackrabbit.oak.plugins.mongomk.UpdateOp.Operation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Objects;
+import com.google.common.base.Splitter;
 import com.google.common.cache.Cache;
 import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.Striped;
@@ -49,11 +51,10 @@ import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 import com.mongodb.MongoException;
 import com.mongodb.QueryBuilder;
+import com.mongodb.ReadPreference;
 import com.mongodb.WriteConcern;
 import com.mongodb.WriteResult;
 
-import static org.apache.jackrabbit.oak.plugins.mongomk.UpdateOp.Key;
-
 /**
  * A document store that uses MongoDB as the backend.
  */
@@ -87,6 +88,8 @@ public class MongoDocumentStore implemen
      */
     private final Comparator<Revision> comparator = StableRevisionComparator.REVERSE;
 
+    private String lastReadWriteMode;
+
     public MongoDocumentStore(DB db, MongoMK.Builder builder) {
         nodes = db.getCollection(
                 Collection.NODES.toString());
@@ -768,4 +771,33 @@ public class MongoDocumentStore implemen
         l.lock();
         return l;
     }
+
+    @Override
+    public void setReadWriteMode(String readWriteMode) {
+        if (readWriteMode == null || readWriteMode.equals(lastReadWriteMode)) {
+            return;
+        }
+        lastReadWriteMode = readWriteMode;
+        try {
+            Map<String, String> map = Splitter.on(", ").withKeyValueSeparator(":").split(readWriteMode);
+            String read = map.get("read");
+            if (read != null) {
+                ReadPreference readPref = ReadPreference.valueOf(read);
+                if (!readPref.equals(nodes.getReadPreference())) {
+                    nodes.setReadPreference(readPref);
+                    LOG.info("Using ReadPreference " + readPref);
+                }
+            } 
+            String write = map.get("write");
+            if (write != null) {
+                WriteConcern writeConcern = WriteConcern.valueOf(write);
+                if (!writeConcern.equals(nodes.getWriteConcern())) {
+                    nodes.setWriteConcern(writeConcern);
+                    LOG.info("Using WriteConcern " + writeConcern);
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Error setting readWriteMode " + readWriteMode, e);
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
Tue Jan 21 09:23:21 2014
@@ -40,7 +40,7 @@ public class LoggingDocumentStoreWrapper
     private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("ds.debug",
"true"));
 
     final DocumentStore store;
-    private boolean logThread = false;
+    private boolean logThread;
 
     public LoggingDocumentStoreWrapper(DocumentStore store) {
         this.store = store;
@@ -261,6 +261,17 @@ public class LoggingDocumentStoreWrapper
             throw convert(e);
         }
     }
+    
+    @Override
+    public void setReadWriteMode(String readWriteMode) {
+        try {
+            logMethod("setReadWriteMode", readWriteMode);
+            store.setReadWriteMode(readWriteMode);
+        } catch (Exception e) {
+            logException(e);
+            throw convert(e);
+        }
+    }
 
     private void logMethod(String methodName, Object... args) {
         StringBuilder buff = new StringBuilder("ds");

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/SynchronizingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/SynchronizingDocumentStoreWrapper.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/SynchronizingDocumentStoreWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/SynchronizingDocumentStoreWrapper.java
Tue Jan 21 09:23:21 2014
@@ -39,75 +39,81 @@ public class SynchronizingDocumentStoreW
     }
 
     @Override
-    synchronized public <T extends Document> T find(final Collection<T> collection,
final String key) {
+    public synchronized <T extends Document> T find(final Collection<T> collection,
final String key) {
         return store.find(collection, key);
     }
 
     @Override
-    synchronized public <T extends Document> T find(final Collection<T> collection,
final String key, final int maxCacheAge) {
+    public synchronized <T extends Document> T find(final Collection<T> collection,
final String key, final int maxCacheAge) {
         return store.find(collection, key, maxCacheAge);
     }
 
     @Nonnull
     @Override
-    synchronized public <T extends Document> List<T> query(final Collection<T>
collection, final String fromKey,
+    public synchronized <T extends Document> List<T> query(final Collection<T>
collection, final String fromKey,
             final String toKey, final int limit) {
         return store.query(collection, fromKey, toKey, limit);
     }
 
     @Override
     @Nonnull
-    synchronized public <T extends Document> List<T> query(final Collection<T>
collection, final String fromKey,
+    public synchronized <T extends Document> List<T> query(final Collection<T>
collection, final String fromKey,
             final String toKey, final String indexedProperty, final long startValue, final
int limit) {
         return store.query(collection, fromKey, toKey, indexedProperty, startValue, limit);
     }
 
     @Override
-    synchronized public <T extends Document> void remove(Collection<T> collection,
String key) {
+    public synchronized <T extends Document> void remove(Collection<T> collection,
String key) {
         store.remove(collection, key);
     }
 
     @Override
-    synchronized public <T extends Document> boolean create(final Collection<T>
collection, final List<UpdateOp> updateOps) {
+    public synchronized <T extends Document> boolean create(final Collection<T>
collection, final List<UpdateOp> updateOps) {
         return store.create(collection, updateOps);
     }
 
     @Override
-    synchronized public <T extends Document> void update(final Collection<T>
collection, final List<String> keys,
+    public synchronized <T extends Document> void update(final Collection<T>
collection, final List<String> keys,
             final UpdateOp updateOp) {
         store.update(collection, keys, updateOp);
     }
 
     @Nonnull
     @Override
-    synchronized public <T extends Document> T createOrUpdate(final Collection<T>
collection, final UpdateOp update)
+    public synchronized <T extends Document> T createOrUpdate(final Collection<T>
collection, final UpdateOp update)
             throws MicroKernelException {
         return store.createOrUpdate(collection, update);
     }
 
     @Override
-    synchronized public <T extends Document> T findAndUpdate(final Collection<T>
collection, final UpdateOp update)
+    public synchronized <T extends Document> T findAndUpdate(final Collection<T>
collection, final UpdateOp update)
             throws MicroKernelException {
         return store.findAndUpdate(collection, update);
     }
 
     @Override
-    synchronized public void invalidateCache() {
+    public synchronized void invalidateCache() {
         store.invalidateCache();
     }
 
     @Override
-    synchronized public <T extends Document> void invalidateCache(Collection<T>
collection, String key) {
+    public synchronized <T extends Document> void invalidateCache(Collection<T>
collection, String key) {
         store.invalidateCache(collection, key);
     }
 
     @Override
-    synchronized public void dispose() {
+    public synchronized void dispose() {
         store.dispose();
     }
 
     @Override
-    synchronized public <T extends Document> T getIfCached(final Collection<T>
collection, final String key) {
+    public synchronized <T extends Document> T getIfCached(final Collection<T>
collection, final String key) {
         return store.getIfCached(collection, key);
     }
+    
+    @Override
+    public synchronized void setReadWriteMode(String readWriteMode) {
+        store.setReadWriteMode(readWriteMode);
+    }    
+    
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/TimingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/TimingDocumentStoreWrapper.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/TimingDocumentStoreWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/TimingDocumentStoreWrapper.java
Tue Jan 21 09:23:21 2014
@@ -286,6 +286,17 @@ public class TimingDocumentStoreWrapper 
         }
     }
     
+    @Override
+    public void setReadWriteMode(String readWriteMode) {
+        try {
+            long start = now();
+            base.setReadWriteMode(readWriteMode);
+            updateAndLogTimes("setReadWriteMode", start, 0, 0);
+        } catch (Exception e) {
+            throw convert(e);
+        }
+    }
+    
     private void logCommonCall(long start, String key) {
         int time = (int) (System.currentTimeMillis() - start);
         if (time <= 0) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java
Tue Jan 21 09:23:21 2014
@@ -494,4 +494,10 @@ public class SQLDocumentStore implements
             stmt.close();
         }
     }
+
+    @Override
+    public void setReadWriteMode(String readWriteMode) {
+        // ignored
+    }
+
 }

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterInfoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterInfoTest.java?rev=1559951&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterInfoTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterInfoTest.java
Tue Jan 21 09:23:21 2014
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.mongomk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import com.mongodb.ReadPreference;
+import com.mongodb.WriteConcern;
+
+/**
+ * Test the ClusterInfo class
+ */
+public class ClusterInfoTest {
+    
+    @Test
+    public void readWriteMode() throws InterruptedException {
+        
+        MemoryDocumentStore mem = new MemoryDocumentStore();
+        MongoNodeStore ns1 = new MongoMK.Builder().
+                setDocumentStore(mem).
+                setAsyncDelay(0).
+                getNodeStore();
+        MongoNodeStore ns2 = new MongoMK.Builder().
+                setDocumentStore(mem).
+                setAsyncDelay(0).
+                getNodeStore();
+        ns1.getClusterInfo().setLeaseTime(0);
+        ns2.getClusterInfo().setLeaseTime(0);
+        List<ClusterNodeInfoDocument> list = mem.query(
+                Collection.CLUSTER_NODES, "0", "a", Integer.MAX_VALUE);
+        assertEquals(2, list.size());
+        
+        assertNull(mem.getReadPreference());
+        assertNull(mem.getWriteConcern());
+        mem.setReadWriteMode("read:primary, write:majority");
+        assertEquals(ReadPreference.primary(), mem.getReadPreference());
+        assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
+
+        UpdateOp op;
+        
+        // unknown modes: ignore
+        op = new UpdateOp(list.get(0).getId(), false);
+        op.set("readWriteMode", "read:xyz, write:abc");
+        mem.findAndUpdate(Collection.CLUSTER_NODES, op);
+        ns1.runBackgroundOperations();
+        assertEquals(ReadPreference.primary(), mem.getReadPreference());
+        assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
+
+        op = new UpdateOp(list.get(0).getId(), false);
+        op.set("readWriteMode", "read:nearest, write:fsynced");
+        mem.findAndUpdate(Collection.CLUSTER_NODES, op);
+        ns1.runBackgroundOperations();
+        assertEquals(ReadPreference.nearest(), mem.getReadPreference());
+        assertEquals(WriteConcern.FSYNCED, mem.getWriteConcern());
+
+        ns1.dispose();
+        ns2.dispose();
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterJoinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterJoinTest.java?rev=1559951&r1=1559950&r2=1559951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterJoinTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/ClusterJoinTest.java
Tue Jan 21 09:23:21 2014
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.mongomk;
 
-import org.apache.jackrabbit.oak.plugins.mongomk.util.MongoConnection;
 import org.json.simple.JSONObject;
 import org.junit.Test;
 



Mime
View raw message