mirror of https://github.com/procxx/kepka.git
Fix crash in streaming caching.
This commit is contained in:
parent
12614ab68c
commit
08cd46cd4c
|
@ -550,17 +550,35 @@ int Reader::Slices::maxSliceSize(int sliceNumber) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Reader::SerializedSlice Reader::Slices::serializeAndUnloadUnused() {
|
Reader::SerializedSlice Reader::Slices::serializeAndUnloadUnused() {
|
||||||
|
using Flag = Slice::Flag;
|
||||||
|
|
||||||
if (_headerMode == HeaderMode::Unknown
|
if (_headerMode == HeaderMode::Unknown
|
||||||
|| _usedSlices.size() <= kSlicesInMemory) {
|
|| _usedSlices.size() <= kSlicesInMemory) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto purgeSlice = _usedSlices.front();
|
const auto purgeSlice = _usedSlices.front();
|
||||||
_usedSlices.pop_front();
|
_usedSlices.pop_front();
|
||||||
if (!(_data[purgeSlice].flags & Slice::Flag::LoadedFromCache)) {
|
if (!(_data[purgeSlice].flags & Flag::LoadedFromCache)) {
|
||||||
// If the only data in this slice was from _header, just leave it.
|
// If the only data in this slice was from _header, just leave it.
|
||||||
return {};
|
return {};
|
||||||
} else if (_headerMode == HeaderMode::NoCache
|
}
|
||||||
|| !(_data[purgeSlice].flags & Slice::Flag::ChangedSinceCache)) {
|
const auto noNeedToSaveToCache = [&] {
|
||||||
|
if (_headerMode == HeaderMode::NoCache) {
|
||||||
|
// Cache is not used.
|
||||||
|
return true;
|
||||||
|
} else if (!(_data[purgeSlice].flags & Flag::ChangedSinceCache)) {
|
||||||
|
// If no data was changed we should still save first slice,
|
||||||
|
// if header data was changed since loading from cache.
|
||||||
|
// Otherwise in destructor we won't be able to unload header.
|
||||||
|
if (!isGoodHeader()
|
||||||
|
|| (purgeSlice > 0)
|
||||||
|
|| (!(_header.flags & Flag::ChangedSinceCache))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
if (noNeedToSaveToCache) {
|
||||||
_data[purgeSlice] = Slice();
|
_data[purgeSlice] = Slice();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue