Announcement Announcement Module
Collapse
No announcement yet.
`Unable to lock store` problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • `Unable to lock store` problem

    I'm having some issues with the following scenario:
    I have neo4j configured with spring-data-neo4j:

    Code:
    <context:spring-configured />
    
    	<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
    		<constructor-arg index="0" value="${neo4j.store}" />
    		<constructor-arg index="1">
    			<map>
    				<entry key="allow_store_upgrade" value="true" />
    			</map>
    		</constructor-arg>
    	</bean>
    	<neo4j:config graphDatabaseService="graphDatabaseService" />
    
    	<neo4j:repositories base-package="com.geocoding.persistence.dao.neo4j" />
    
    	<!-- Transaction configuration -->
    	<bean id="neo4jTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    		<property name="transactionManager">
    			<bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
    				<constructor-arg ref="graphDatabaseService" />
    			</bean>
    		</property>
    		<property name="userTransaction">
    			<bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
    				<constructor-arg ref="graphDatabaseService" />
    			</bean>
    		</property>
    	</bean>
    
    	<tx:annotation-driven mode="aspectj" transaction-manager="neo4jTransactionManager" />
    So my persistence layer is using neo4j; I'm also trying to use neo4j (the same GraphDatabaseService) for some spatial work - manually doing this (on context initialization):

    Code:
    public final class Neo4JFactoryBean implements FactoryBean<SimplePointLayer>, InitializingBean, DisposableBean {
        private static final Logger logger = LoggerFactory.getLogger(Neo4JFactoryBean.class);
    
        @Value("${search.neo4j.nameOfLayer}")
        String nameOfLayer;
    
        @Autowired
        GraphDatabaseService graphDatabase;
    
        private SimplePointLayer layer;
    
        private SpatialDatabaseService spatialDBService;
    
        public Neo4JFactoryBean() {
    	super();
        }
    
        // API - Spring
    
        @Override
        public final SimplePointLayer getObject() {
    	return layer;
        }
    
        @Override
        public final Class<SimplePointLayer> getObjectType() {
    	return SimplePointLayer.class;
        }
    
        @Override
        public final boolean isSingleton() {
    	return true;
        }
    
        // API
    
        public final void reset() {
    	try {
    	    spatialDBService.deleteLayer(nameOfLayer, new ConsoleListener());
    	} catch (final SpatialDatabaseException e) {
    	    logger.error("There was no layer to delete");
    	} catch (final NullPointerException e) { // TODO: this may hide an actual problem
    	    logger.error("There was no layer to delete");
    	}
        }
    
        public final void createLayer() {
    	try {
    	    logger.info("creating New Simple Point Layer named: " + nameOfLayer);
    	    spatialDBService.createSimplePointLayer(nameOfLayer);
    	    logger.info("New Simple Point Layer Created");
    	} catch (final SpatialDatabaseException e) {
    	    logger.error("Problem creating the SimplePointLayer...the layer probably already exists");
    	}
    	layer = (SimplePointLayer) spatialDBService.getOrCreateEditableLayer(nameOfLayer);
    	Preconditions.checkNotNull(layer);
        }
    
        // non-API
    
        @Override
        public final void afterPropertiesSet() {
    	try {
    	    spatialDBService = new SpatialDatabaseService(graphDatabase);
    
    	    reset();
    	    createLayer();
    	} catch (final Exception ex) {
    	    throw new IllegalStateException("Neo4J failed to start", ex);
    	}
        }
    
        @Override
        public void destroy() throws Exception {
    	spatialDBService.deleteLayer(nameOfLayer, new ConsoleListener());
        }
    
    }
    Running a Maven build (which executes tests) will fail as follows:

    Code:
    Caused by: java.lang.IllegalStateException: Unable to lock store [C:\opt\git\odesk\ross\Geolocation\data\graph_test17.db\neostore], this is usually a result of some other Neo4j kernel running using the same store.
    	at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:174) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.<init>(CommonAbstractStore.java:102) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at org.neo4j.kernel.impl.nioneo.store.AbstractStore.<init>(AbstractStore.java:119) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at org.neo4j.kernel.impl.nioneo.store.NeoStore.<init>(NeoStore.java:78) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.<init>(NeoStoreXaDataSource.java:214) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_02]
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_02]
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_02]
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:525) ~[na:1.7.0_02]
    	at org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:77) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:155) ~[neo4j-kernel-1.6.1.jar:1.6.1]
    	... 110 common frames omitted
    This happens ONLY when I'm first running a test that actually initializes the spatial components, then a normal test that is only initializing the persistence layer; each test runs fine individually.
    My initial though was that I am perhaps initializing some components in the spatial code that are not properly cleaned up, and so when the next test is executing, it fails because the GraphDatabaseService remains somehow locked from the previous test.

    I am currently on:
    - neo4j 1.6.1
    - neo4j-spatial 0.7-SNAPSHOT
    - spring-data-neo4j 2.0.1.RELEASE

    I am aware that there is some neo4j-spatial support in spring-data that I'm not yet using - for the time being I'm trying to use the API directly (which is why I'm instantiating my own SimplePointLayer).
    Is there anything I'm missing?
    Any help on this thorny issue is appreciated.
    Thanks.
    Eugen.

  • #2
    Eugen,

    please make sure that you always gdb.shutdown() or appContext.close after the test (in @After).

    In general only one Graph-Database within one JVM can access the store.

    HTH

    Michael

    Comment


    • #3
      Thanks for the response.
      All tests are using the Spring Test framework support, which should do appContext.close() (I'm not managing the context manually).
      Also, the actual gdb is managed by spring-data, so I'm assuming that also get's closed properly;
      The only thing I'm doing manually is injecting the GraphDatabaseService and doing this:
      spatialDBService = new SpatialDatabaseService(graphDatabase);
      spatialDBService.createSimplePointLayer(nameOfLaye r);
      spatialDBService.getOrCreateEditableLayer(nameOfLa yer);
      So, I could do:
      spatialDBService.getDatabase().shutdown();
      But that would mean I'm closing the underlying db manually, and since I'm not administering it, I don't know if that's necessary.
      What could be the cause of this issue (I'm able to consistently reproduce it).
      Is there some manual shutdowns I still need to do even considering my configuration (destroy-method="shutdown")?
      Thanks.
      Eugen.

      Comment


      • #4
        Eugen,

        could you please post the full stacktrace, I would be interested which part of the code tries to create the second graphdatabase instance.

        And can you please also show your spring-config and your test-class?

        Thanks

        Michael

        Comment

        Working...
        X