|
@@ -346,12 +346,13 @@ std::string MemoryStore::insert(const std::string& collection, Document doc) {
|
|
|
// v1.7.0 T6 quiesce: mark this doc as having an in-flight write so a
|
|
// v1.7.0 T6 quiesce: mark this doc as having an in-flight write so a
|
|
|
// concurrent evictOneChunk() skips it.
|
|
// concurrent evictOneChunk() skips it.
|
|
|
InFlightWriteGuard inFlight(*coll, doc.id);
|
|
InFlightWriteGuard inFlight(*coll, doc.id);
|
|
|
|
|
+ reloadIfEvicted(collection, doc.id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
|
// Check if ID already exists
|
|
// Check if ID already exists
|
|
|
if (coll->documents.find(doc.id) != coll->documents.end()) {
|
|
if (coll->documents.find(doc.id) != coll->documents.end()) {
|
|
|
- throw std::runtime_error("Document with ID '" + doc.id + "' already exists");
|
|
|
|
|
|
|
+ throw DuplicateDocumentId(collection, doc.id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Extract vector before storing document (strips _vector from JSON data)
|
|
// Extract vector before storing document (strips _vector from JSON data)
|
|
@@ -509,6 +510,7 @@ bool MemoryStore::update(const std::string& collection, const std::string& id, c
|
|
|
|
|
|
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
|
|
|
+ reloadIfEvicted(collection, id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -681,6 +683,7 @@ std::string MemoryStore::upsert(const std::string& collection, Document doc) {
|
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock. Closes the
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock. Closes the
|
|
|
// find-existing-then-write-new-version race with concurrent eviction.
|
|
// find-existing-then-write-new-version race with concurrent eviction.
|
|
|
InFlightWriteGuard inFlight(*coll, doc.id);
|
|
InFlightWriteGuard inFlight(*coll, doc.id);
|
|
|
|
|
+ reloadIfEvicted(collection, doc.id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -851,6 +854,7 @@ bool MemoryStore::remove(const std::string& collection, const std::string& id,
|
|
|
|
|
|
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
|
|
|
+ reloadIfEvicted(collection, id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -1199,6 +1203,7 @@ bool MemoryStore::updateIfVersion(const std::string& collection, const std::stri
|
|
|
|
|
|
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
|
|
|
+ reloadIfEvicted(collection, id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -1488,6 +1493,7 @@ uint64_t MemoryStore::patchDocument(const std::string& collection, const std::st
|
|
|
|
|
|
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
// v1.7.0 T6 quiesce: mark before taking the write lock.
|
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
InFlightWriteGuard inFlight(*coll, id);
|
|
|
|
|
+ reloadIfEvicted(collection, id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -1865,6 +1871,7 @@ uint64_t MemoryStore::count(const std::string& collection, const std::vector<Fil
|
|
|
|
|
|
|
|
bool MemoryStore::setAdd(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
bool MemoryStore::setAdd(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
|
|
|
+ reloadIfEvicted(collection, setId); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -1977,6 +1984,7 @@ bool MemoryStore::setAdd(const std::string& collection, const std::string& setId
|
|
|
|
|
|
|
|
bool MemoryStore::setRemove(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
bool MemoryStore::setRemove(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
|
|
|
+ reloadIfEvicted(collection, setId); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -2950,6 +2958,7 @@ std::optional<DocumentVersion> MemoryStore::getDocumentAtVersion(
|
|
|
uint64_t MemoryStore::restoreToVersion(const std::string& collection, const std::string& id,
|
|
uint64_t MemoryStore::restoreToVersion(const std::string& collection, const std::string& id,
|
|
|
uint64_t version, const std::string& actor) {
|
|
uint64_t version, const std::string& actor) {
|
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
CollectionData* coll = getOrCreateCollection(collection);
|
|
|
|
|
+ reloadIfEvicted(collection, id); // v2.12.1
|
|
|
|
|
|
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
std::unique_lock<std::shared_mutex> lock(coll->mutex);
|
|
|
|
|
|
|
@@ -3427,6 +3436,20 @@ void MemoryStore::emitEvictionBurst(uint64_t docs, uint64_t bytesFreed) {
|
|
|
memoryPressureToString(pressure()));
|
|
memoryPressureToString(pressure()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void MemoryStore::reloadIfEvicted(const std::string& collection, const std::string& id) {
|
|
|
|
|
+ if (id.empty() || !getEvictedStub(collection, id)) return; // the common case: resident
|
|
|
|
|
+ if (loadEvictedDocument(collection, id)) return;
|
|
|
|
|
+ // The load failed. If the stub is gone, someone else reloaded (or deleted)
|
|
|
|
|
+ // it meanwhile and the write may proceed against the real state. If the
|
|
|
|
|
+ // stub is still there, the document exists and could not be read back:
|
|
|
|
|
+ // refuse rather than let the write treat it as absent.
|
|
|
|
|
+ if (getEvictedStub(collection, id)) {
|
|
|
|
|
+ throw std::runtime_error("document '" + collection + "/" + id +
|
|
|
|
|
+ "' is evicted from memory and could not be reloaded; "
|
|
|
|
|
+ "refusing the write rather than treating it as absent");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void MemoryStore::emitPersist(const std::string& collection, const std::string& id,
|
|
void MemoryStore::emitPersist(const std::string& collection, const std::string& id,
|
|
|
const std::optional<Document>& doc, EventType eventType,
|
|
const std::optional<Document>& doc, EventType eventType,
|
|
|
const std::optional<std::string>& actor) {
|
|
const std::optional<std::string>& actor) {
|