postgres: return unknown records instead of skipping them (#3876) (#3877)

This commit is contained in:
Caleb Doxsey 2023-01-09 19:32:35 -07:00 committed by GitHub
parent 1761a39fb2
commit 7c69e612b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 41 deletions

View file

@ -173,10 +173,11 @@ func TestBackend(t *testing.T) {
_, err = backend.Get(ctx, "unknown", "1") _, err = backend.Get(ctx, "unknown", "1")
assert.ErrorIs(t, err, storage.ErrNotFound) assert.ErrorIs(t, err, storage.ErrNotFound)
_, _, stream, err := backend.SyncLatest(ctx, "unknown-test", nil) _, _, stream, err := backend.SyncLatest(ctx, "unknown", nil)
if assert.NoError(t, err) { if assert.NoError(t, err) {
_, err := storage.RecordStreamToList(stream) records, err := storage.RecordStreamToList(stream)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, records, 1)
stream.Close() stream.Close()
} }
}) })

View file

@ -97,7 +97,6 @@ func getLatestRecordVersion(ctx context.Context, q querier) (recordVersion uint6
} }
func getNextChangedRecord(ctx context.Context, q querier, recordType string, afterRecordVersion uint64) (*databroker.Record, error) { func getNextChangedRecord(ctx context.Context, q querier, recordType string, afterRecordVersion uint64) (*databroker.Record, error) {
for {
var recordID string var recordID string
var version uint64 var version uint64
var data pgtype.JSONB var data pgtype.JSONB
@ -123,12 +122,12 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("error querying next changed record: %w", err) return nil, fmt.Errorf("error querying next changed record: %w", err)
} }
afterRecordVersion = version
any, err := protoutil.UnmarshalAnyJSON(data.Bytes) any, err := protoutil.UnmarshalAnyJSON(data.Bytes)
if isUnknownType(err) { if isUnknownType(err) {
// ignore any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
continue "id": recordID,
}))
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("error unmarshaling changed record data: %w", err) return nil, fmt.Errorf("error unmarshaling changed record data: %w", err)
} }
@ -141,7 +140,6 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
ModifiedAt: timestamppbFromTimestamptz(modifiedAt), ModifiedAt: timestamppbFromTimestamptz(modifiedAt),
DeletedAt: timestamppbFromTimestamptz(deletedAt), DeletedAt: timestamppbFromTimestamptz(deletedAt),
}, nil }, nil
}
} }
func getOptions(ctx context.Context, q querier, recordType string) (*databroker.Options, error) { func getOptions(ctx context.Context, q querier, recordType string) (*databroker.Options, error) {
@ -229,8 +227,9 @@ func listRecords(ctx context.Context, q querier, expr storage.FilterExpression,
any, err := protoutil.UnmarshalAnyJSON(data.Bytes) any, err := protoutil.UnmarshalAnyJSON(data.Bytes)
if isUnknownType(err) { if isUnknownType(err) {
// ignore records with an unknown type any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
continue "id": id,
}))
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("postgres: failed to unmarshal data: %w", err) return nil, fmt.Errorf("postgres: failed to unmarshal data: %w", err)
} }