jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1560667 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java
Date Thu, 23 Jan 2014 12:35:35 GMT
Author: chetanm
Date: Thu Jan 23 12:35:35 2014
New Revision: 1560667

URL: http://svn.apache.org/r1560667
Log:
OAK-891 - Use DirectMemory as Level 2/Offheap cache

Enabling support for configuring off heap cache via OSGi. Further now various
properties are also read from framework properties also. So to configure offHeapCache
size from framework property use `oak.documentstore.offHeapCache`. Similar
pattern for cache also

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

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java?rev=1560667&r1=1560666&r2=1560667&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java
Thu Jan 23 12:35:35 2014
@@ -59,7 +59,9 @@ import static org.apache.jackrabbit.oak.
 public class MongoNodeStoreService{
     private static final String DEFAULT_URI = "mongodb://localhost:27017/oak";
     private static final int DEFAULT_CACHE = 256;
+    private static final int DEFAULT_OFF_HEAP_CACHE = 0;
     private static final String DEFAULT_DB = "oak";
+    private static final String PREFIX = "oak.documentstore.";
 
     /**
      * Name of framework property to configure Mongo Connection URI
@@ -86,6 +88,9 @@ public class MongoNodeStoreService{
     @Property(intValue = DEFAULT_CACHE)
     private static final String PROP_CACHE = "cache";
 
+    @Property(intValue = DEFAULT_OFF_HEAP_CACHE)
+    private static final String PROP_OFF_HEAP_CACHE = "offHeapCache";
+
     private static final long MB = 1024 * 1024;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -94,20 +99,17 @@ public class MongoNodeStoreService{
     private final List<Registration> registrations = new ArrayList<Registration>();
     private MongoMK mk;
     private ObserverTracker observerTracker;
+    private BundleContext bundleContext;
 
     @Activate
     protected void activate(BundleContext context, Map<String, ?> config) throws Exception
{
-        String uri = PropertiesUtil.toString(config.get(PROP_URI), DEFAULT_URI);
-        if(context.getProperty(FWK_PROP_URI) != null){
-            uri = context.getProperty(FWK_PROP_URI);
-        }
+        this.bundleContext = context;
 
-        String db = PropertiesUtil.toString(config.get(PROP_DB), DEFAULT_DB);
-        if(context.getProperty(FWK_PROP_DB) != null){
-            db = context.getProperty(FWK_PROP_DB);
-        }
+        String uri = PropertiesUtil.toString(prop(config, PROP_URI, FWK_PROP_URI), DEFAULT_URI);
+        String db = PropertiesUtil.toString(prop(config, PROP_DB, FWK_PROP_DB), DEFAULT_DB);
 
-        int cacheSize = PropertiesUtil.toInteger(config.get(PROP_CACHE), DEFAULT_CACHE);
+        int offHeapCache = PropertiesUtil.toInteger(prop(config, PROP_OFF_HEAP_CACHE), DEFAULT_OFF_HEAP_CACHE);
+        int cacheSize = PropertiesUtil.toInteger(prop(config, PROP_CACHE), DEFAULT_CACHE);
         boolean useMK = PropertiesUtil.toBoolean(config.get(PROP_USE_MK), false);
 
         MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
@@ -117,8 +119,8 @@ public class MongoNodeStoreService{
             //Take care around not logging the uri directly as it
             //might contain passwords
             String type = useMK ? "MicroKernel" : "NodeStore" ;
-            logger.info("Starting MongoDB {} with host={}, db={}",
-                    new Object[] {type,mongoURI.getHosts(), db});
+            logger.info("Starting MongoDB {} with host={}, db={}, cache size (MB)={}, Off
Heap Cache size (MB)={}",
+                    new Object[] {type,mongoURI.getHosts(), db, cacheSize, offHeapCache});
             logger.info("Mongo Connection details {}",MongoConnection.toString(mongoURI.getOptions()));
         }
 
@@ -127,6 +129,7 @@ public class MongoNodeStoreService{
 
         mk = new MongoMK.Builder()
                 .memoryCacheSize(cacheSize * MB)
+                .offHeapCacheSize(offHeapCache * MB)
                 .setMongoDB(mongoDB)
                 .open();
 
@@ -149,6 +152,21 @@ public class MongoNodeStoreService{
         reg = context.registerService(NodeStore.class.getName(), store, new Properties());
     }
 
+    private Object prop(Map<String, ?> config, String propName){
+        return prop(config,propName,PREFIX + propName);
+    }
+
+    private Object prop(Map<String, ?> config, String propName, String fwkPropName){
+        //Prefer framework property first
+        Object value = bundleContext.getProperty(fwkPropName);
+        if(value != null){
+            return value;
+        }
+
+        //Fallback to one from config
+        return config.get(propName);
+    }
+
     @Deactivate
     protected void deactivate() {
         if(observerTracker != null){
@@ -210,5 +228,7 @@ public class MongoNodeStoreService{
                             mds.getCacheStats().getName())
             );
         }
+
+        //TODO Register JMX bean for Off Heap Cache stats
     }
 }



Mime
View raw message