Repository navigation
Conversation
sebhofmann
left a comment
There was a problem hiding this comment.
Merge assessment: Mergeable after the allocation accounting in cacheUpdate is fixed (see inline comment). The two nits are optional. CI is green.
This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
| * from the digest of the content, so the existing file has the same content. It may exist on disk without | ||
| * being in the cache index, for example if another process using the same directory wrote it. | ||
| */ | ||
| private static void moveToFinalPath(Path tempFile, Path finalPath) throws IOException { |
There was a problem hiding this comment.
Cache allocation drifts on concurrent writes of the same content
Before this change, the second writer of the same content failed with FileAlreadyExistsException. Now both writers reach cacheUpdate, which is not atomic:
FileInfo fileInfo = this.cache.get(digest); // both threads see null
boolean newFile = fileInfo == null;
this.totalAllocation.addAndGet(newFile ? size : size - fileInfo.size); // size is added twice
this.cache.put(...);If two threads write the same content and both pass the containsKey check before either updates the cache, totalAllocation is permanently too high. The eviction strategy then evicts too early, and the journal gets two Add events.
Suggestion: use the return value of put:
FileInfo previous = this.cache.put(digest, new FileInfo(digest, size, originalFileName));
this.totalAllocation.addAndGet(previous == null ? size : size - previous.size());This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
| // fill the read cache with v1 | ||
| assertTrue(Files.exists(MCRVersionedPath.getPath(derivate, "v1", "/old.txt"))); | ||
|
|
||
| if (purge) { |
There was a problem hiding this comment.
Nit: purge is reused here to choose between purging through the file system and through the metadata manager, while elsewhere it is the purge configuration. It works because removeRoot only purges with purge=true, but it is confusing to read. A short comment would help.
This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
| @Override | ||
| public void purgeObject(String objectId) { | ||
| base.purgeObject(objectId); | ||
| purgeListeners.forEach(listener -> listener.accept(objectId)); |
There was a problem hiding this comment.
Nit: the listeners run after base.purgeObject. If a listener throws, the caller sees a failure although the object is already purged. Not relevant for invalidateAll, but a try/catch with LOGGER.error per listener would be more robust for future listeners.
This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
sebhofmann
left a comment
There was a problem hiding this comment.
All three points of the previous review are fixed.
Merge assessment: Mergeable after the journal compaction issue is fixed (see inline comment). CI is green.
This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
| // 4. Re-open the writer on the new, compacted journal file | ||
| this.journalWriter = Files.newBufferedWriter(journalFile, StandardCharsets.UTF_8, | ||
| StandardOpenOption.CREATE, StandardOpenOption.APPEND); | ||
| openWriter(); |
There was a problem hiding this comment.
Compaction on startup can leave the journal writer closed for good
Both weaknesses existed before, but they matter now that every startup may compact and several processes are explicitly supported:
- The temp file has a fixed name (
cache.journal.tmp). If two processes start at the same time and both compact, they write into the same file, and the firstmovecan move a half-written file. The next startup then fails with aDeserializationExceptionand clears the whole cache. compactcallsthis.close()before themove. If themovefails, e.g. withNoSuchFileExceptionbecause the other process already moved the temp file,journalWriterstaysnull.compactOnStartuponly logs a warning, every followingappendfails with "Journal is not open", andcacheUpdatenow only logs that. The process writes nothing to the journal until the next restart, and after it those files are unmanaged on disk.
Suggestion: create the temp file with Files.createTempFile(journalFile.getParent(), journalFile.getFileName().toString(), ".tmp") and call openWriter() in a finally, so the writer is open again after a failure.
This review was generated by an AI assistant (Claude) on behalf of sebhofmann.
…ile trees after purge - MCROCFLDefaultRemoteTemporaryStorage writes cache files to a temporary file first and moves them to their final path atomically, replacing an existing file with the same digest. A file that exists on disk but not in the cache index no longer fails the import with FileAlreadyExistsException, and concurrent writes of the same content do not conflict - MCROCFLXMLMetadataManager.retrieveContent(MCRObjectID) uses getContent(), so MCRGZIPOCFLXMLMetadataManager decompresses the current version. The content is bound to the version that was checked, instead of resolving the head again when it is read - MCROCFLRepository notifies listeners about purged objects. The MCROCFLVirtualObjectProvider removes all cached versions of a purged object and does not cache versions loaded during a purge, so a reused id is not read from the purged object. Purges by another process using the same repository are not noticed - the read cache is no longer modified inside computeIfAbsent, and written objects are invalidated right after each persist
Remote temporary storage: - Count the allocation only once for concurrent writes of the same content and for duplicate add events in the journal - Pass the size to cacheUpdate instead of reading it from the cache file, which a concurrent eviction may already have deleted - Keep a valid cache entry if appending it to the journal fails, only log the error - exists() no longer adds missing digests to the LRU queue - synchronizeCache only removes the cache entry of a missing file and no longer deletes files another thread or process may have written - Delete stale temporary files of interrupted downloads on startup - Document the shared use of the directory by several processes Journal: - Do not compact the journal on close anymore. Another process, like the web application while a CLI run ends, may still append to it - Compact on startup instead, right after the replay, if the journal contains more than twice as many events as cache entries - Reopen the journal writer if another process replaced or deleted the journal file, otherwise its entries would be lost File system provider and repository: - Remove the purge listener of the previous virtual object provider when init() is called again - A failing purge listener no longer makes a successful purge look failed to the caller - invalidateAll ignores non-derivate objects
433b6f2 to
1d170c0
Compare
Link to jira.
Pull Request Checklist (Author)
Please go through the following checklist before assigning the PR for review:
Ticket & Documentation
fixed-versionis correctly set in the ticket and matches the PR's target branch (main).Feature & Improvement Specific Checks
Bugfix-Specific Checks
Testing
MCR Conventions & Metadata
mycore.properties.mycore.properties.Multi-Repo Considerations
MIRrequired?