Skip to content

Document and validate MatrixOne enable-sacrificing-freshness for pooled Memoria deployments #329

Open

Description

@loveRhythm1990

Problem

Memoria's multi-database routing initializes a user's schema through one SQL connection pool and then serves writes and reads through another pool. With multiple MatrixOne CNs, these connections can also terminate on different CNs.

MatrixOne's enable-sacrificing-freshness setting changes the visibility guarantees this architecture can rely on. Memoria should document and validate the required consistency configuration, including its latency and throughput tradeoffs.

Scope decision: do not change MatrixOne engine code for this issue. This tracks Memoria's deployment requirements, documentation, and controlled validation. The observations below do not by themselves establish a MatrixOne implementation bug.

What the parameter does

Source audit: MatrixOne v4.2.5, commit 1a44f3db3056e32975fde86ca0ab69a094996a3f.

Setting Meaning
enable-sacrificing-freshness = 1 Allows a transaction to use the CN's available logtail progress instead of always waiting for a fresh snapshot. This reduces transaction-start waiting but permits temporarily stale reads.
enable-sacrificing-freshness = -1 Disables this freshness relaxation. It is the candidate configuration to validate when fresh reads across independent sessions/CNs are required.
enable-sacrificing-freshness = 0 Automatic configuration, not an explicit disable. In the audited version, both transaction-mode branches resolve this option to enabled.

The relaxed mode preserves a session's own last-commit timestamp as a lower bound for later transactions in that session. A different pooled connection does not automatically inherit that bound.

enable-cn-based-consistency = 1 extends the commit-timestamp bound across transactions on the same CN. It does not, by itself, provide a cluster-wide cross-CN read-after-write guarantee.

Source references:

These details must be checked again for other MatrixOne versions.

Why Memoria is affected

In DbRouter::user_store():

  1. user_init_pool runs the user-schema migration.
  2. Successful initialization is cached.
  3. A routed store backed by global_user_pool is returned for business queries.

Awaiting step 1 does not transfer its session timestamp to step 3. The same concern applies when an API client immediately reads a successfully written memory through a later HTTP request using a different SQL connection.

Synthetic diagnostics observed:

  • Successful creation of mem_memories, followed by a PREPARE/SELECT on another connection and another CN reporting that the table did not exist. The database was correct and the table existed afterward. The API returned 500.
  • A successful memory write followed by an immediate point read that did not find the record. Later reads found the same active record, with no duplicate. One case has direct SQL zero-row evidence; another is inferred from the API call chain and client control flow because short SQL statements were aggregated in history.

A local protocol fault-injection test also demonstrates that the current router can complete initialization while a query session that has not observed the DDL still fails. This validates the missing handling in Memoria; it does not independently prove the engine's internal cause.

Effect and tradeoffs

  • Correctness/availability: consumers expecting a newly initialized schema or a committed memory to be immediately visible through any connection can receive transient errors or empty results under relaxed freshness.
  • Performance: disabling freshness relaxation can increase transaction-start latency while waiting for logtail progress. Tail latency and throughput must be measured rather than assuming the stricter configuration is free.
  • Deployment scope: this is a CN transaction setting, not a per-request Memoria flag. Changing a shared CN can affect other workloads.
  • Retries: read retries or bounded visibility waits may be useful application safeguards, but should be designed explicitly. Do not blindly replay non-idempotent writes or claim that atomic idempotency also guarantees immediate visibility.

Proposed work

  • Document Memoria's required schema-visibility and read-after-write guarantees for pooled, multi-CN deployments.
  • Document 1 / 0 / -1, the session-only guarantee, and the limits of CN-based consistency.
  • Prepare any QA configuration change through the normal GitOps PR/review process; do not apply an ad-hoc cluster change.
  • Run a controlled comparison with enable-sacrificing-freshness = -1, covering new-user initialization, writes on one connection/CN followed by reads on another, and immediate retrieval visibility.
  • Compare failure/empty-read rates, P50/P95/P99, throughput, and transaction/logtail waiting under comparable background load.
  • Evaluate whether Memoria also needs bounded, safe visibility handling before publishing schema readiness or exposing successful writes to consumers that require immediate readability.

Keep MatrixOne engine modifications out of scope for now. If failures persist with freshness relaxation disabled and an appropriately fresh read snapshot, collect a separate minimal synthetic reproduction before classifying them as engine defects.

No credentials, infrastructure identifiers, production data, or external evaluation content are included in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions