Bug 397355 - Make p2 access to the local Maven repository multi-process safe
Summary: Make p2 access to the local Maven repository multi-process safe
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Tycho (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 373175 347963 457249
Blocks: 380169
  Show dependency tree
 
Reported: 2013-01-03 05:26 EST by Tobias Oberlies CLA
Modified: 2021-04-28 16:54 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Oberlies CLA 2013-01-03 05:26:07 EST
The local Maven repository is also a p2 repository, and it caches artifacts downloaded from p2 repositories (.m2/repository/p2/...). Since 0.14 (see bug 347963), the access to the index file .m2/repository/.meta/p2-artifacts.properties is protected by a file lock, preventing corrupt index files through write access through multiple Tycho processes.

However there is still the possibility that two builds corrupt each others artifacts when both processes download the same p2 artifact because they download to the same file (without any locking). 

Holding the index lock while downloading a file would enforce a single-threaded download across processes and is therefore not an option. Per-artifact locks would IMHO also be too complicated. Instead, we should do the following:
- Download the file to a temporary file next to the target location in the local Maven repository.
- Acquire the index lock
- Check if another process has downloaded the same artifact in the meanwhile -> if yes, discard the own download
- Otherwise, copy the temporary file to the right location, write the p2artifacts metadata and update the index
- Release the index lock

With this approach, the artifacts are written at most once (and never deleted), so we don't need to lock read access to the local Maven repository.
Comment 1 Tobias Oberlies CLA 2013-01-03 05:30:11 EST
Although probably not absolutely required, we should also make the LocalArtifactRepository class thread-safe. This means that we need two locks: One for the in-memory representation of the repository index, and one for the file system (index file read/write, artifact write).
Comment 2 Tobias Oberlies CLA 2013-01-03 06:28:03 EST
Other multi-process problem not covered by this enhancement: bug 394998.
Comment 3 Tobias Oberlies CLA 2013-01-11 07:03:50 EST
I'm working on cleaning up the LocalArtifactRepository implementation. Cutting down the complexity as much as possible is probably a good idea before trying to make the remaining implementation thread-/process-safe.
Comment 4 Tobias Oberlies CLA 2013-07-08 05:30:22 EDT
The LocalArtifactRepository renovation is completed (see bug 393004 comment 4 for details). Now the work on thread and multi-process safety could start...
Comment 5 Tobias Oberlies CLA 2013-10-18 10:46:47 EDT
Optimizing the index update write operations (needed for bug 373175) is probably also a prerequisite for this enhancement. Marking bug 373175 as dependency.
Comment 6 Mickael Istria CLA 2021-04-08 18:14:25 EDT
Eclipse Tycho is moving away from this bugs.eclipse.org issue tracker to https://github.com/eclipse/tycho/issues/ instead. If this issue is relevant to you, your action is required.
0. Verify this issue is still happening with latest Tycho 2.4.0-SNAPSHOT
  if issue has disappeared, please change status of this issue to "CLOSED WORKFORME" with some details about your testing environment and how you did verify the issue; and you're done
  if issue is still present when latest release:
* Create a new issue at https://github.com/eclipse/tycho/issues/
  ** Use as title in GitHub the title of this Bugzilla ticket (may include the bug number or not, at your own convenience)
  ** In the GitHub description, start with a link to this bugzilla ticket
  ** Optionally add new content to the description if it can helps towards resolution
  ** Submit GitHub issue
* Update bugzilla ticket
  ** Add to "See also" property (up right column) the link to the newly created GitHub issue
  ** Add a comment "Migrated to <link-to-newly-created-GitHub-issue>"
  ** Set status as CLOSED MOVED
  ** Submit

All issues that remain open will be automatically closed next week or so. Then the Bugzilla component for Tycho will be archived and made read-only.