Laidieni

  • v1.7.1 — Replication content-loss fix

    Szontágh Ferenc 7 mēneši atpakaļ | 236 revīzijas atzarā main kopš šī laidiena

    Critical replication fix

    Replication was structurally working but silently dropping all user content on every replicated document. Structure survived (_id, _version, timestamps), but the actual data fields were lost. Pre-existing bug from 2026-02-05, unrelated to v1.7.0's eviction work — surfaced by the replication sanity load test added in v1.7.0's follow-up (tests/load_test/run_replication_test.sh).

    If you have replication.enabled: false (the default), you're unaffected. If you've turned replication on in any deployment, upgrade to v1.7.1.

    The bug

    Side Code Behavior
    Leader database_service.cpp:515 entry.set_data(doc->data.dump()) Broadcasts only the user's JSON payload
    Follower database_service.cpp:612 Document doc = Document::fromJson(json) Expects full envelope (id, collection, data, version, timestamps)

    Document::fromJson reads j.value("data", {}). When the follower saw {seq: 123, content: "hello"} it looked for a "data" field inside that object, found nothing, and produced a Document with empty data. The replicated doc had the right ID and version metadata but zero user content.

    The fix

    One-line leader-side change: send doc->toJson() instead of doc->data.dump(). The follower's existing Document::fromJson() call then works correctly.

    -     if (doc) entry.set_data(doc->data.dump());
    +     if (doc) entry.set_data(doc->toJson().dump());
    

    Follower code unchanged. The ReplicationEntry proto fields (document_id, collection, document_version) stay — they're now slightly redundant with what's in the envelope but still serve as out-of-band routing breadcrumbs.

    Test evidence

    Using tests/load_test/run_replication_test.sh:

    Before fix (v1.7.0):

    Inserted on leader:     1000
    Seen on follower:       1000
    Content matches:        0
    Content mismatches:     1000
    Verdict: FAIL
    

    After fix (v1.7.1):

    Inserted on leader:     1000/1000
    Seen on follower:       1000
    Content matches:        1000
    Content mismatches:     0
    Catch-up time:          366ms
    Verdict: PASS — all 1000 docs replicated in 366ms, zero corruption
    

    Blame

    git blame puts the bug at commit a96c168 on 2026-02-05, ~2.5 months before this release. It has been silently broken since then. Nobody noticed because replication has been opt-in and most deployments run single-node.

    Backward compatibility

    • Wire format change: ReplicationEntry.data payload format changed from "raw user JSON" to "full Document envelope JSON". A v1.7.0 follower talking to a v1.7.1 leader won't understand the new format (will try to parse envelope as user data). Upgrade leaders and followers together.
    • Internal data format, proto schema, disk format, client API: all unchanged.
    • Consumer projects: no code changes required.

    Packages

    Four .deb packages published to repository.smartbotics.ai (suite: trixie):

    • smartbotic-database_1.7.1-1_amd64.deb
    • libsmartbotic-db-client_1.7.1-1_amd64.deb
    • libsmartbotic-db-client-dev_1.7.1-1_amd64.deb
    • smartbotic-db-cli_1.7.1-1_amd64.deb