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

FMWK-468 Allow send key classes to use PK instead of Bin #160

Merged
merged 9 commits into from
Jul 1, 2024

Conversation

tim-aero
Copy link
Contributor

Added functionality to allow the record key to be stored in the database key field rather than requiring an explicit bin.

Added a new annotation field "storeInPkOnly" to use the PK field as
storing the key, rather than explicitly setting a bin in the database.
- Added unit tests for the same, both reactive and normal
- Tested with annotations, YAML config, code config.
@tim-aero tim-aero requested a review from roimenashe June 14, 2024 22:20
@roimenashe
Copy link
Contributor

@tim-aero
Did the Java Object Mapper support key as a bin previously to this change?
PK (stored in the record's metadata) is definitely the way to go which btw aligns with our Spring Data Aerospike implementation.

Should we even keep the previous "key as bin" approach? is it done only for backward compatibility? if so we can maybe mark "key as bin" as deprecated with warning of use PK instead and remove this flag in later versions (In Spring Data Aerospike we had the same problem and we removed the "key as bin" without deprecation but it's not ideal from backward perspective)

Do we use this "key as bin" when reading a record? (to map to the POJO?) - we can try map it from the PK if exists and if not from the "key as bin" that way we can support reads for both approaches (in case we will change it to PK without supporting "key as bin" and still being able to read the old records).

WDYT?

@tfaulkes
Copy link
Contributor

tfaulkes commented Jun 16, 2024 via email

@roimenashe
Copy link
Contributor

@tim-aero
Few things:

  1. Refactored and cleaned up a bit so make sure you are pulling before making any change

  2. We consulted internally within our team regarding the style of the new flag and we have a small suggestion:

  • Instead of storeInPkOnly, let’s reverse that and change to storeAsBin which by default will be set to true (in order not to break compatibility)
  • Add validation, in case sendKey is false (which is the default) then we want to prevent the user from writing with storeAsBin = false since we won’t be able to read and map the record back due to not having the original key (the same issue could be encountered in the existing proposal as well).

@tim-aero
Copy link
Contributor Author

Hi Roi,

Yes, I like the storeAsBin option over the storeInPkOnly and agree that storeAsBin should default to true to match the current situation. However, there seem to be 3 scenarios we should consider:

  1. storeAsBin is false -- In this case we use the PK only if sendKey is true, and throw an exception if sendKey is false
  2. storeAsBin is true -- current behaviour
  3. storeAsBin is not specified -- in this case it should default to the same value as sendKey

So I'm wondering if we should create an Enum like storeKey with values IN_PK and IN_BIN, with null allowing it to default to IN_PK if sendKey is true.

There is currently a check to see if storeInPkOnly == true && sendKey == false which will throw an exception if true.

@roimenashe
Copy link
Contributor

@tfaulkes
I agree with (1) - which adds the validation we talked about, (2) - current behavior in case sendKey is false, if sendKey is true we will store the key in both PK and "key as bin" but I don't see (3) the same way as you, I think if storeAsBin isn't specified it's default should be true for now to align with the same behavior as we have now and not set to the current sendKey value (which in my opinion should be 2 completely unrelated options unless both are not set and then we should throw an exception as you mentioned).

I don't like the enum idea because sendKey option already exists as part of @AerospikeRecord, if it wasn't the case we could argue about the design and maybe even always set sendKey to true behind the scenes as we do in Spring Data Aerospike and keep storeAsBin optional with true as default (just to avoid breaking the compatibility), but since it isn't the case I would go with:

  1. storeAsBin is false -- In this case we use the PK only if sendKey is true, and throw an exception if sendKey is false (same as you said).
  2. storeAsBin is true -- current behaviour (in case sendKey is also true we will store the key both in PK and as a bin).
  3. storeAsBin isn't specified -- default should be true (regardless of sendKey value) to align with the current behavior that doesn't include storeAsBin option but always writes the key in a bin.

@roimenashe roimenashe changed the title Allow send key classes to use pk instead of bin FMWK-468 Allow send key classes to use pk instead of bin Jun 18, 2024
@roimenashe roimenashe changed the title FMWK-468 Allow send key classes to use pk instead of bin FMWK-468 Allow send key classes to use PK instead of Bin Jun 18, 2024
@roimenashe roimenashe added the enhancement New feature or request label Jun 18, 2024
tim-aero and others added 3 commits June 18, 2024 17:22
Changed the config field name from `storeInPkOnly` to `storeAsBin`,
added unit test to ensure config validation works.
@roimenashe roimenashe requested a review from reugn June 19, 2024 08:09
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@tim-aero tim-aero merged commit 954fac9 into main Jul 1, 2024
6 checks passed
@tim-aero tim-aero deleted the allow-send-key-classes-to-use-pk-instead-of-bin branch July 1, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants