Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Git index locking problem
Git index locking problem [message #1727357] Tue, 22 March 2016 08:05 Go to next message
Eclipse UserFriend
Hi!
My scenario in my java program is the following:
1. Two users in parallel commit a file and doing a push.
2. Method is synchronized.
3. Code:
synchronized(getSynchroForRepo(rootRepoDir)) {
            File file = new File(rootRepoDir, listDefinitionName);
            writeFile(file, xmlDef.getBytes());
    		try {
    			git.add().addFilepattern(listDefinitionName).call();
    			CommitCommand commit = git.commit();
    			commit.setMessage("Commit file: "+listDefinitionName).call();
    			GitPush();
    		}


Unfortunately I get the exception (addFilepattern line above):
org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:242)
...
Caused by: org.eclipse.jgit.errors.LockFailedException: Cannot lock C:\RepoGit\.git\index
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:250)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:327)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:293)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:1158)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:147)
... 30 more


If anybody had any idea what I'm doing wrong I'd appreciate it!
Re: Git index locking problem [message #1727505 is a reply to message #1727357] Wed, 23 March 2016 07:58 Go to previous messageGo to next message
Eclipse UserFriend
I think I found a solution. I had different methods for repo access like storeFile(), removeFile(), getFile() etc.
Each method was synchronized with different key. After changing so all store/remove methods use the same synchronization key, so far my tests don't show any problems.
Re: Git index locking problem [message #1729407 is a reply to message #1727505] Wed, 13 April 2016 18:00 Go to previous messageGo to next message
Eclipse UserFriend
The DirCache (aka git index) can only be locked once.
So all operations working on a working tree needing a locked index can't run concurrently.
The straight forward solution is to use one clone per user, as soon as support for git worktree is available in jgit
this could also help. With that each user would need a separate worktree (sharing the same .git object database) and git index.
Unfortunately worktree support isn't yet available in jgit.
Re: Git index locking problem [message #1731734 is a reply to message #1729407] Mon, 09 May 2016 12:04 Go to previous message
Eclipse UserFriend
Thanks. Makes sense.
Previous Topic:disable 'Information Message' from egit
Next Topic:Hirarchical grouping for unstaged files
Goto Forum:
  


Current Time: Thu Jul 10 03:28:06 EDT 2025

Powered by FUDForum. Page generated in 0.05922 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top