获取锁定时出错(org.neo4j.kernal.StoreLockException)

时间:2013-06-19 05:04:32

标签: java-ee tomcat neo4j

尝试在现有数据库中创建新节点时,我收到以下异常:

org.neo4j.kernal.StoreLockException

下面的代码snippit是导致的实际行 例外。下面我已经附上了一些更多细节和完整的堆栈跟踪。

如果我创建一个新文件夹并将其用作DB_PATH,那么我的代码在第一次运行时工作正常。在第二次运行时,它将失败并出现相同的异常。似乎有些事情阻止了获取锁定。

我尝试在DB_PATH中的每个文件上设置读/写权限。没运气。是否有一个配置文件中的设置必须禁用锁?

代码抛出异常

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

更多细节(第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");
}

堆栈跟踪

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)

我用来存储数据库实例的帮助程序类

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();
            }
        } );
    }   

}

5 个答案:

答案 0 :(得分:1)

程序结束时,您没有正确关闭数据库,所以它将锁定文件保留在那里。

您可以考虑设置一个关闭钩子,如下所述: http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-setup.html#tutorials-java-embedded-setup-startstop

答案 1 :(得分:1)

我只是想知道为什么在创建节点之前关闭数据库?

您无法使用已关闭的数据库创建节点,因此它可以是这样的:

 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" );
    }

在创建完所有节点后,您可以调用:

   registerShutdownHook(graphDB);

答案 2 :(得分:1)

我不知道发生了什么,但你能简单地检查你的graphdb目录中是否有“store_lock”文件,如果没有,只需创建它(使用“touch”命令)或其他什么?那应该解决它。

答案 3 :(得分:1)

我不确定您是否仍在搜索解决方案,但在处理项目时我偶然发现了同样的问题。如果数据库在程序终止后没有正确关闭,或者如果你已经注册了一个shutdownhook,就会发生这种情况,因为这个进程以某种方式被强行终止(有些......非常......体贴......例如大学)所以钩子永远不会被调用。这意味着您必须在下次启动程序时释放锁定。所以这里是我的代码,希望它仍能以某种方式帮助某人。

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();
        }

当然,如果在数据库打开过程中出现问题,你应该只调用它!这应该是清楚的,但我会说它只是为了确定。如果您的程序有两个或更多实例,则会发生同样的错误,在这种情况下使用这种方式释放锁定会引发更多问题!

答案 4 :(得分:1)

在Neo4j手册中:

  

EmbeddedGraphDatabase实例可以在多个实例之间共享   线程。但请注意,您无法创建多个实例   指向同一个数据库。

我之所以遇到这个错误只是因为我在部署应用程序之前运行了Neo4j Server。一旦我运行Neo4j服务器,就会创建一个空的“lock”文件并放在数据库目录中。

所以我想这是因为已经创建了一个实例,我试图通过我的Java应用程序创建新实例,这是不可能