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

DynamoDB - Respect lineage #422

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sources/dynamodb/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ func (s *StreamStore) ListenToChannel(ctx context.Context, writer writers.Writer
}

func (s *StreamStore) processShard(ctx context.Context, shard *dynamodbstreams.Shard, writer writers.Writer) {
var attempts int

// Is there another go-routine processing this shard?
if s.storage.GetShardProcessing(*shard.ShardId) {
return
}

if parentID := shard.ParentShardId; parentID != nil {
// If the parent shard exists, is it still being processed? If so, let's wait a bit and then retry.
// We must process the parent shard first before processing the child shard.
if s.storage.GetShardProcessing(*parentID) && !s.storage.GetShardProcessed(*parentID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the parent hasn't started processing yet? Is that possible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm interesting. I think we need to sort the shards that are returned since there's no guarantee it's ordered

slog.Info("Parent shard is being processed, let's sleep 3s and retry", slog.String("shardId", *shard.ShardId), slog.String("parentShardId", *parentID))
time.Sleep(3 * time.Second)
s.processShard(ctx, shard, writer)
return
}
}

// If no one is processing it, let's mark it as being processed.
s.storage.SetShardProcessing(*shard.ShardId)
if s.storage.GetShardProcessed(*shard.ShardId) {
Expand Down Expand Up @@ -103,6 +112,7 @@ func (s *StreamStore) processShard(ctx context.Context, shard *dynamodbstreams.S
logger.Panic("Failed to publish messages, exiting...", slog.Any("err", err))
}

var attempts int
if len(getRecordsOutput.Records) > 0 {
attempts = 0
lastRecord := getRecordsOutput.Records[len(getRecordsOutput.Records)-1]
Expand Down