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

Bulk indexer util: Add a worker ID context value to flush events #647

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion opensearchutil/bulk_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
)

const defaultFlushInterval = 30 * time.Second
// WorkerIdCtxKeyType is a context value type to get the worker ID from the context in flush callbacks
type WorkerIdCtxKeyType string

Check failure on line 45 in opensearchutil/bulk_indexer.go

View workflow job for this annotation

GitHub Actions / Lint

ST1003: type WorkerIdCtxKeyType should be WorkerIDCtxKeyType (stylecheck)

const (
WorkerCtxKey WorkerIdCtxKeyType = "workerId"

Check failure on line 48 in opensearchutil/bulk_indexer.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/opensearch-project/opensearch-go) (gci)
defaultFlushInterval = 30 * time.Second
)

// BulkIndexer represents a parallel, asynchronous, efficient indexer for OpenSearch.
type BulkIndexer interface {
Expand Down Expand Up @@ -452,6 +458,7 @@

// flush writes out the worker buffer; it must be called under a lock.
func (w *worker) flush(ctx context.Context) error {
ctx = context.WithValue(ctx, WorkerCtxKey, w.id)
if w.bi.config.OnFlushStart != nil {
ctx = w.bi.config.OnFlushStart(ctx)
}
Expand Down
Loading