Skip to content
Merged
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
10 changes: 5 additions & 5 deletions internal/database/sqlcommon/data_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func (s *SQLCommon) attemptDataUpdate(ctx context.Context, tx *txWrapper, data *
})
}

func (s *SQLCommon) attemptDataInsert(ctx context.Context, tx *txWrapper, data *fftypes.Data, datatype *fftypes.DatatypeRef, blob *fftypes.BlobRef) (int64, error) {
func (s *SQLCommon) attemptDataInsert(ctx context.Context, tx *txWrapper, data *fftypes.Data, datatype *fftypes.DatatypeRef, blob *fftypes.BlobRef, requestConflictEmptyResult bool) (int64, error) {
data.ValueSize = data.Value.Length()
return s.insertTx(ctx, tx,
return s.insertTxExt(ctx, tx,
sq.Insert("data").
Columns(dataColumnsWithValue...).
Values(
Expand All @@ -101,7 +101,7 @@ func (s *SQLCommon) attemptDataInsert(ctx context.Context, tx *txWrapper, data *
),
func() {
s.callbacks.UUIDCollectionNSEvent(database.CollectionData, fftypes.ChangeEventTypeCreated, data.Namespace, data.ID)
})
}, requestConflictEmptyResult)
}

func (s *SQLCommon) UpsertData(ctx context.Context, data *fftypes.Data, optimization database.UpsertOptimization) (err error) {
Expand All @@ -127,7 +127,7 @@ func (s *SQLCommon) UpsertData(ctx context.Context, data *fftypes.Data, optimiza
// as only recovery paths require us to go down the un-optimized route.
optimized := false
if optimization == database.UpsertOptimizationNew {
_, opErr := s.attemptDataInsert(ctx, tx, data, datatype, blob)
_, opErr := s.attemptDataInsert(ctx, tx, data, datatype, blob, true /* we want a failure here we can progress past */)
optimized = opErr == nil
} else if optimization == database.UpsertOptimizationExisting {
rowsAffected, opErr := s.attemptDataUpdate(ctx, tx, data, datatype, blob)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (s *SQLCommon) UpsertData(ctx context.Context, data *fftypes.Data, optimiza
return err
}
} else {
if _, err = s.attemptDataInsert(ctx, tx, data, datatype, blob); err != nil {
if _, err = s.attemptDataInsert(ctx, tx, data, datatype, blob, false); err != nil {
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/database/sqlcommon/message_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (s *SQLCommon) attemptMessageUpdate(ctx context.Context, tx *txWrapper, mes
})
}

func (s *SQLCommon) attemptMessageInsert(ctx context.Context, tx *txWrapper, message *fftypes.Message) (err error) {
message.Sequence, err = s.insertTx(ctx, tx,
func (s *SQLCommon) attemptMessageInsert(ctx context.Context, tx *txWrapper, message *fftypes.Message, requestConflictEmptyResult bool) (err error) {
message.Sequence, err = s.insertTxExt(ctx, tx,
sq.Insert("messages").
Columns(msgColumns...).
Values(
Expand All @@ -109,7 +109,7 @@ func (s *SQLCommon) attemptMessageInsert(ctx context.Context, tx *txWrapper, mes
),
func() {
s.callbacks.OrderedUUIDCollectionNSEvent(database.CollectionMessages, fftypes.ChangeEventTypeCreated, message.Header.Namespace, message.Header.ID, message.Sequence)
})
}, requestConflictEmptyResult)
return err
}

Expand All @@ -128,7 +128,7 @@ func (s *SQLCommon) UpsertMessage(ctx context.Context, message *fftypes.Message,
optimized := false
recreateDatarefs := false
if optimization == database.UpsertOptimizationNew {
opErr := s.attemptMessageInsert(ctx, tx, message)
opErr := s.attemptMessageInsert(ctx, tx, message, true /* we want a failure here we can progress past */)
optimized = opErr == nil
} else if optimization == database.UpsertOptimizationExisting {
rowsAffected, opErr := s.attemptMessageUpdate(ctx, tx, message)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *SQLCommon) UpsertMessage(ctx context.Context, message *fftypes.Message,
return err
}
} else {
if err = s.attemptMessageInsert(ctx, tx, message); err != nil {
if err = s.attemptMessageInsert(ctx, tx, message, false); err != nil {
return err
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *SQLCommon) ReplaceMessage(ctx context.Context, message *fftypes.Message
return err
}

if err = s.attemptMessageInsert(ctx, tx, message); err != nil {
if err = s.attemptMessageInsert(ctx, tx, message, false); err != nil {
return err
}

Expand Down