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

Protect against doing requests for snapshots that are over 400KB. #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spangaer
Copy link
Contributor

Sources:
https://zaccharles.medium.com/calculating-a-dynamodb-items-size-and-consumed-capacity-d1728942eb7c https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html

Draft note

I'm well aware that the rename refactor and deployment processes are still ongoing. We'll adapt these commits to the new reality as it materializes but wanted to stage the contributions already.

Also FYI @coreyoconnor

@pjfanning pjfanning added this to the v1.1.0 milestone Feb 10, 2023
@coreyoconnor
Copy link
Contributor

Nice!

To clarify: This is to improve the error handling in the case a snapshot would be rejected due to exceeding DynamoDB's maximum item size?

I also like that this is part of the code that would be required to dispatch large snapshots to S3 :)

Copy link
Contributor

@mdedetrich mdedetrich left a comment

Choose a reason for hiding this comment

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

Thanks, just found a couple of things.

Also it would be ideal if we could write a test for this.

@@ -12,6 +12,8 @@ import com.typesafe.config.Config
import akka.persistence.dynamodb._
import scala.concurrent.Future

class DynamoDBSnapshotRejection(message: String, cause: Throwable = null) extends RuntimeException(message, cause)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a Key field as a val to this exception so we know which key caused the exception incase people want to catch it.

Also mention the key in the exception message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like that then breaks consistency with e.g.
https://github.com/esko-oss/pekko-persistence-dynamodb/blob/4d172134208279a00b90ef597dd0970c31b56fde/src/main/scala/akka/persistence/dynamodb/journal/DynamoDBJournal.scala#L30

If this exception ripples back to the persistent actor, the persistence ID would be known there too.

* https://zaccharles.medium.com/calculating-a-dynamodb-items-size-and-consumed-capacity-d1728942eb7c
* https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html
*/
val dynamoFixedByteSize =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be DynamoFixedByteSize since its a constant (Scala convention).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll adapt when we rebase this.

@spangaer
Copy link
Contributor Author

To clarify: This is to improve the error handling in the case a snapshot would be rejected due to exceeding DynamoDB's maximum item size?

It is, avoiding a sizeable round trip in doing so.

@spangaer spangaer marked this pull request as ready for review December 18, 2023 19:34
@spangaer
Copy link
Contributor Author

The headers should be fixed, but it looks like we're still doing something wrong with the formatting.

@pjfanning
Copy link
Contributor

@spangaer SnapshotTooBigSpec has 2 formatting issues

  • incorrect indent on line 31
  • stray space at end of line 61

@spangaer
Copy link
Contributor Author

Should be fixed now.
Failure to use scalafmtAll instead of scalafmt.

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

lgtm

@pjfanning
Copy link
Contributor

Thanks, just found a couple of things.

Also it would be ideal if we could write a test for this.

@mdedetrich could you re-review? I've created a 1.0.x branch so it should now be safe to merge 1.1 stuff.

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

5 participants