2222import com .sleepycat .je .DatabaseException ;
2323import com .sleepycat .je .Environment ;
2424import com .sleepycat .je .EnvironmentConfig ;
25- import com .sleepycat .je .EnvironmentFailureException ;
2625import com .sleepycat .je .LockMode ;
27- import com .sleepycat .je .ThreadInterruptedException ;
2826import com .sleepycat .je .Transaction ;
2927import com .sleepycat .je .TransactionConfig ;
30- import org .apache .tinkerpop .gremlin .process .traversal .util .TraversalInterruptedException ;
3128import org .janusgraph .diskstorage .BackendException ;
3229import org .janusgraph .diskstorage .BaseTransactionConfig ;
3330import org .janusgraph .diskstorage .PermanentBackendException ;
3431import org .janusgraph .diskstorage .StaticBuffer ;
35- import org .janusgraph .diskstorage .TemporaryBackendException ;
3632import org .janusgraph .diskstorage .common .LocalStoreManager ;
3733import org .janusgraph .diskstorage .configuration .ConfigNamespace ;
3834import org .janusgraph .diskstorage .configuration .ConfigOption ;
5248import org .slf4j .Logger ;
5349import org .slf4j .LoggerFactory ;
5450
51+ import java .util .HashMap ;
5552import java .util .List ;
5653import java .util .Map ;
57- import java .util .concurrent .ConcurrentHashMap ;
58- import java .util .concurrent .ConcurrentMap ;
5954
6055import static org .janusgraph .diskstorage .configuration .ConfigOption .disallowEmpty ;
6156
@@ -93,16 +88,19 @@ public class BerkeleyJEStoreManager extends LocalStoreManager implements Ordered
9388 ConfigOption .Type .MASKABLE , String .class ,
9489 IsolationLevel .REPEATABLE_READ .toString (), disallowEmpty (String .class ));
9590
96- private final ConcurrentMap <String , BerkeleyJEKeyValueStore > stores ;
91+ private final Map <String , BerkeleyJEKeyValueStore > stores ;
9792
98- protected volatile Environment environment ;
93+ protected Environment environment ;
9994 protected final StoreFeatures features ;
10095
10196 public BerkeleyJEStoreManager (Configuration configuration ) throws BackendException {
10297 super (configuration );
103- stores = new ConcurrentHashMap <>();
98+ stores = new HashMap <>();
10499
105- initialize ();
100+ int cachePercentage = configuration .get (JVM_CACHE );
101+ boolean sharedCache = configuration .get (SHARED_CACHE );
102+ CacheMode cacheMode = ConfigOption .getEnumValue (configuration .get (CACHE_MODE ), CacheMode .class );
103+ initialize (cachePercentage , sharedCache , cacheMode );
106104
107105 features = new StandardStoreFeatures .Builder ()
108106 .orderedScan (true )
@@ -113,24 +111,14 @@ public BerkeleyJEStoreManager(Configuration configuration) throws BackendExcepti
113111 .scanTxConfig (GraphDatabaseConfiguration .buildGraphConfiguration ()
114112 .set (ISOLATION_LEVEL , IsolationLevel .READ_UNCOMMITTED .toString ())
115113 )
116- .supportsInterruption (true )
114+ .supportsInterruption (false )
117115 .cellTTL (true )
118116 .optimisticLocking (false )
119117 .build ();
120118 }
121119
122- private synchronized void initialize () throws BackendException {
120+ private void initialize (int cachePercent , final boolean sharedCache , final CacheMode cacheMode ) throws BackendException {
123121 try {
124- if (environment != null && environment .isValid ()) {
125- return ;
126- }
127-
128- close (true );
129-
130- int cachePercent = storageConfig .get (JVM_CACHE );
131- boolean sharedCache = storageConfig .get (SHARED_CACHE );
132- CacheMode cacheMode = ConfigOption .getEnumValue (storageConfig .get (CACHE_MODE ), CacheMode .class );
133-
134122 EnvironmentConfig envConfig = new EnvironmentConfig ();
135123 envConfig .setAllowCreate (true );
136124 envConfig .setTransactional (transactional );
@@ -143,28 +131,15 @@ private synchronized void initialize() throws BackendException {
143131 envConfig .setConfigParam (EnvironmentConfig .ENV_RUN_CLEANER , "false" );
144132 }
145133
146- // Open the environment
134+ //Open the environment
147135 environment = new Environment (directory , envConfig );
148136
149- // Reopen any existing DB connections
150- for (String storeName : stores .keySet ()) {
151- openDatabase (storeName , true );
152- }
153137 } catch (DatabaseException e ) {
154138 throw new PermanentBackendException ("Error during BerkeleyJE initialization: " , e );
155139 }
156140
157141 }
158142
159- private synchronized void reInitialize (DatabaseException exception ) throws BackendException {
160- initialize ();
161-
162- if (exception instanceof ThreadInterruptedException ) {
163- Thread .currentThread ().interrupt ();
164- throw (TraversalInterruptedException ) new TraversalInterruptedException ().initCause (exception );
165- }
166- }
167-
168143 @ Override
169144 public StoreFeatures getFeatures () {
170145 return features ;
@@ -175,7 +150,8 @@ public List<KeyRange> getLocalKeyPartition() throws BackendException {
175150 throw new UnsupportedOperationException ();
176151 }
177152
178- private BerkeleyJETx beginTransaction (final BaseTransactionConfig txCfg , boolean retryEnvironmentFailure ) throws BackendException {
153+ @ Override
154+ public BerkeleyJETx beginTransaction (final BaseTransactionConfig txCfg ) throws BackendException {
179155 try {
180156 Transaction tx = null ;
181157
@@ -206,27 +182,15 @@ private BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg, boolean
206182 }
207183
208184 return btx ;
209- } catch (EnvironmentFailureException e ) {
210- reInitialize (e );
211-
212- if (retryEnvironmentFailure ) {
213- return beginTransaction (txCfg , false );
214- }
215-
216- throw new TemporaryBackendException ("Could not start BerkeleyJE transaction" , e );
217185 } catch (DatabaseException e ) {
218186 throw new PermanentBackendException ("Could not start BerkeleyJE transaction" , e );
219187 }
220188 }
221189
222190 @ Override
223- public BerkeleyJETx beginTransaction (final BaseTransactionConfig txCfg ) throws BackendException {
224- return beginTransaction (txCfg , true );
225- }
226-
227- private BerkeleyJEKeyValueStore openDatabase (String name , boolean force , boolean retryEnvironmentFailure ) throws BackendException {
191+ public BerkeleyJEKeyValueStore openDatabase (String name ) throws BackendException {
228192 Preconditions .checkNotNull (name );
229- if (stores .containsKey (name ) && ! force ) {
193+ if (stores .containsKey (name )) {
230194 return stores .get (name );
231195 }
232196 try {
@@ -245,34 +209,13 @@ private BerkeleyJEKeyValueStore openDatabase(String name, boolean force, boolean
245209 log .debug ("Opened database {}" , name );
246210
247211 BerkeleyJEKeyValueStore store = new BerkeleyJEKeyValueStore (name , db , this );
248- if (stores .containsKey (name )) {
249- stores .get (name ).reopen (db );
250- } else {
251- stores .put (name , store );
252- }
212+ stores .put (name , store );
253213 return store ;
254- } catch (EnvironmentFailureException e ) {
255- reInitialize (e );
256-
257- if (retryEnvironmentFailure ) {
258- return openDatabase (name , force , false );
259- }
260-
261- throw new TemporaryBackendException ("Could not open BerkeleyJE data store" , e );
262214 } catch (DatabaseException e ) {
263215 throw new PermanentBackendException ("Could not open BerkeleyJE data store" , e );
264216 }
265217 }
266218
267- private BerkeleyJEKeyValueStore openDatabase (String name , boolean force ) throws BackendException {
268- return openDatabase (name , force , true );
269- }
270-
271- @ Override
272- public BerkeleyJEKeyValueStore openDatabase (String name ) throws BackendException {
273- return openDatabase (name , false , true );
274- }
275-
276219 @ Override
277220 public void mutateMany (Map <String , KVMutation > mutations , StoreTransaction txh ) throws BackendException {
278221 for (Map .Entry <String ,KVMutation > mutation : mutations .entrySet ()) {
@@ -309,16 +252,18 @@ void removeDatabase(BerkeleyJEKeyValueStore db) {
309252 log .debug ("Removed database {}" , name );
310253 }
311254
312- public void close (boolean force ) throws BackendException {
255+
256+ @ Override
257+ public void close () throws BackendException {
313258 if (environment != null ) {
314- if (!force && ! stores .isEmpty ())
259+ if (!stores .isEmpty ())
315260 throw new IllegalStateException ("Cannot shutdown manager since some databases are still open" );
316261 try {
317262 // TODO this looks like a race condition
318263 //Wait just a little bit before closing so that independent transaction threads can clean up.
319264 Thread .sleep (30 );
320265 } catch (InterruptedException e ) {
321- Thread . currentThread (). interrupt ();
266+ //Ignore
322267 }
323268 try {
324269 environment .close ();
@@ -329,11 +274,6 @@ public void close(boolean force) throws BackendException {
329274
330275 }
331276
332- @ Override
333- public void close () throws BackendException {
334- close (false );
335- }
336-
337277 private static final Transaction NULL_TRANSACTION = null ;
338278
339279 @ Override
0 commit comments