diff --git a/CHANGELOG.md b/CHANGELOG.md index 695913f0..290e6ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove unecessary transactions where a single database operation will do. This reduces the number of subtransactions created which can be an operational benefit it many cases. [PR #950](https://github.com/riverqueue/river/pull/950) - Bring all driver tests into separate package so they don't leak dependencies. This removes dependencies from the top level `river` package that most River installations won't need, thereby reducing the transitive dependency load of most River installations. [PR #955](https://github.com/riverqueue/river/pull/955). +- The reindexer maintenance service now reindexes all `river_job` indexes, including its primary key. This is expected to help in situations where the jobs table has in the past expanded to a very large size (which makes most indexes larger), is now a much more modest size, but has left the indexes in their expanded state. [PR #963](https://github.com/riverqueue/river/pull/963). - The River CLI now accepts a `--target-version` of 0 with `river migrate-down` to run all down migrations and remove all River tables (previously, -1 was used for this; -1 still works, but now 0 also works). [PR #966](https://github.com/riverqueue/river/pull/966). ### Fixed diff --git a/client_test.go b/client_test.go index 97a66769..287b7b6d 100644 --- a/client_test.go +++ b/client_test.go @@ -6428,7 +6428,13 @@ func Test_NewClient_Defaults(t *testing.T) { require.False(t, enqueuer.StaggerStartupIsDisabled()) reindexer := maintenance.GetService[*maintenance.Reindexer](client.queueMaintainer) - require.Equal(t, []string{"river_job_args_index", "river_job_metadata_index"}, reindexer.Config.IndexNames) + require.Contains(t, reindexer.Config.IndexNames, "river_job_args_index") + require.Contains(t, reindexer.Config.IndexNames, "river_job_kind") + require.Contains(t, reindexer.Config.IndexNames, "river_job_metadata_index") + require.Contains(t, reindexer.Config.IndexNames, "river_job_pkey") + require.Contains(t, reindexer.Config.IndexNames, "river_job_prioritized_fetching_index") + require.Contains(t, reindexer.Config.IndexNames, "river_job_state_and_finalized_at_index") + require.Contains(t, reindexer.Config.IndexNames, "river_job_unique_idx") now := time.Now().UTC() nextMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1) require.Equal(t, nextMidnight, reindexer.Config.ScheduleFunc(now)) diff --git a/internal/maintenance/reindexer.go b/internal/maintenance/reindexer.go index cd53f02c..b014648a 100644 --- a/internal/maintenance/reindexer.go +++ b/internal/maintenance/reindexer.go @@ -26,7 +26,15 @@ const ( ReindexerTimeoutDefault = 1 * time.Minute ) -var defaultIndexNames = []string{"river_job_args_index", "river_job_metadata_index"} //nolint:gochecknoglobals +var defaultIndexNames = []string{ //nolint:gochecknoglobals + "river_job_args_index", + "river_job_kind", + "river_job_metadata_index", + "river_job_pkey", + "river_job_prioritized_fetching_index", + "river_job_state_and_finalized_at_index", + "river_job_unique_idx", +} // Test-only properties. type ReindexerTestSignals struct { diff --git a/internal/maintenance/reindexer_test.go b/internal/maintenance/reindexer_test.go index ac35e6d0..04f28cf3 100644 --- a/internal/maintenance/reindexer_test.go +++ b/internal/maintenance/reindexer_test.go @@ -127,7 +127,7 @@ func TestReindexer(t *testing.T) { require.True(t, requireReindexOne(indexName)) }) - t.Run("ReindexesEachIndex", func(t *testing.T) { + t.Run("ReindexesMinimalSubsetofIndexes", func(t *testing.T) { t.Parallel() svc, bundle := setup(t) @@ -163,6 +163,17 @@ func TestReindexer(t *testing.T) { } }) + t.Run("ReindexesDefaultIndexes", func(t *testing.T) { + t.Parallel() + + svc, _ := setup(t) + + svc.Config.ScheduleFunc = runImmediatelyThenOnceAnHour() + + require.NoError(t, svc.Start(ctx)) + svc.TestSignals.Reindexed.WaitOrTimeout() + }) + t.Run("ReindexDeletesArtifactsWhenCancelledWithStop", func(t *testing.T) { t.Parallel()