Repository navigation
fix(opensearch): propagate batch context to bulk flushes - #1174
pcbeingused333 wants to merge 3 commits into
Conversation
gregfurman
left a comment
There was a problem hiding this comment.
This appears to be fixed in v4.7.0 of the opensearch-go client, with the inclusion of a short-lived Context attribute.
In addition to the worker.run now allowing a context to be passed in:
I'd prefer if this PR rather upgraded to the latest version of v4 on v4.8.2 (see https://github.com/opensearch-project/opensearch-go/blob/v4.8.2/CHANGELOG.md) and migrated over the tests in integration_test.go to account for the deprecations + changes.
…ch-go to v4.8.2 opensearch-go v4.7 added BulkIndexerConfig.Context for the worker lifecycle. Use it instead of OnFlushStart, bump the client to v4.8.2 and migrate integration_test.go to the generic Do API.
|
Thanks, agreed. Upgraded to v4.8.2 and switched to |
|
|
||
| ### Fixed | ||
|
|
||
| - `opensearch` output now cancels in-flight bulk requests triggered mid-batch when the batch context is cancelled (upgrades `opensearch-go` to v4.8.2) |
There was a problem hiding this comment.
nit: Upgrading the dependency should probably be in the Changed section (which should be before Fixed):
### Changed
- upgrade `opensearch-go` from `v4.7.0` to `v4.8.2` @pcbeingused333 Then we can remove the (upgrades ...) trailer
There was a problem hiding this comment.
Want to just confirm: have you run these locally?
gregfurman
left a comment
There was a problem hiding this comment.
Appears that this new approach will panic if we pass in an already cancelled context.Context to the NewBulkIndexer. I've opened an issue upstream for this opensearch-project/opensearch-go#1392
Also, this needs to run make deps or go mod tidy since it seems the go.sum is stale.
|
|
||
| require.NoError(t, o.Connect(t.Context())) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Context(), 300*time.Millisecond) |
There was a problem hiding this comment.
FYI this panics when the timeout is 0 and workers are greater than 1 -- since the upstream bulk indexer appears to have a bug.
There was a problem hiding this comment.
IMO this entire test can be replaced with a simple additional integration test:
func testOpenSearchInterruptWrite(urls []string, client *osapi.Client, t *testing.T) {
ctx, done := context.WithTimeout(context.Background(), time.Second*30)
defer done()
m := outputFromConf(t, `
index: does_not_exist
id: 'foo-${!count("interruptWriteTest")}'
urls: %v
action: index
`, urls)
require.NoError(t, m.Connect(ctx))
defer func() {
require.NoError(t, m.Close(ctx))
}()
cancelCtx, cancel := context.WithCancel(ctx)
cancel()
err := m.WriteBatch(cancelCtx, service.MessageBatch{
service.NewMessage([]byte(`{"message":"hello world","user":"1"}`)),
})
require.ErrorIs(t, err, context.Canceled)
}NewBulkIndexer panics if its context is cancelled while the workers are starting (opensearch-project/opensearch-go#1392). Return early for an already cancelled batch and only link the batch context to the workers once the indexer has been created. Also tidy go.sum, move the dependency bump to Changed in the CHANGELOG and replace the httptest test with an integration test.
|
Pushed a fix for the panic. An early On your question: no, the integration tests have not been run yet. They compile and vet clean, and the cancelled-context case was checked with a temporary unit test (panics before this commit, passes after). Note that the new integration test covers an already cancelled context, not cancellation while a request is in flight. This comment was drafted with Claude Code. |
Fixes the
opensearchoutput ignoring the batch context for bulk flushes triggered while a batch is still being added.Cause:
WriteBatchbuilt itsBulkIndexerwithout a context, so flushes ran undercontext.Background()and a stalled cluster kept the request alive after the batch context was cancelled.Fix: upgrade
opensearch-go/v4to v4.8.2 and pass a context tied to the batch throughBulkIndexerConfig.Context.NewBulkIndexerpanics if that context is cancelled while workers are starting (opensearch-project/opensearch-go#1392), so an already cancelled batch returns early and the cancellation is only linked once the indexer exists.integration_test.gois migrated to the genericDoAPI and gains an interrupted-write case.The docker-based integration tests compile and vet clean but have not been run.
This change was prepared with the help of an AI coding assistant (Claude).