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

dynamo data streaming update #81

Open
wants to merge 1 commit into
base: name-to-id-test-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions sources/dynamodb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ func (isi InfoSchemaImpl) StartChangeDataCapture(ctx context.Context, conv *inte
fmt.Println("Starting DynamoDB Streams initialization...")

latestStreamArn := make(map[string]interface{})
orderTableNames := ddl.OrderTables(conv.SpSchema)
orderTableIds := ddl.OrderTables(conv.SpSchema)

for _, spannerTable := range orderTableNames {
srcTable, _ := internal.GetSourceTable(conv, spannerTable)
for _, tableId := range orderTableIds {
// srcTable, _ := internal.GetSourceTable(conv, spannerTable)
srcTable := conv.SrcSchema[tableId].Name
streamArn, err := NewDynamoDBStream(isi.DynamoClient, srcTable)
if err != nil {
conv.Unexpected(fmt.Sprintf("Couldn't initialize DynamoDB Stream for table %s: %s", srcTable, err))
Expand Down
22 changes: 16 additions & 6 deletions sources/dynamodb/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/cloudspannerecosystem/harbourbridge/common/metrics"
"github.com/cloudspannerecosystem/harbourbridge/internal"
"github.com/cloudspannerecosystem/harbourbridge/schema"
"github.com/cloudspannerecosystem/harbourbridge/sources/common"
)

const (
Expand Down Expand Up @@ -345,12 +344,23 @@ func ProcessRecord(conv *internal.Conv, streamInfo *StreamingInfo, record *dynam
eventName := *record.EventName
streamInfo.StatsAddRecord(srcTable, eventName)

srcSchema, spTable, spCols, spSchema, err := common.GetColsAndSchemas(conv, srcTable)
if err != nil {
streamInfo.Unexpected(fmt.Sprintf("Can't get cols and schemas for table %s: %v", srcTable, err))
return
tableId, _ := internal.GetTableIdFromName(conv, srcTable)
srcSchema := conv.SrcSchema[tableId]
spSchema := conv.SpSchema[tableId]
spTable := spSchema.Name
spCols := []string{}
srcCols := []string{}
for _, colId := range spSchema.ColIds {
spCols = append(spCols, spSchema.ColDefs[colId].Name)
srcCols = append(srcCols, srcSchema.ColDefs[colId].Name)
}

// srcSchema, spTable, spCols, spSchema, err := common.GetColsAndSchemas(conv, srcTable)
// if err1 != nil || {
// streamInfo.Unexpected(fmt.Sprintf("Can't get cols and schemas for table %s: %v", srcTable, err))
// return
// }

var srcImage map[string]*dynamodb.AttributeValue
if eventName == "REMOVE" {
srcImage = record.Dynamodb.Keys
Expand All @@ -363,7 +373,7 @@ func ProcessRecord(conv *internal.Conv, streamInfo *StreamingInfo, record *dynam
writeRecord(streamInfo, srcTable, spTable, eventName, spCols, spVals, srcSchema)
} else {
streamInfo.StatsAddBadRecord(srcTable, eventName)
streamInfo.CollectBadRecord(eventName, srcTable, srcSchema.ColIds, srcStrVals)
streamInfo.CollectBadRecord(eventName, srcTable, srcCols, srcStrVals)
}
streamInfo.StatsAddRecordProcessed()
}
Expand Down