Skip to content

Commit

Permalink
Merge pull request #7379 from dolthub/zachmu/replicate-tags
Browse files Browse the repository at this point in the history
[no-release-notes] simplified warn on error behavior
  • Loading branch information
zachmu authored Jan 20, 2024
2 parents b981bef + da1bb8d commit dee5e41
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
4 changes: 0 additions & 4 deletions go/libraries/doltcore/env/actions/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func CreateTagOnDB(ctx context.Context, ddb *doltdb.DoltDB, tagName, startPoint
return ddb.NewTagAtCommit(ctx, tagRef, cm, meta)
}

func DeleteTags(ctx context.Context, dEnv *env.DoltEnv, tagNames ...string) error {
return DeleteTagsOnDB(ctx, dEnv.DoltDB, tagNames...)
}

func DeleteTagsOnDB(ctx context.Context, ddb *doltdb.DoltDB, tagNames ...string) error {
for _, tn := range tagNames {
dref := ref.NewTagRef(tn)
Expand Down
31 changes: 6 additions & 25 deletions go/libraries/doltcore/sqle/read_replica_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,13 @@ func (rrd ReadReplicaDatabase) PullFromRemote(ctx *sql.Context) error {
}

err := rrd.srcDB.Rebase(ctx)
if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}

remoteRefs, localRefs, toDelete, err := getReplicationRefs(ctx, rrd)
if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}

switch {
Expand Down Expand Up @@ -194,39 +188,26 @@ func (rrd ReadReplicaDatabase) PullFromRemote(ctx *sql.Context) error {
}

err := fmt.Errorf("unable to find %q on %q; branch not found", branch, rrd.remote.Name)
if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}
}

remoteRefs = prunedRefs
_, err = pullBranches(ctx, rrd, remoteRefs, localRefs, behavior)

if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}

case allHeads == int8(1):
_, err = pullBranches(ctx, rrd, remoteRefs, localRefs, behavior)
if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}

err = deleteBranches(ctx, rrd, toDelete)
if err != nil && !dsess.IgnoreReplicationErrors() {
if err != nil {
return err
} else if err != nil {
dsess.WarnReplicationError(ctx, err)
return nil
}
default:
ctx.GetLogger().Warnf("must set either @@dolt_replicate_heads or @@dolt_replicate_all_heads, replication disabled")
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/read_replica_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestLimiter(t *testing.T) {
}()
}

// TODO: This is some janky to reduce flakiness.
// TODO: This is some jank to reduce flakiness.
sema.Acquire(context.Background(), 16)
time.Sleep(10 * time.Millisecond)
for i := 0; i < 128; i++ {
Expand Down
10 changes: 3 additions & 7 deletions go/libraries/doltcore/sqle/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/sirupsen/logrus"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
Expand Down Expand Up @@ -104,13 +103,10 @@ func newReplicaDatabase(ctx context.Context, name string, remoteName string, dEn

rrd, err := NewReadReplicaDatabase(ctx, db, remoteName, dEnv)
if err != nil {
err = fmt.Errorf("%w from remote '%s'; %s", ErrFailedToLoadReplicaDB, remoteName, err.Error())
if !dsess.IgnoreReplicationErrors() {
return ReadReplicaDatabase{}, err
}
cli.Println(err)
return ReadReplicaDatabase{Database: db}, nil
err = fmt.Errorf("%s from remote '%s'; %w", ErrFailedToLoadReplicaDB.Error(), remoteName, err)
return ReadReplicaDatabase{}, err
}

return rrd, nil
}

Expand Down
29 changes: 29 additions & 0 deletions integration-tests/bats/replication.bats
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ teardown() {
[[ ! "$output" =~ "feature" ]] || false
}

@test "replication: push tag delete, pull delete on read" {
cd repo1
dolt tag tag1
dolt tag tag2
dolt push remote1 tag1
dolt push remote1 tag2

cd ..
dolt clone file://./rem1 repo2
cd repo2
dolt config --local --add sqlserver.global.dolt_read_replica_remote origin
dolt config --local --add sqlserver.global.dolt_replicate_all_heads 1

run dolt sql -q "select tag_name from dolt_tags" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "tag1" ]] || false
[[ "$output" =~ "tag2" ]] || false

cd ../repo1
dolt config --local --add sqlserver.global.dolt_replicate_to_remote remote1
dolt tag -d tag1

cd ../repo2
run dolt sql -q "select tag_name from dolt_tags" -r csv
[ "$status" -eq 0 ]
[[ ! "$output" =~ "tag1" ]] || false
[[ "$output" =~ "tag2" ]] || false
}

@test "replication: pull branch delete on read" {
cd repo1
dolt push remote1 feature
Expand Down

0 comments on commit dee5e41

Please sign in to comment.