Error getting lock (org.neo4j.kernal.StoreLockException)

When I try to create new nodes in an existing database, I get the following exception:

org.neo4j.kernal.StoreLockException .

The following is a snippet of code - the actual line that causes the exception. Below I have added some details and a full stack trace.

If I create a new folder and use it as DB_PATH , then my code works fine the first time it starts. On the second launch, it will work with the same exception. Something seems to be preventing the castle from being obtained.

I tried to set permissions to read / write for each file in DB_PATH . Bad luck. Is there a parameter in one of the configuration files that should be disabled with respect to locks?

Metadata exception

 graphDB = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); 

Details (line 6)

 private static GraphDatabaseService graphDB = null; public static final String DB_PATH = "/Users/NtroduceMe/Downloads/neo4j-community-2.0.0-M03/data/ntroduceme"; private static Index<Node> userNodeIndex; private static Index<Node> rememberMeNodeIndex; static { graphDB = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); registerShutdownHook(graphDB); userNodeIndex = graphDB.index().forNodes("profile_id"); rememberMeNodeIndex = graphDB.index().forNodes("profile_id"); } 

Stack trace

 Jun 19, 2013 12:12:50 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [ProfileController] in context with path [] threw exception [Servlet execution threw an exception] with root cause org.neo4j.kernel.StoreLockException: Could not create lock file at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:85) at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:498) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115) at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:296) at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:100) at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:92) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:197) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69) at com.NtroduceMe.Utilities.GraphDBManager.<clinit>(GraphDBManager.java:22) at com.NtroduceMe.UserProfile.Profiles.createProfile(Profiles.java:141) at com.NtroduceMe.UserProfile.ProfileController.doPost(ProfileController.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722) 

Helper class i for storing database instance

 public class GraphDBManager { public static final String DB_PATH = "/Users/NtroduceMe/Downloads/neo4j-community-2.0.0-M03/data/ntroduceme"; private static final GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); private static Index<Node> userNodeIndex; private static Index<Node> rememberMeNodeIndex; static { registerShutdownHook(graphDB); userNodeIndex = graphDB.index().forNodes("profile_id"); rememberMeNodeIndex = graphDB.index().forNodes("profile_id"); } public static GraphDatabaseService getGraphDB(){ return graphDB; } public static Index<Node> getUserNodeIndex(){ return userNodeIndex; } public static Index<Node> getRemberMeNodeIndex(){ return rememberMeNodeIndex; } private static void registerShutdownHook(final GraphDatabaseService graphDb ) { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you "Ctrl-C" the // running application). Runtime.getRuntime().addShutdownHook( new Thread() { @Override public void run() { graphDb.shutdown(); } } ); } } 
+6
source share
5 answers

You do not close your database when the program terminates, so it leaves a lock file.

You might consider setting up a disconnect hook as described here: http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-setup.html#tutorials-java-embedded-setup-startstop

+1
source

I'm just wondering why you close the database before creating the nodes?

You cannot create nodes using a private database, so it could be like this:

  graphDB = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); userNodeIndex = graphDB.index().forNodes("profile_id"); rememberMeNodeIndex = graphDB.index().forNodes("profile_id"); Transaction tx = graphDb.beginTx(); try { Node node = graphDb.createNode(); node.setProperty( USER_ID, "userID"); nodeIndex.add( node, USER_ID, "userID" ); } 

and after you create all the nodes, you can call:

  registerShutdownHook(graphDB); 
+1
source

I don’t know what happened, but you could just check if the store_lock file is in your graphdb directory, and if not, just create it (with the β€œtouch” command) or something else? This should solve the problem.

+1
source

I'm not sure if you are still looking for a solution or not, but while working on a project I came across the same problem. This happens if the database does not close correctly after the program terminates, or if you registered a shutdownhook, this happens after the process is somehow forcibly terminated (by some of them ... very ... attentive ... college for example) therefore the hook is never called. This means that you will have to release the lock the next time the program starts. So, here is my code for this, hope it helps someone anyway.

 StoreLocker lock = new StoreLocker(new DefaultFileSystemAbstraction()); lock.checkLock(new File(DB_Location)); try { lock.release(); graph = new GraphDatabaseFactory().newEmbeddedDatabase(DB_Location); } catch (IOException e1) { e1.printStackTrace(); } 

Of course, you should only call it if something went wrong during the opening of the database! And it should be clear, but I will say it anyway, to be sure. The same error occurs if there are two or more instances of your program, using this method to release the lock in this case will cause additional problems!

+1
source

In the Neo4j manual:

An EmbeddedGraphDatabase instance can be split between multiple threads. Please note, however, that you cannot create multiple instances pointing to the same database.

And I had this error because I started the Neo4j server before deploying the application. As soon as I start the Neo4j server, an empty "lock" file is created and placed in the database directory.

So, I suppose this is because the instance has already been created, and I tried to create a new instance with my Java application, which is impossible .

+1
source

Source: https://habr.com/ru/post/947614/


All Articles