Skip to content

Commit

Permalink
fix possible deadlock on big move (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikifkon authored Aug 29, 2023
1 parent 9f5ba81 commit 3881f39
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/datatransfers/data_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ WHERE column_name=$1;
qry := fmt.Sprintf("COPY (DELETE FROM %s.%s WHERE %s >= %s and %s <= %s RETURNING *) TO STDOUT", v.TableSchema, v.TableName,
key.Entries()[0].Column, keyRange.LowerBound, key.Entries()[0].Column, keyRange.UpperBound)

_, err = txFrom.Conn().PgConn().CopyTo(ctx, &pw, qry)
if err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
}

if err := pw.w.Close(); err != nil {
spqrlog.Zero.Error().Err(err).Msg("error closing pipe")
}

go func() {
_, err = txFrom.Conn().PgConn().CopyTo(ctx, &pw, qry)
if err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
}

if err := pw.w.Close(); err != nil {
spqrlog.Zero.Error().Err(err).Msg("error closing pipe")
}
}()
_, err = txTo.Conn().PgConn().CopyFrom(ctx,
r, fmt.Sprintf("COPY %s.%s FROM STDIN", v.TableSchema, v.TableName))
if err != nil {
Expand Down

0 comments on commit 3881f39

Please sign in to comment.