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

This commit is contained in:
Caleb Doxsey 2023-01-09 15:10:52 -07:00 committed by GitHub
parent 9677e18bbd
commit 92b50683ff
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")
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) {
_, err := storage.RecordStreamToList(stream)
records, err := storage.RecordStreamToList(stream)
assert.NoError(t, err)
assert.Len(t, records, 1)
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) {
for {
var recordID string
var version uint64
var data []byte
@ -123,12 +122,12 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
} else if err != nil {
return nil, fmt.Errorf("error querying next changed record: %w", err)
}
afterRecordVersion = version
any, err := protoutil.UnmarshalAnyJSON(data)
if isUnknownType(err) {
// ignore
continue
any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
"id": recordID,
}))
} else if err != nil {
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),
DeletedAt: timestamppbFromTimestamptz(deletedAt),
}, nil
}
}
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)
if isUnknownType(err) {
// ignore records with an unknown type
continue
any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
"id": id,
}))
} else if err != nil {
return nil, fmt.Errorf("postgres: failed to unmarshal data: %w", err)
}