-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TrackDAO/GlobalTrackCache: Handle file aliasing #3026
Changes from all commits
4804b6a
2cd49e8
e7993bc
588350f
f4426d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,8 +391,34 @@ bool GlobalTrackCache::isEmpty() const { | |
return m_tracksById.empty() && m_tracksByCanonicalLocation.empty(); | ||
} | ||
|
||
TrackPointer GlobalTrackCache::lookupByRef( | ||
const TrackRef& trackRef) { | ||
TrackPointer trackPtr; | ||
if (trackRef.hasId()) { | ||
trackPtr = lookupById(trackRef.getId()); | ||
if (trackPtr) { | ||
return trackPtr; | ||
} | ||
} | ||
if (trackRef.hasCanonicalLocation()) { | ||
trackPtr = lookupByCanonicalLocation(trackRef.getCanonicalLocation()); | ||
if (trackPtr) { | ||
if (trackRef.hasId() && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this ever be true because of the check in line 426? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If another track with a different id but the same canonical location has already been stored in the cache we will get here. That's part of the problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we might check that the found track also already has a valid id. Otherwise, this is a rare, intermediate edge case. |
||
trackRef.getId() != trackPtr->getId()) { | ||
kLogger.warning() | ||
<< "Found a different track with the same canonical location:" | ||
<< "expected =" << trackRef | ||
<< "actual =" << createTrackRef(*trackPtr); | ||
} | ||
return trackPtr; | ||
} | ||
} | ||
return trackPtr; | ||
} | ||
|
||
TrackPointer GlobalTrackCache::lookupById( | ||
const TrackId& trackId) { | ||
TrackPointer trackPtr; | ||
const auto trackById(m_tracksById.find(trackId)); | ||
if (m_tracksById.end() != trackById) { | ||
// Cache hit | ||
|
@@ -402,45 +428,43 @@ TrackPointer GlobalTrackCache::lookupById( | |
<< trackId | ||
<< trackById->second->getPlainPtr(); | ||
} | ||
return revive(trackById->second); | ||
trackPtr = revive(trackById->second); | ||
DEBUG_ASSERT(trackPtr); | ||
} else { | ||
// Cache miss | ||
if (traceLogEnabled()) { | ||
kLogger.trace() | ||
<< "Cache miss for" | ||
<< trackId; | ||
} | ||
return TrackPointer(); | ||
} | ||
return trackPtr; | ||
} | ||
|
||
TrackPointer GlobalTrackCache::lookupByRef( | ||
const TrackRef& trackRef) { | ||
if (trackRef.hasId()) { | ||
return lookupById(trackRef.getId()); | ||
TrackPointer GlobalTrackCache::lookupByCanonicalLocation( | ||
const QString& canonicalLocation) { | ||
TrackPointer trackPtr; | ||
const auto trackByCanonicalLocation( | ||
m_tracksByCanonicalLocation.find(canonicalLocation)); | ||
if (m_tracksByCanonicalLocation.end() != trackByCanonicalLocation) { | ||
// Cache hit | ||
if (traceLogEnabled()) { | ||
kLogger.trace() | ||
<< "Cache hit for" | ||
<< canonicalLocation | ||
<< trackByCanonicalLocation->second->getPlainPtr(); | ||
} | ||
trackPtr = revive(trackByCanonicalLocation->second); | ||
DEBUG_ASSERT(trackPtr); | ||
} else { | ||
const auto canonicalLocation = trackRef.getCanonicalLocation(); | ||
const auto trackByCanonicalLocation( | ||
m_tracksByCanonicalLocation.find(canonicalLocation)); | ||
if (m_tracksByCanonicalLocation.end() != trackByCanonicalLocation) { | ||
// Cache hit | ||
if (traceLogEnabled()) { | ||
kLogger.trace() | ||
<< "Cache hit for" | ||
<< canonicalLocation | ||
<< trackByCanonicalLocation->second->getPlainPtr(); | ||
} | ||
return revive(trackByCanonicalLocation->second); | ||
} else { | ||
// Cache miss | ||
if (traceLogEnabled()) { | ||
kLogger.trace() | ||
<< "Cache miss for" | ||
<< canonicalLocation; | ||
} | ||
return TrackPointer(); | ||
// Cache miss | ||
if (traceLogEnabled()) { | ||
kLogger.trace() | ||
<< "Cache miss for" | ||
<< canonicalLocation; | ||
} | ||
} | ||
return trackPtr; | ||
} | ||
|
||
TrackPointer GlobalTrackCache::revive( | ||
|
@@ -515,7 +539,8 @@ void GlobalTrackCache::resolve( | |
<< "Resolving track by canonical location" | ||
<< trackRef.getCanonicalLocation(); | ||
} | ||
auto strongPtr = lookupByRef(trackRef); | ||
auto strongPtr = lookupByCanonicalLocation( | ||
trackRef.getCanonicalLocation()); | ||
if (strongPtr) { | ||
// Cache hit | ||
if (debugLogEnabled()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The cacheResolver() failed to resolve the track by it's trackId, but has found a different track listed in the database, referencing ...
It took me a bit to remind me how everything is connected. So I think I think this comment helps here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the using code keeps has the old track ID already on stack and keeps using it.
So we either need to inform the using code about the changed track ID or fail here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to solve all downstream issues and also haven't spotted any serious issues at first sight.