|
14 | 14 |
|
15 | 15 | package org.janusgraph.diskstorage.berkeleyje; |
16 | 16 |
|
17 | | - |
18 | 17 | import com.google.common.base.Preconditions; |
19 | 18 | import com.sleepycat.je.CacheMode; |
20 | 19 | import com.sleepycat.je.Database; |
|
44 | 43 | import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration; |
45 | 44 | import org.janusgraph.graphdb.configuration.PreInitializeConfigOptions; |
46 | 45 | import org.janusgraph.graphdb.transaction.TransactionConfiguration; |
| 46 | +import org.janusgraph.util.system.ConfigurationUtil; |
47 | 47 | import org.janusgraph.util.system.IOUtils; |
48 | 48 | import org.slf4j.Logger; |
49 | 49 | import org.slf4j.LoggerFactory; |
@@ -88,6 +88,27 @@ public class BerkeleyJEStoreManager extends LocalStoreManager implements Ordered |
88 | 88 | ConfigOption.Type.MASKABLE, String.class, |
89 | 89 | IsolationLevel.REPEATABLE_READ.toString(), disallowEmpty(String.class)); |
90 | 90 |
|
| 91 | + public static final ConfigNamespace BERKELEY_EXTRAS_NS = |
| 92 | + new ConfigNamespace(BERKELEY_NS, "ext", "Overrides for arbitrary settings applied at `EnvironmentConfig` creation.\n" + |
| 93 | + "The full list of possible setting is available inside the Java class `com.sleepycat.je.EnvironmentConfig`. " + |
| 94 | + "All configurations values should be specified as `String` and be formated the same as specified in the following " + |
| 95 | + "[documentation](https://docs.oracle.com/cd/E17277_02/html/java/com/sleepycat/je/EnvironmentConfig.html).\n" + |
| 96 | + "Notice, for compatibility reasons, it's allowed to use `-` character instead of `.` for config keys. All dashes will " + |
| 97 | + "be replaced by dots when passing those keys to `EnvironmentConfig`."); |
| 98 | + |
| 99 | + // This setting isn't used directly in Java, but this setting will be picked up indirectly during parsing of the |
| 100 | + // subset configuration of `BERKELEY_EXTRAS_NS` namespace |
| 101 | + public static final ConfigOption<String> EXT_LOCK_TIMEOUT = |
| 102 | + new ConfigOption<>(BERKELEY_EXTRAS_NS, toJanusGraphConfigKey(EnvironmentConfig.LOCK_TIMEOUT), |
| 103 | + String.format("Lock timeout configuration. `0` disabled lock timeout completely. " + |
| 104 | + "To set lock timeout via this configuration it's required to use " + |
| 105 | + "String formated time representation. For example: `500 ms`, `5 min`, etc. \nSee information about value " + |
| 106 | + "constraints in the official " + |
| 107 | + "[sleepycat documentation](https://docs.oracle.com/cd/E17277_02/html/java/com/sleepycat/je/EnvironmentConfig.html#LOCK_TIMEOUT).\n" + |
| 108 | + "Notice, this option can be specified as `%s` which will be treated the same as this configuration option.", |
| 109 | + BERKELEY_EXTRAS_NS.toStringWithoutRoot() + "." + EnvironmentConfig.LOCK_TIMEOUT |
| 110 | + ), ConfigOption.Type.MASKABLE, String.class); |
| 111 | + |
91 | 112 | private final Map<String, BerkeleyJEKeyValueStore> stores; |
92 | 113 |
|
93 | 114 | protected Environment environment; |
@@ -132,12 +153,32 @@ private void initialize(int cachePercent, final boolean sharedCache, final Cache |
132 | 153 | } |
133 | 154 |
|
134 | 155 | //Open the environment |
| 156 | + Map<String, String> extraSettings = getSettingsFromJanusGraphConf(storageConfig); |
| 157 | + extraSettings.forEach((key, value) -> envConfig.setConfigParam(toBerkeleyConfigKey(key), value)); |
| 158 | + |
| 159 | + // Open the environment |
135 | 160 | environment = new Environment(directory, envConfig); |
136 | 161 |
|
137 | 162 | } catch (DatabaseException e) { |
138 | 163 | throw new PermanentBackendException("Error during BerkeleyJE initialization: ", e); |
139 | 164 | } |
| 165 | + } |
| 166 | + |
| 167 | + public static String toBerkeleyConfigKey(String janusGraphConfigKey){ |
| 168 | + return janusGraphConfigKey.replace("-", "."); |
| 169 | + } |
140 | 170 |
|
| 171 | + public static String toJanusGraphConfigKey(String berkeleyConfigKey){ |
| 172 | + return berkeleyConfigKey.replace(".", "-"); |
| 173 | + } |
| 174 | + |
| 175 | + static Map<String, String> getSettingsFromJanusGraphConf(Configuration config) { |
| 176 | + final Map<String, String> settings = ConfigurationUtil.getSettingsFromJanusGraphConf(config, BERKELEY_EXTRAS_NS); |
| 177 | + if(log.isDebugEnabled()){ |
| 178 | + settings.forEach((key, val) -> log.debug("[BERKELEY ext.* cfg] Set {}: {}", key, val)); |
| 179 | + log.debug("Loaded {} settings from the {} JanusGraph config namespace", settings.size(), BERKELEY_EXTRAS_NS); |
| 180 | + } |
| 181 | + return settings; |
141 | 182 | } |
142 | 183 |
|
143 | 184 | @Override |
@@ -335,4 +376,8 @@ private TransactionBegin(String msg) { |
335 | 376 | super(msg); |
336 | 377 | } |
337 | 378 | } |
| 379 | + |
| 380 | + public Environment getEnvironment(){ |
| 381 | + return environment; |
| 382 | + } |
338 | 383 | } |
0 commit comments