← Back to Pull requests

feat import mode #1374

Closed
unknown closed this pull request without merging on Sep 25, 2026 08:37 UTC
View on GitHub
unknown unknown commented on Sep 17, 2026 16:31 UTC
Author

<!-- All contributors please complete these sections, including maintainers -->

Adds an IMPORT mode to the Schema Registry so schemas can be migrated from another registry keeping their original schema IDs and version numbers.

Key features

1. IMPORT mode, global or per subject.
2. Schema identity is preserved. POST /subjects/{subject}/versions accepts id and version in the body
3. New endpoints:

  • PUT /mode,

  • PUT /mode/{subject},

  • DELETE /mode/{subject},
  • curl -X PUT  -d '{"mode": "IMPORT"}' localhost:8081/mode/my-subject
    
    curl -X POST -d '{"schema": "...", "id": 1001, "version": 5}' \
      localhost:8081/subjects/my-subject/versions      # -> {"id":1001}
    
    curl -X DELETE localhost:8081/mode/my-subject         # -> {"mode":"READWRITE"}
    
    GET /mode/{subject} also works with ?defaultToGlobal=true/false
    

    Subject has its own override. If there is no override, then global mode serves.
    But for a non-existent subject, with ?defaultToGlobal=true returns global mode

    Examples

    curl -s "$SR/mode/no-such-subject"                        # 404 {"error_code":40401,"message":"Subject 'no-such-subject' not found."}
    curl -s "$SR/mode/no-such-subject?defaultToGlobal=false"  # 404  (identical to omitting it)
    curl -s "$SR/mode/no-such-subject?defaultToGlobal=true"   # 200 {"mode":"READWRITE"}
    
    curl -s -X POST -H "$CT" -d '{"schema":"{\"type\":\"string\"}"}' $SR/subjects/exists/versions
    curl -s "$SR/mode/exists"                                 # 200 {"mode":"READWRITE"}   <- global fallback, no flag needed
    curl -s "$SR/mode/exists?defaultToGlobal=true"            # 200 {"mode":"READWRITE"}   <- same
    
    curl -s -X PUT -H "$CT" -d '{"mode":"IMPORT"}' $SR/mode/imported
    curl -s "$SR/mode/imported?defaultToGlobal=true"          # 200 {"mode":"IMPORT"}
    

    4. Guardrails, so a bad import fails loudly rather than corrupting quietly. An ID is bound to its content permanently; a version slot can't be repointed; and the
    presence of an id is what selects the mode — supplying one outside IMPORT, or omitting one inside it, is rejected rather than reinterpreted. Ten documented
    rejections across 42202, 42204, 42205, 42207.

    Ex.

    POST {"schema": A, "id": 1001, "version": 1}   -> 200 {"id":1001}
    POST {"schema": B, "id": 1001, "version": 2}   -> 422 .. Overwrite new schema with id 128200200 is not permitted.
    
    POST {"schema": A, "id": 100, "version": 5}    -> 200
    POST {"schema": B, "id": 200, "version": 5}    -> 422 ... version 5 is already registered with schema id ..
    
    POST {"schema": A, "id": 1001}     # subject is in READWRITE
      -> 422 {"error_code":42205,"message":"Subject 'demo-noimport' is not in IMPORT mode."}
    
    POST {"schema": A}                 # subject is in IMPORT
    -> 422 {"error_code":42205,"message":"Subject 'demo-noid' is in IMPORT mode,
              a schema id is required to register."}
     IMPORT deliberately skips compatibility checks.
    

    For all unreachable versions, 422 ... The specified version '0' is not valid.

    5. Two operator flags.

    mode_mutability (default true) — a cluster-wide operator switch. Set false and every mode change is refused, so IMPORT can never be entered at runtime. Config-only, requires a restart.

    allow_duplicate_schema_ids (default true) false refuses an import whose content already has a different ID, keeping IDs one-to-one with content

    6. Modes are MODE records in _schemas topic, so they survive a restart.
    subject: None means the global mode.

    7. Compatibility

    id/version on POST /subjects/{subject}/versions were previously parsed and ignored; they're now honoured or rejected.

    8. Testing

    1218 unit tests & 34 integration tests

    Updated docs
    https://mbasani-feat-import-mode.karapace.pages.dev/docs/import-mode

    --------

    Local tests

    IMPORT mode demo run 20260918-140209
      kafka    : localhost:9092
      registry : http://localhost:8081
      topic    : _schemas_import_demo_20260918-140209  (fresh, so global IMPORT starts empty)
      logs     : ./.runs/20260918-140209
    
    ── global mode
       11 checks passed
    ── scenarios
       100 checks passed
    ── restart replay (seeding)
       seeded
    ── restart replay
       7 checks passed
    ── mode_mutability=false
       8 checks passed
    ── allow_duplicate_schema_ids=false
       9 checks passed
    
    ================================================================
    ### IMPORT mode verified against a live registry
    
    | Phase | Checks | Result |
    | --- | --- | --- |
    | global mode | 11 | pass |
    | scenarios | 100 | pass |
    | restart replay | 7 | pass |
    | mode_mutability=false | 8 | pass |
    | allow_duplicate_schema_ids=false | 9 | pass |
    
    Total: 135 checks. Kafka localhost:9092, registry on a fresh topic per run.
    
    Covered: id and version preserved on import; idempotent replay; an id refused when
    already bound to other content; the same content allowed under a second id; a version
    slot refused when taken; importing over a populated subject with force; several
    pre-existing versions; resuming a part done batch; hard delete dropping the mode;
    explicit id refused outside IMPORT and required inside it; id and version range checks;
    compatibility skipped inside and enforced again after; soft deleted versions; ids shared
    across subjects; JSON Schema and Protobuf including normalize; references; global IMPORT
    and subject level override; MODE records replayed from Kafka after a restart;
    mode_mutability=false refusing every mode change; and
    allow_duplicate_schema_ids=false refusing one schema under a second id.
    

    <!-- Provide a small sentence that summarizes the change. -->

    <!-- Provide the issue number below if it exists. -->
    References: #xxxxx

    Why this way

    <!-- Provide a small explanation on why this is the approach you took for solving this problem. -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: muralibasani Review duration: 11045m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1374"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%