microsoft/garnet · error · TsavoriteException

Consistent read context does not reset ResetModified!

Error message

Consistent read context does not reset ResetModified!

What it means

ResetModified marks a key as no longer modified within a transactional context. ConsistentReadContext does not support this because it is a read-only snapshot view — it has no transactional write state to reset. The method is implemented as an unconditional throw to satisfy the ITsavoriteContext interface contract while making the limitation explicit. Note the message text 'does not reset ResetModified' is slightly awkward but intentional.

Source

Thrown at libs/storage/Tsavorite/cs/src/core/ClientSession/ConsistentReadContext.cs:283

        /// <inheritdoc/>
        public Status RMW(TKey key, ref TInput input, TContext userContext = default)
            => throw new TsavoriteException("Consistent read context does not allow writes!");

        /// <inheritdoc/>
        public Status RMW(TKey key, ref TInput input, ref RMWOptions rmwOptions, TContext userContext = default)
            => throw new TsavoriteException("Consistent read context does not allow writes!");

        /// <inheritdoc/>
        public Status Delete(TKey key, TContext userContext = default)
            => throw new TsavoriteException("Consistent read context does not allow writes!");

        /// <inheritdoc/>
        public Status Delete(TKey key, ref DeleteOptions deleteOptions, TContext userContext = default)
            => throw new TsavoriteException("Consistent read context does not allow writes!");

        /// <inheritdoc/>
        public void ResetModified(TKey key)
            => throw new TsavoriteException("Consistent read context does not reset ResetModified!");

        /// <inheritdoc/>
        public void Refresh()
            => throw new TsavoriteException("Consistent read context does not reset Refresh!");
        #endregion
    }
}

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Call ResetModified on the TransactionalContext (session.TransactionalContext) or BasicContext, not on ConsistentReadContext.
  2. If using TransactionalConsistentReadContext for reads inside a transaction, note that ResetModified is also rejected there — use the non-consistent TransactionalContext for transactional write state management.

Example fix

// before (throws)
session.ConsistentReadContext.ResetModified(key);

// after
session.TransactionalContext.ResetModified(key);
Defensive patterns

Strategy: validation

Validate before calling

// Call ResetModified on a context that supports transactional write state
// ConsistentReadContext does not support ResetModified
session.TransactionalContext.ResetModified(key);

Prevention

When it happens

Trigger: Calling ResetModified(TKey key) on the ConsistentReadContext struct. This can happen when transactional code that calls ResetModified is refactored to use the consistent-read context, or when an ITsavoriteContext-typed variable that happens to hold a ConsistentReadContext is used.

Common situations: Transaction management code that tracks modified keys and calls ResetModified after processing; mixing transactional and consistent-read patterns in the same session lifecycle.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/0a595772ddeb75e1. Report an issue: GitHub.