microsoft/garnet · error · TsavoriteException
Consistent read context does not allow reads from address!
Error message
Consistent read context does not allow reads from address!
What it means
ConsistentReadContext provides sequential-read consistency by tracking read positions. ReadAtAddress reads a record at a specific logical address, which bypasses the consistent-read cursor/sequence tracking that guarantees you see a monotonic, coherent view of the store. Allowing address-based reads would break the consistency invariant, so both overloads throw.
Source
Thrown at libs/storage/Tsavorite/cs/src/core/ClientSession/ConsistentReadContext.cs:112
TOutput output = default;
return (Read(key, ref input, ref output, ref readOptions, userContext), output);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Status Read(TKey key, ref TInput input, ref TOutput output, ref ReadOptions readOptions, out RecordMetadata recordMetadata, TContext userContext = default)
{
var hash = readOptions.KeyHash ?? GetKeyHash(key);
Session.functions.PreSingleKeyConsistentRead(hash);
var status = BasicContext.Read(key, ref input, ref output, ref readOptions, out recordMetadata, userContext);
Session.functions.PostSingleKeyConsistentReadCallback();
return status;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Status ReadAtAddress(long address, ref TInput input, ref TOutput output, ref ReadOptions readOptions, out RecordMetadata recordMetadata, TContext userContext = default)
=> throw new TsavoriteException("Consistent read context does not allow reads from address!");
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Status ReadAtAddress(long address, TKey key, ref TInput input, ref TOutput output, ref ReadOptions readOptions, out RecordMetadata recordMetadata, TContext userContext = default)
=> throw new TsavoriteException("Consistent read context does not allow reads from address!");
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReadWithPrefetch<TBatch>(ref TBatch batch, TContext userContext = default)
where TBatch : IReadArgBatch<TKey, TInput, TOutput>
#if NET9_0_OR_GREATER
, allows ref struct
#endif
{
do
{
Thread.Yield();
Session.functions.PreBatchKeyConsistentReadCallback(batch.Parameters);View on GitHub (pinned to 951b0fc683)
Solutions
- For address-based reads, use session.BasicContext.ReadAtAddress instead of ConsistentReadContext.ReadAtAddress.
- If consistent reads are required, do not use ReadAtAddress — use key-based Read which respects the consistency cursor.
- Create a separate session (without enableConsistentRead) for low-level address-based access.
Example fix
// before var status = session.ConsistentReadContext.ReadAtAddress(addr, ref input, ref output, ref opts, out var meta); // after var status = session.BasicContext.ReadAtAddress(addr, ref input, ref output, ref opts, out var meta);
Defensive patterns
Strategy: validation
Validate before calling
if (session.ConsistentReadContext is not null) throw new InvalidOperationException("Use BasicContext.ReadAtAddress for address-based reads; ConsistentReadContext disallows them."); Type guard
static bool CanReadAtAddress(ClientSession s) => !s.EnableConsistentRead;
Prevention
- Do not enable consistent reads on sessions that need address-based access.
- Use BasicContext.ReadAtAddress for low-level record reads.
- Create a dedicated non-consistent session for recovery/replay address reads.
When it happens
Trigger: Calling consistentContext.ReadAtAddress(address, ref input, ...) — the single-address overload — on a ConsistentReadContext obtained from a session with enableConsistentRead=true.
Common situations: Enabling consistent reads on a session but then attempting address-based reads (e.g. for recovery, replay, or low-level record access); porting BasicContext.ReadAtAddress code to a consistent-read session.
Related errors
- Transactional method call when BeginTransactional has not be
- BeginTransactional cannot be called twice (call EndTransacti
- Transactional consistent read context does not allow reads f
- TsavoriteLogAllocator does not support VerifyRecordFromDiskC
- TsavoriteLogAllocator Scan methods should not be used
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/e4807184738a6927.
Report an issue: GitHub.