Skip to content

Amending commits on a primary breaks remote based replication #6627

@timsehn

Description

@timsehn

Repro:

  1. Make a primary.
$ mkdir test_commit_amend_replication_primary
$ dolt init --fun 
Successfully initialized dolt data repository.
  1. Make a new DoltHub database and push to it
$ dolt remote add origin timsehn/test_commit_amend_replication 
$ dolt push
Uploaded 374 B of 374 B @ 3.02 kB/s.
  1. Set Up replication
$ dolt sql -q "set @@persist.dolt_replicate_all_heads = 1"
$ dolt sql -q "set @@persist.dolt_replicate_to_remote = 'origin'"
  1. Insert some data
$ dolt sql -q "create table foo (pk int primary key, c1 int)"
$ dolt commit -Am "Created Table"
commit en50plogjefuoo41ne4jfmcohhotfbjg (HEAD -> main) 
Author: timsehn <[email protected]>
Date:  Thu Sep 07 12:29:39 -0700 2023

        Created Table

$ dolt sql -q "insert into foo values (0,0)"
Query OK, 1 row affected (0.00 sec)
$ dolt commit -Am "inserted 0,0"                             
commit 9mhqkvo538f107bail7rjs3russrjkmk (HEAD -> main) 
Author: timsehn <[email protected]>
Date:  Thu Sep 07 12:34:34 -0700 2023

        inserted 0,0

  1. Make a read replica
$ dolt clone timsehn/test_commit_amend_replication 
$ mv test_commit_amend_replication test_commit_amend_replication_secondary
$ dolt sql -q "set @@persist.dolt_replicate_heads = 'main'"       
$ dolt sql -q "set @@persist.dolt_read_replica_remote = 'origin'"
$ dolt sql -q "select * from foo" 
+----+----+
| pk | c1 |
+----+----+
| 0  | 0  |
+----+----+
  1. Amend a commit on the primary
$ dolt commit --amend -m "inserted 0,0. amended"
commit ac5h4ugp24oi9sar10l13oo039cnkr41 (HEAD -> main) 
Author: timsehn <[email protected]>
Date:  Thu Sep 07 12:35:36 -0700 2023

        inserted 0,0. amended

  1. Read replication breaks
$ dolt sql -q "select * from foo" 
error on line 1 for query select * from foo: replication error: dataset head is not ancestor of commit
  1. dolt pull -f does not fix it but should. Can't fetch and reset main to the new commit because dolt branch gets in a bad state.
$ dolt pull -f origin main
fetch failed; dataset head is not ancestor of commit
$ dolt fetch 
$ dolt branch -va
error: failed to read remote branches from db

We should make force pull work in this case. We should also make a new replication setting called dolt_read_replica_force_pull and have read replication do a force pull instead of a normal pull if that variable is on.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions