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

Debugging PR #1086

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 12 additions & 2 deletions clients/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (s *Store) putTable(ctx context.Context, bqTableID dialect.TableIdentifier,
if err != nil {
return fmt.Errorf("failed to create managedwriter client: %w", err)
}

defer managedWriterClient.Close()

managedStream, err := managedWriterClient.NewManagedStream(ctx,
Expand All @@ -161,6 +162,7 @@ func (s *Store) putTable(ctx context.Context, bqTableID dialect.TableIdentifier,
if err != nil {
return fmt.Errorf("failed to create managed stream: %w", err)
}

defer managedStream.Close()

encoder := func(row map[string]any) ([]byte, error) {
Expand All @@ -180,11 +182,19 @@ func (s *Store) putTable(ctx context.Context, bqTableID dialect.TableIdentifier,
return batch.BySize(tableData.Rows(), maxRequestByteSize, false, encoder, func(chunk [][]byte) error {
result, err := managedStream.AppendRows(ctx, chunk)
if err != nil {
slog.Error("Failed to append rows", slog.Any("err", err))
return fmt.Errorf("failed to append rows: %w", err)
}

if resp, err := result.FullResponse(ctx); err != nil {
return fmt.Errorf("failed to get response (%s): %w", resp.GetError().String(), err)
resp, err := result.FullResponse(ctx)
if err != nil {
slog.Error("Failed to get response", slog.Any("err", err))
return fmt.Errorf("failed to get response: %w", err)
}

if status := resp.GetError(); status != nil {
slog.Error("Failed to append rows", slog.String("status", status.String()))
return fmt.Errorf("failed to append rows: %s", status.String())
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion clients/bigquery/dialect/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (BigQueryDialect) BuildCreateTableQuery(tableID sql.TableIdentifier, tempor
return fmt.Sprintf(
`%s OPTIONS (expiration_timestamp = TIMESTAMP("%s"))`,
query,
BQExpiresDate(time.Now().UTC().Add(constants.TemporaryTableTTL)),
BQExpiresDate(time.Now().UTC().Add(constants.ExtraLongTTL)),
)
} else {
return query
Expand Down
8 changes: 4 additions & 4 deletions clients/shared/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/artie-labs/transfer/lib/destination"
"github.com/artie-labs/transfer/lib/destination/ddl"
"github.com/artie-labs/transfer/lib/destination/types"
"github.com/artie-labs/transfer/lib/jitter"
"github.com/artie-labs/transfer/lib/optimization"
Expand Down Expand Up @@ -59,9 +58,10 @@ func Merge(ctx context.Context, dwh destination.DataWarehouse, tableData *optimi

temporaryTableID := TempTableIDWithSuffix(dwh.IdentifierFor(tableData.TopicConfig(), tableData.Name()), tableData.TempTableSuffix())
defer func() {
if dropErr := ddl.DropTemporaryTable(dwh, temporaryTableID, false); dropErr != nil {
slog.Warn("Failed to drop temporary table", slog.Any("err", dropErr), slog.String("tableName", temporaryTableID.FullyQualifiedName()))
}
// Don't drop the temporary table.
//if dropErr := ddl.DropTemporaryTable(dwh, temporaryTableID, false); dropErr != nil {
// slog.Warn("Failed to drop temporary table", slog.Any("err", dropErr), slog.String("tableName", temporaryTableID.FullyQualifiedName()))
//}
}()

if err = dwh.PrepareTemporaryTable(ctx, tableData, tableConfig, temporaryTableID, tableID, types.AdditionalSettings{ColumnSettings: opts.ColumnSettings}, true); err != nil {
Expand Down
1 change: 1 addition & 0 deletions lib/config/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
ExceededValueMarker = ArtiePrefix + "_exceeded_value"

TemporaryTableTTL = 6 * time.Hour
ExtraLongTTL = 14 * 24 * time.Hour

DBZMongoFormat = "debezium.mongodb"

Expand Down
3 changes: 3 additions & 0 deletions lib/optimization/table_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package optimization

import (
"fmt"
"log/slog"
"strings"
"time"

Expand Down Expand Up @@ -155,6 +156,8 @@ func (t *TableData) InsertRow(pk string, rowData map[string]any, delete bool) {
t.approxSize += newRowSize - prevRowSize
t.rowsData[pk] = rowData

slog.Info("Inserted row", slog.String("pk", pk), slog.String("__artie_db_updated_at", fmt.Sprint(rowData[constants.DatabaseUpdatedColumnMarker])))

if !delete {
t.containOtherOperations = true
} else if delete && !t.topicConfig.SoftDelete {
Expand Down
Loading