Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show completion estimate during backfill #567

Merged
merged 7 commits into from
Jan 8, 2025
Merged

Conversation

ryanslade
Copy link
Collaborator

Instead of only showing the number of rows backfills, show an estimate of the total number of tows completed as a percentage.

For example:

1500 records complete... (12.34%)

It attempts to estimate the total number of rows but will fall back to a full scan if the number of rows estimated is zero.

Closes #492

pkg/db/db.go Outdated Show resolved Hide resolved
@ryanslade ryanslade requested a review from a team January 3, 2025 13:05
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just left a comment about the retryable query.

pkg/db/db.go Outdated Show resolved Hide resolved
@ryanslade
Copy link
Collaborator Author

@andrew-farries PTAL

Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good 👍

We have tests for this package in db_test.go; we should add tests for QueryContext just as we have for ExecContext:

pgroll/pkg/db/db_test.go

Lines 22 to 62 in d64ba26

func TestExecContext(t *testing.T) {
t.Parallel()
testutils.WithConnectionToContainer(t, func(conn *sql.DB, connStr string) {
ctx := context.Background()
// create a table on which an exclusive lock is held for 2 seconds
setupTableLock(t, connStr, 2*time.Second)
// set the lock timeout to 100ms
ensureLockTimeout(t, conn, 100)
// execute a query that should retry until the lock is released
rdb := &db.RDB{DB: conn}
_, err := rdb.ExecContext(ctx, "INSERT INTO test(id) VALUES (1)")
require.NoError(t, err)
})
}
func TestExecContextWhenContextCancelled(t *testing.T) {
t.Parallel()
testutils.WithConnectionToContainer(t, func(conn *sql.DB, connStr string) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
// create a table on which an exclusive lock is held for 2 seconds
setupTableLock(t, connStr, 2*time.Second)
// set the lock timeout to 100ms
ensureLockTimeout(t, conn, 100)
// execute a query that should retry until the lock is released
rdb := &db.RDB{DB: conn}
// Cancel the context before the lock times out
go time.AfterFunc(500*time.Millisecond, cancel)
_, err := rdb.ExecContext(ctx, "INSERT INTO test(id) VALUES (1)")
require.Errorf(t, err, "context canceled")
})
}

@ryanslade
Copy link
Collaborator Author

This looks good 👍

We have tests for this package in db_test.go; we should add tests for QueryContext just as we have for ExecContext:

pgroll/pkg/db/db_test.go

Lines 22 to 62 in d64ba26

func TestExecContext(t *testing.T) {
t.Parallel()
testutils.WithConnectionToContainer(t, func(conn *sql.DB, connStr string) {
ctx := context.Background()
// create a table on which an exclusive lock is held for 2 seconds
setupTableLock(t, connStr, 2*time.Second)
// set the lock timeout to 100ms
ensureLockTimeout(t, conn, 100)
// execute a query that should retry until the lock is released
rdb := &db.RDB{DB: conn}
_, err := rdb.ExecContext(ctx, "INSERT INTO test(id) VALUES (1)")
require.NoError(t, err)
})
}
func TestExecContextWhenContextCancelled(t *testing.T) {
t.Parallel()
testutils.WithConnectionToContainer(t, func(conn *sql.DB, connStr string) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
// create a table on which an exclusive lock is held for 2 seconds
setupTableLock(t, connStr, 2*time.Second)
// set the lock timeout to 100ms
ensureLockTimeout(t, conn, 100)
// execute a query that should retry until the lock is released
rdb := &db.RDB{DB: conn}
// Cancel the context before the lock times out
go time.AfterFunc(500*time.Millisecond, cancel)
_, err := rdb.ExecContext(ctx, "INSERT INTO test(id) VALUES (1)")
require.Errorf(t, err, "context canceled")
})
}

Done

@ryanslade ryanslade merged commit 952fb23 into main Jan 8, 2025
28 checks passed
@ryanslade ryanslade deleted the rs/percentage-progress branch January 8, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include percentage complete information during migration start
2 participants