|
@@ -130,12 +130,31 @@ bool MemoryStore::alterCollection(const std::string& name, const CollectionOptio
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> collLock(it->second->mutex);
|
|
std::unique_lock<std::shared_mutex> collLock(it->second->mutex);
|
|
|
|
|
|
|
|
- // Update collection options
|
|
|
|
|
|
|
+ // Check if maxVersions is being set/reduced - need to prune existing history
|
|
|
|
|
+ uint32_t oldMaxVersions = it->second->options.maxVersions;
|
|
|
|
|
+ uint32_t newMaxVersions = options.maxVersions;
|
|
|
|
|
+
|
|
|
|
|
+ // Update collection options first
|
|
|
it->second->options = options;
|
|
it->second->options = options;
|
|
|
it->second->updatedAt = currentTimeMs();
|
|
it->second->updatedAt = currentTimeMs();
|
|
|
|
|
|
|
|
- spdlog::debug("Altered collection '{}': pinned={}, encrypted={}",
|
|
|
|
|
- name, options.pinned, options.encrypted);
|
|
|
|
|
|
|
+ // If maxVersions is now limited (and was unlimited or higher before), prune all history
|
|
|
|
|
+ if (newMaxVersions > 0 && (oldMaxVersions == 0 || newMaxVersions < oldMaxVersions)) {
|
|
|
|
|
+ uint64_t prunedVersions = 0;
|
|
|
|
|
+ for (auto& [docId, history] : it->second->versionHistory) {
|
|
|
|
|
+ while (history.size() > newMaxVersions) {
|
|
|
|
|
+ history.pop_front();
|
|
|
|
|
+ ++prunedVersions;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (prunedVersions > 0) {
|
|
|
|
|
+ spdlog::info("Pruned {} version history entries from collection '{}' (maxVersions: {} -> {})",
|
|
|
|
|
+ prunedVersions, name, oldMaxVersions, newMaxVersions);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ spdlog::debug("Altered collection '{}': pinned={}, encrypted={}, maxVersions={}",
|
|
|
|
|
+ name, options.pinned, options.encrypted, options.maxVersions);
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|