Skip to content

[improve][io] ElasticSearch sink: conditional id hashing - #18668

Merged
nicoloboschi merged 3 commits into
apache:masterfrom
nicoloboschi:elastic-conditional-hashing
Nov 30, 2022
Merged

nicoloboschi merged 3 commits into
apache:masterfrom
nicoloboschi:elastic-conditional-hashing

Conversation

@nicoloboschi

@nicoloboschi nicoloboschi commented Nov 29, 2022 •

Copy link
Copy Markdown
Contributor

Motivation

#15428 introduced a new flag for hashing the document id. This is a great option for not getting into the hard limit of 512 bytes of ElasticSearch.

In prod environment this flag is likely to not be enabled without troubles. If the sink was working before without that flag, all the doc ids are formatted as JSON format. With the same key, an update or deletion would be triggered on ES side. If the user enables the hashing option, those ids won't matching anymore and it will end up creating new records.

In some cases this is not a viable option. Since the hashing algo is actually useful only for workaround the ES limit, it makes sense to have an option to only hash if the would be key length errors on ES side.
In this way, in a living cluster the hashing could be turned on with 100% compatibility with the existing documents.

  • The <= 512 bytes record will behave the same way
  • For > 512 bytes record, it's guaranteed the record is not present on elastic. Enabling this new option, the record will be inserted with a hashed (base64 format) key.

The collision between an hashed key and a non hashed key is not possible:

  • hashed keys are represented in base64 (no { } characters allowed)
  • non hashed keys are json

To sum up, if a living env hits the issue, these are the suggested steps to get the sink to work again without losing messages and unblocking the subscription:

  1. Stop the sink
  2. Change the following config properties:
  • canonicalKeyFields=true
  • idHashingAlgorithm=SHA256
  • conditionalIdHashing=true
    Note that changing may alter the key format and therefore creates new records but it's required to get the hashing option to works correctly.
  1. Restart the sink

Modifications

  • New option conditionalIdHashing default to false. If the raw key is <= 512 bytes and idHashingAlgorithm is set, then the hashing won't be performed

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

@github-actions github-actions Bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Nov 29, 2022
Comment thread site2/docs/io-elasticsearch-sink.md Resolved

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lgtm

nicoloboschi added a commit to datastax/pulsar that referenced this pull request Nov 29, 2022
@nicoloboschi
nicoloboschi merged commit 90c5534 into apache:master Nov 30, 2022
@lhotari

lhotari commented Nov 30, 2022

Copy link
Copy Markdown
Member

@nicoloboschi @eolivelli I'm just wondering if the behavior of conditionalIdHashing should be revisited slightly. In most cases, the id will be the clear text one. However when the length goes over 512 bytes, it becomes a hash value. The length of the resulting base64 encoded value is fairly short.

For example in the test, the AkJcD1sNq/PSuRFfP3cjoCrYvPsVNKDSMWFP1CuBiPY is an example and the length is 43 bytes. Why not take a prefix (512-43 bytes=469 bytes) from the original value and add the hash to the end to make it a unique 512 bytes value?
This probably doesn't matter that much, but it could make the id values more human readable.

lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants