3

I am trying to evaluate different datamodels in Neo4j. For that reason I have created two databases which have those different models and saved them in the same directory:

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

The next step is that I have created an application with java where I can select the datamodel and the query I want to evaluate (there are only a few predefined queries). Depending which model was selected I want to use the instance of the embedded database. At the moment I use the following if-clause to distinguish between them:

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

But using that snippet of code I got the following exception after I did the first query with model1 and want to compute the same query with 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

I realized that there are already a store_lock and a lock on the first database but how does this affect starting a second embedded database? Does anyone know how to solve this problem?

Thanks in advance!

d.r.91
  • 123
  • 1
  • 5

2 Answers2

1

It is possible that your GraphDatabase instance was not properly shut down - leaving it in a locked state. I see in your code above that you are registering a shutdown hook, but for graphDB not graph. This might explain how the instance was not properly shut down.

If you know there are no other instances pointing to your Neo4j directory you can try manually deleting the graph.db/lock and graph.db/store_lock files and running your code again.

William Lyon
  • 8,371
  • 1
  • 17
  • 22
  • I am sorry, the difference between `graphDB` and `graph` were caused by a lack of concentration. The shutdown hook is registered for `graph`. As I shutdown the database manually I cannot create a new one, I have already tried this approach. – d.r.91 Jul 14 '15 at 15:25
0

There's long term common misunderstanding in the directory structure for (embedded) database storage location. Designers submit "root" DB folder in the API while required to submit child repository folder.

new GraphDatabaseFactory().newEmbeddedDatabase( "path/to/db" ) // wrong
new GraphDatabaseFactory().newEmbeddedDatabase( "path/to/db/repository" ) // correct

For described case, consider to extend paths to created/reused database locations, by "repository" folder (this name could be varied):

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

When both DB instances start simultaneously, you will see next file system items created:

path/to/database/graphModel1/repository
path/to/database/graphModel1/logs
path/to/database/graphModel1/store_lock

path/to/database/graphModel2/repository
path/to/database/graphModel2/logs
path/to/database/graphModel2/store_lock

As one can see, there are no any "store_lock" conflicts there. Verified with Neo4j version 3.5.17, "embedded" setup.