{"record":{"id":"ff9f8fc395edbdfb","repo":"microsoft/garnet","slug":"transactional-consistent-read-context-does-not-res","errorCode":null,"errorMessage":"Transactional consistent read context does not reset ResetModified!","messagePattern":"Transactional consistent read context does not reset ResetModified!","errorType":"exception","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/ClientSession/TransactionalConsistentReadContext.cs","lineNumber":384,"sourceCode":"        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public Status RMW(TKey key, ref TInput input, ref RMWOptions rmwOptions, TContext userContext = default)\n            => throw new TsavoriteException(\"Transactional consistent read context does not allow writes!\");\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public Status Delete(TKey key, TContext userContext = default)\n            => throw new TsavoriteException(\"Transactional consistent read context does not allow writes!\");\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public Status Delete(TKey key, ref DeleteOptions deleteOptions, TContext userContext = default)\n            => throw new TsavoriteException(\"Transactional consistent read context does not allow writes!\");\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public void ResetModified(TKey key)\n            => throw new TsavoriteException(\"Transactional consistent read context does not reset ResetModified!\");\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        internal bool IsModified(TKey key)\n            => throw new TsavoriteException(\"Transactional consistent read context does not allow IsModified!\");\n\n        /// <inheritdoc/>\n        public void Refresh()\n            => throw new TsavoriteException(\"Transactional consistent read context does not Refresh!\");\n\n        #endregion ITsavoriteContext\n    }\n}","sourceCodeStart":366,"sourceCodeEnd":397,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/ClientSession/TransactionalConsistentReadContext.cs#L366-L397","documentation":"The Delete overload with DeleteOptions (line 379) and the ResetModified method (line 384) both reject calls on the TransactionalConsistentReadContext. This entry maps to ResetModified (message 'does not reset ResetModified!'): because the read-only context never tracks per-key modifications, clearing the modified flag is meaningless and throws. ResetModified is only supported on the write-capable contexts.","triggerScenarios":"Calling tcrContext.ResetModified(TKey key) (and, relatedly, tcrContext.Delete(key, ref DeleteOptions)) on the transactional consistent read context, typically to clear a modification marker after handling a record.","commonSituations":"Code that interplays with UnsafeContext.IsModified/ResetModified semantics is copied into a transactional consistent-read scope; the read-only context has no modified-flag state to reset.","solutions":["Use session.TransactionalUnsafeContext for ResetModified (implemented at TransactionalUnsafeContext.cs:498) and for DeleteOptions Delete (TransactionalUnsafeContext.cs:484).","Use a non-transactional write context if isolation is not needed.","Do not call modification-tracking methods on read-only consistent read contexts."],"exampleFix":"// before\nvar tcr = session.TransactionalConsistentReadContext;\ntcr.ResetModified(key); // throws\n\n// after\nvar luc = session.TransactionalUnsafeContext;\nluc.BeginUnsafe();\ntry { luc.ResetModified(key); }\nfinally { luc.EndUnsafe(); }","handlingStrategy":"validation","validationCode":"// Modification tracking belongs on a write-capable context.\nvar w = session.TransactionalUnsafeContext;\nw.BeginUnsafe();\ntry { w.ResetModified(key); }\nfinally { w.EndUnsafe(); }\n// (DeleteOptions Delete likewise: w.Delete(key, ref deleteOptions).)","typeGuard":"static bool IsReadOnlyContext<TCtx>() => typeof(TCtx).Name.Contains(\"ConsistentReadContext\");\n// Assert before ResetModified/Delete(deleteOptions) calls.","tryCatchPattern":null,"preventionTips":["ResetModified and Delete(DeleteOptions) require a write context.","Do not call modification-tracking methods on read-only contexts.","Use TransactionalUnsafeContext for these operations."],"tags":["tsavorite","transaction","read-only-context","resetmodified","csharp"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}