Class BulkWriteReporting
Turns a bulk write's outcome into the log line it deserves, and answers the only two questions a caller actually has about one.
public static class BulkWriteReporting
- Inheritance
-
BulkWriteReporting
- Inherited Members
Remarks
A batched write reports three counts rather than a boolean — see BulkWriteResult — and the two ways rows go missing want opposite treatment. A superseded row is the database telling us it already holds something newer, which is routine under concurrency and not worth a warning on every periodic save. A filtered row is the service telling us it could not act on what we asked for at all, which is never routine and was, before this, entirely silent.
Centralised so that every call site classifies a discrepancy the same way. Spread across twenty hand-written checks, the distinction would survive in some and quietly rot in the rest — which is how it came to be missing in the first place.
Methods
MayClearDirtyMarks(DatabaseResult<BulkWriteResult>)
Whether a best-effort write lets its caller clear the dirty marks of the rows it carried. Pure.
public static bool MayClearDirtyMarks(DatabaseResult<BulkWriteResult> result)
Parameters
resultDatabaseResult<BulkWriteResult>The write's outcome.
Returns
- bool
True when every row the batch carried was attempted.
Remarks
Only a write that succeeded AND attempted every row. A filtered row never reached the database — an unresolved character or template, a key the batch named twice, or a row the ownership gate refused because this server no longer holds its character's claim (Unowned, which is counted as filtered) — so retiring its mark would retire a value that was never stored, and the periodic save has no retry of its own to notice. A superseded row is the opposite and safe: the database refused it because it already holds something newer.
A failed write — including a refusal of the whole batch as Forbidden — clears nothing.
ReportAsync(string, string, DatabaseResult<BulkWriteResult>, string)
Reports a best-effort bulk write: one where the database legitimately holding newer data is an acceptable outcome.
public static Task<bool> ReportAsync(string tag, string operation, DatabaseResult<BulkWriteResult> result, string context = null)
Parameters
tagstringLog source.
operationstringWhat was being written, for the log line.
resultDatabaseResult<BulkWriteResult>The write's outcome.
contextstringOptional extra identification, such as a character ID.
Returns
Remarks
The right call for periodic and despawn saves. A superseded row there means another writer got to it first with a fresher snapshot, so the stored value is the better of the two and there is nothing to repair.
RequireCompleteAsync(string, string, DatabaseResult<BulkWriteResult>, string)
Reports a bulk write that must land in full, failing the caller if it did not.
public static Task<bool> RequireCompleteAsync(string tag, string operation, DatabaseResult<BulkWriteResult> result, string context = null)
Parameters
tagstringLog source.
operationstringWhat was being written, for the log line.
resultDatabaseResult<BulkWriteResult>The write's outcome.
contextstringOptional extra identification, such as a character ID.
Returns
Remarks
The right call for rows that are being created for the first time — a new character's starting inventory, factions and abilities. Nothing newer can exist to supersede them, so a shortfall is not a race: it means rows were dropped, and continuing would hand the player a character that is quietly missing part of itself.