Skip to content

Batch WAL operations in stream mode#774

Open
tsg wants to merge 3 commits intomainfrom
batch_stream_operations
Open

Batch WAL operations in stream mode#774
tsg wants to merge 3 commits intomainfrom
batch_stream_operations

Conversation

@tsg
Copy link
Member

@tsg tsg commented Mar 12, 2026

Description

This is the implementation for the plan in #770

Before this PR, we were batching write operations against the target in snapshot mode, but not in stream mode. This adds batching also in stream mode, as a performance optimisation.

Related Issue(s)

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

}
return w.dmlAdapter.buildBulkInsertQueries(events, run[0].schemaInfo), nil
default:
// UPDATE, TRUNCATE, and anything else: individual queries
Copy link
Member Author

Choose a reason for hiding this comment

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

This means we can still have the same type of issue with UPDATE ... WHERE ... statements that updates a lot of rows. Hopefully less common than the commit case.

@tsg tsg requested a review from kvch March 12, 2026 17:48
@github-actions
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/stream/integration 0.00% (ø)
github.com/xataio/pgstream/pkg/wal/processor/postgres 80.57% (+1.68%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/wal/processor/postgres/instrumented_wal_adapter.go 0.00% (ø) 10 (+3) 0 10 (+3)
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_batch_writer.go 74.80% (-4.47%) 127 (+45) 95 (+30) 32 (+15) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_adapter.go 73.91% (+13.91%) 46 (+16) 34 (+16) 12 🎉
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_dml_adapter_bulk.go 91.34% (+91.34%) 127 (+127) 116 (+116) 11 (+11) 🌟
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_message.go 85.71% (+85.71%) 14 (+14) 12 (+12) 2 (+2) 🌟
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_writer.go 37.14% (ø) 35 13 22

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgstream/pkg/stream/integration/pg_pg_batch_coalesce_integration_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/helper_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_batch_writer_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_adapter_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_dml_adapter_bulk_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_message_test.go

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.

WAL streaming batch writer is slow for high-churn tables during catch-up

1 participant