Skip to content

feat: Implement strongly consistent reads support for Query and GetItem operations#30

Merged
shidil merged 4 commits intomainfrom
copilot/fix-438eaffb-333c-4ec6-870f-e25cfb176918
Oct 3, 2025
Merged

feat: Implement strongly consistent reads support for Query and GetItem operations#30
shidil merged 4 commits intomainfrom
copilot/fix-438eaffb-333c-4ec6-870f-e25cfb176918

Conversation

Copy link
Contributor

Copilot AI commented Sep 30, 2025

Implementation completed for strongly consistent reads support:

  • Analyze existing codebase and test patterns
  • Add WithConsistentRead() option function to Query operations
  • Update GetItem to support option functions (GetItemOptions) and add WithConsistentReadItem for GetItem
  • Update interface.go to reflect GetItem signature changes
  • Add comprehensive tests for both Query and GetItem consistent read functionality
  • Verify all existing tests still pass
  • Test consistent read behavior works as expected
  • Reorganize tests per reviewer feedback - moved Query tests to query_test.go and GetItem tests to getitem_test.go

Summary of Changes

Core Implementation:

  • Added WithConsistentRead() for Query operations (sets ConsistentRead: true on QueryInput)
  • Added GetItemOptions type and WithConsistentReadItem() for GetItem operations
  • Updated GetItem method signature to accept optional parameters: GetItem(ctx, pk, sk, out, opts...)
  • Updated ReadAPI interface to reflect new GetItem signature
  • Created options.go file with both consistent read option functions

Testing:

  • Added Query consistent read tests to query_test.go following existing patterns
  • Created new getitem_test.go file for GetItem consistent read tests
  • Removed separate consistent_read_test.go file per reviewer feedback
  • Tests cover Query and GetItem with/without consistent read options
  • Tests verify integration with other option functions
  • All existing tests continue to pass

API Usage:

// Query with consistent read
table.Query(ctx, "pk = :pk", values, &results, dynago.WithConsistentRead())

// GetItem with consistent read  
table.GetItem(ctx, pk, sk, &item, dynago.WithConsistentReadItem())

This implementation follows AWS DynamoDB strongly consistent reads specification and maintains backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Strongly consistent reads</issue_title>
<issue_description>Context

Eventually consistent is the default read consistent model for all read operations. When issuing eventually consistent reads to a DynamoDB table or an index, the responses may not reflect the results of a recently completed write operation.

Strongly consistent reads

Read operations such as GetItem, Query, and Scan provide an optional ConsistentRead parameter. If you set ConsistentRead to true, DynamoDB returns a response with the most up-to-date data, reflecting the updates from all prior write operations that were successful. Strongly consistent reads are only supported on tables and local secondary indexes. Strongly consistent reads from a global secondary index or a DynamoDB stream are not supported.

Requirement

Implement support for strongly consistent reads on GetItem and Query operations.
ConsistentRead option for the input should be set to true for enabling consistent reads.

For convenience, provide WithConsistentRead option function.
Check existing option functions on query.go for example implementations.

// query.go

// WithConsistentRead enables strongly consistent read for the query
// See documentation https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html
// Note that the cost for strongly consistent reads are double of eventual consistent reads
func WithConsistentRead() QueryOptions {
  return func(q *dynamodb.QueryInput) {
    q.ConsistentRead = aws.Bool(true)
  }
}
```</issue_description>

<agent_instructions>GetItem might not support option functions yet. It needs to be implemented as part of this feature.

Follow table driven test pattern. Analyze existing tests for examples.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #29

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 30, 2025 04:07
Co-authored-by: shidil <4880359+shidil@users.noreply.github.com>
… with comprehensive testing

Co-authored-by: shidil <4880359+shidil@users.noreply.github.com>
Copilot AI changed the title [WIP] Strongly consistent reads Implement strongly consistent reads support for Query and GetItem operations Sep 30, 2025
Copilot AI requested a review from shidil September 30, 2025 04:11
…nd GetItem tests to getitem_test.go

Co-authored-by: shidil <4880359+shidil@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 30, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cognito-identity.us-east-1.amazonaws.com
    • Triggering command: java -jar DynamoDBLocal.jar -inMemory (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from shidil September 30, 2025 04:50
@shidil shidil changed the title Implement strongly consistent reads support for Query and GetItem operations feat: Implement strongly consistent reads support for Query and GetItem operations Oct 2, 2025
@shidil shidil marked this pull request as ready for review October 2, 2025 22:58
Copilot AI review requested due to automatic review settings October 2, 2025 22:58
@shidil shidil requested review from NalinSajwan and snehithv October 2, 2025 22:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements strongly consistent reads support for DynamoDB Query and GetItem operations. The implementation adds option functions to enable consistent reads while maintaining backward compatibility with existing code.

  • Added WithConsistentRead() option function for Query operations
  • Implemented GetItem options support with WithConsistentReadItem() function
  • Updated GetItem method signature to accept optional parameters

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
options.go New file containing consistent read option functions for both Query and GetItem operations
interface.go Updated ReadAPI interface to reflect new GetItem signature with optional parameters
get_item.go Modified GetItem method to support option functions and added GetItemOptions type
tests/query_test.go Added comprehensive tests for Query consistent read functionality
tests/getitem_test.go New test file for GetItem consistent read functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@shidil shidil requested a review from Copilot October 3, 2025 01:15
@shidil shidil merged commit dd62f46 into main Oct 3, 2025
2 checks passed
@shidil shidil deleted the copilot/fix-438eaffb-333c-4ec6-870f-e25cfb176918 branch October 3, 2025 01:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


type ReadAPI interface {
GetItem(ctx context.Context, pk, sk Attribute, out interface{}) (error, bool)
GetItem(ctx context.Context, pk, sk Attribute, out interface{}, opts ...GetItemOptions) (error, bool)
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The return value order (error, bool) in the interface is inconsistent with Go conventions where error should be the last return value. Consider changing to (bool, error) for better consistency with Go idioms.

Suggested change
GetItem(ctx context.Context, pk, sk Attribute, out interface{}, opts ...GetItemOptions) (error, bool)
GetItem(ctx context.Context, pk, sk Attribute, out interface{}, opts ...GetItemOptions) (bool, error)

Copilot uses AI. Check for mistakes.
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.

Strongly consistent reads

3 participants