使用嵌入在Neo4j中的不同数据库和Java

时间:2015-07-14 10:04:14

标签: java neo4j neo4j-embedded

我正在尝试评估Neo4j中的不同数据模型。出于这个原因,我创建了两个具有不同模型的数据库并将它们保存在同一目录中:

path/to/database/graphModel1
path/to/database/graphModel2

下一步是我用java创建了一个应用程序,我可以在其中选择数据模型和我想要评估的查询(只有少数预定义查询)。根据选择的模型,我想使用嵌入式数据库的实例。目前我使用以下if子句来区分它们:

if (model.equals("G1")) {
    graph = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH_1);
} else if (model.equals("G2")) {
    graph = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH_2);
} 
registerShutdownHook(graph);

但是使用那段代码后,我在使用model1进行第一次查询并想要使用model2计算相同的查询后得到以下异常:

Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@1f1e9b8' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:513)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
... 69 more
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: path/to/database/graphModel1/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:78)
at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:44)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:507)
... 71 more
Caused by: java.io.IOException: Couldn't lock lock file path/to/database/graphModel1/lock because another process already holds the lock.
at org.neo4j.io.fs.FileLock.getLockFileBasedFileLock(FileLock.java:126)
at org.neo4j.io.fs.FileLock.getOsSpecificFileLock(FileLock.java:70)
at org.neo4j.io.fs.DefaultFileSystemAbstraction.tryLock(DefaultFileSystemAbstraction.java:85)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:74)
... 73 more

我意识到第一个数据库上已经有store_locklock,但这对启动第二个嵌入式数据库有何影响?有谁知道如何解决这个问题?

提前致谢!

1 个答案:

答案 0 :(得分:1)

您的GraphDatabase实例可能未正确关闭 - 使其处于锁定状态。我在上面的代码中看到你正在注册一个关闭钩子,但是对于graphDB而不是graph。这可能解释了实例未正确关闭的方式。

如果您知道没有其他实例指向您的Neo4j目录,您可以尝试手动删除graph.db/lockgraph.db/store_lock文件并再次运行您的代码。