Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 2, 2024
1 parent 3754b83 commit f7d7f33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions sources/dynamodb/snapshot/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// findRecentExport - This will check against the DynamoDB table to see if there is a recent export for the given S3 file path.
// It will then return the exportARN, manifestFilePath and error if any.
func (s *Store) findRecentExport(ctx context.Context, s3FilePath string) (*string, *string, error) {
func (s *Store) findRecentExport(ctx context.Context, bucket string, prefix string) (*string, *string, error) {
tableARN, err := dynamo.GetTableArnFromStreamArn(s.streamArn)
if err != nil {
return nil, nil, fmt.Errorf("failed to get table ARN from stream ARN: %w", err)
Expand Down Expand Up @@ -44,7 +44,19 @@ func (s *Store) findRecentExport(ctx context.Context, s3FilePath string) (*strin
}
}

return nil, nil, fmt.Errorf("no recent export found for %s", s3FilePath)
// Not found, so let's initiate one
result, err := s.dynamoDBClient.ExportTableToPointInTime(ctx, &dynamodb.ExportTableToPointInTimeInput{
TableArn: aws.String(tableARN),
S3Bucket: aws.String(bucket),
S3Prefix: aws.String(prefix),
ExportFormat: types.ExportFormatDynamodbJson,
})

if err != nil {
return nil, nil, err
}

return result.ExportDescription.ExportArn, nil, nil
}

func (s *Store) listExports(ctx context.Context, tableARN string) ([]types.ExportSummary, error) {
Expand Down
5 changes: 3 additions & 2 deletions sources/dynamodb/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"path/filepath"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -45,7 +46,7 @@ func NewStore(ctx context.Context, cfg config.DynamoDB, awsCfg aws.Config) (*Sto
}

if cfg.SnapshotSettings.ShouldInitiateExport {
exportARN, manifestFilePath, err := store.findRecentExport(ctx, cfg.SnapshotSettings.Folder)
exportARN, manifestFilePath, err := store.findRecentExport(ctx, bucketName, prefixName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -75,7 +76,7 @@ func (s *Store) loadFolderFromManifest(bucketName string, manifestFilePath strin
return fmt.Errorf("failed to parse manifest: %w", err)
}

s.cfg.SnapshotSettings.Folder = folder
s.cfg.SnapshotSettings.Folder = filepath.Join(folder, "data")
return nil
}

Expand Down

0 comments on commit f7d7f33

Please sign in to comment.