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

AWS SDK v1 DynamoDB backend #142

Merged

Conversation

akhomchenko
Copy link
Contributor

@akhomchenko akhomchenko commented Dec 30, 2020

Good evening.

Thank you a lot for awesome library. It looks really cool.

I wanted to use it for one of my projects and noticed lack of most common backend I use - AWS DynamoDB. At the time I've forked the code there was no 6.0 branch and so I based my code on 5.0 branch which had a lot of helpful abstract classes. Implementation was really simple.

Given that there is 6.0 that does not contain changes from 5.0 I have couple of questions:

  • is 5.0 abandoned and will not be merged to master?
  • if so - what is a best way to start with custom backend in master/6.0?
  • if not - do you plan to release it soon?

General questions:

  • are you interested in this contribution? It is WIP now but I will add more tests and docs to make it a little bit easier to use
  • any special requirements? Current implementation passes tck test but maybe something you want me to double check
  • do you have import, naming or formatting rules? Repository does not contain them. I am trying to follow your style (feel free to call out).

Notes:

  • I can take a look on SDKv2 later as I haven't used it at all (unlike v1). I assume there are common things that can be extracted.

Thank you and happy holidays!

@vladimir-bukhtoyarov
Copy link
Collaborator

vladimir-bukhtoyarov commented Dec 30, 2020

Hello @akhomchenko

Do not worry. Efforts from 5.0 are not abandoned. 5.0 has been just renamed to 7.0. 7.0 by itself will be released after completion of documentation and javadocs.

It was just a technical decision to use 6.0 branch instead of 4.11, because of backward-incompatible changes in the API(replaceConfiguration now accepts the second parameter) requires from us to increase the major version, but 5.0 version was already taken by Beta release without documentation. So I decided to never release 5.0 officially and just move all the efforts to the 7.0 and release it officially in 2021.

@vladimir-bukhtoyarov
Copy link
Collaborator

According to this request: I will merge it to ```7.0```` during the holidays. Thank you for your work.

@vladimir-bukhtoyarov vladimir-bukhtoyarov changed the base branch from 5.0 to 7.0 December 30, 2020 08:58
@akhomchenko akhomchenko force-pushed the feature/dynamodb-support branch 3 times, most recently from 8ef57c1 to e3065e6 Compare January 3, 2021 22:08
@vladimir-bukhtoyarov
Copy link
Collaborator

@ akhomchenko hello,

I am going to review and merge this request. Did you finalize all planned works?

@akhomchenko
Copy link
Contributor Author

Hey, sorry for the delay.

Did you finalize all planned works?

I have update with documentation + extra safe guards locally. I will publish it by EOD for review. There are some things that I am not sure about and I want to hear your opinion as you are a lead maintainer.

I want to test it in personal AWS account during this weekend but that should not affect the review.

@vladimir-bukhtoyarov
Copy link
Collaborator

Ok. Just do not forget to remove WIP prefix when finishing.

@akhomchenko akhomchenko changed the title WIP AWS SDK v1 DynamoDB backend AWS SDK v1 DynamoDB backend Jan 16, 2021
@akhomchenko
Copy link
Contributor Author

akhomchenko commented Jan 16, 2021

Updated. I left some comments and questions as TODOs and will add some as inline comments.

I used CFN template I specified in javadoc to create a table and used that table in StringDynamoDBBackendTckTest. All tests pass.

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.913</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I can not specify range for dependencyManagement so I am not sure what is the best path forward. My idea was to specify 1.11.913 <2.0 range to support updates. I can update pom.xml to not use dependencyManagement and just specify range on a dependency.

}

AttributeValue state = result.get(stateAttr);
if (state.getB() == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the first place I have a question for. So in my initial implementation I was returning empty optional here as I was not sure if throwing an exception from get is something that can be expected (method does not define if exception can be thrown if state is broken).

I switched to throwing as there is no possibility for code to succeed if state attribute has type different from NULL or B.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method does not support NULL value for state as from current logic NULL should never be written, but I can update code to support it.

By "current logic NULL should never be written" I mean I assume that getModifiedStateBytes of GenericEntry will not return null. Is it a case?

Comment on lines +30 to +36
int length = key.getBytes(StandardCharsets.UTF_8).length;
if (length > MAX_SUPPORTED_LENGTH) {
throw new IllegalArgumentException(
"key " + key + " has length of " + length + " bytes " +
"while max allowed is " + MAX_SUPPORTED_LENGTH + " bytes"
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this check in updated revision to provide better message. If you think that it is not worth the trouble and / or expensive to do I can drop it. DynamoDB will throw it's own exception.

Backend supports 2 key types: string and number (only long for now).
Backend is based on compare and swap and relies on DynamoDB's condition
expression to guarantee consistency.
@vladimir-bukhtoyarov vladimir-bukhtoyarov merged commit 4c8d4ab into bucket4j:7.0 Jan 19, 2021
vladimir-bukhtoyarov added a commit that referenced this pull request Jan 19, 2021
@akhomchenko
Copy link
Contributor Author

Oh wow, that was fast! Thank you for accepting my contribution! Could you please take a look on questions I left in this PR? I will do some follow-up fixed based on your feedback if necessary. I am mostly interested if GenericEntry#getModifiedStateBytes can ever return null. Thank you.

@akhomchenko akhomchenko deleted the feature/dynamodb-support branch January 26, 2021 00:11
@vladimir-bukhtoyarov
Copy link
Collaborator

I will answer your questions at weekend

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.

None yet

2 participants