databroker: refactor databroker to sync all changes (#1879)

* refactor backend, implement encrypted store

* refactor in-memory store

* wip

* wip

* wip

* add syncer test

* fix redis expiry

* fix linting issues

* fix test by skipping non-config records

* fix backoff import

* fix init issues

* fix query

* wait for initial sync before starting directory sync

* add type to SyncLatest

* add more log messages, fix deadlock in in-memory store, always return server version from SyncLatest

* update sync types and tests

* add redis tests

* skip macos in github actions

* add comments to proto

* split getBackend into separate methods

* handle errors in initVersion

* return different error for not found vs other errors in get

* use exponential backoff for redis transaction retry

* rename raw to result

* use context instead of close channel

* store type urls as constants in databroker

* use timestampb instead of ptypes

* fix group merging not waiting

* change locked names

* update GetAll to return latest record version

* add method to grpcutil to get the type url for a protobuf type
This commit is contained in:
Caleb Doxsey 2021-02-18 15:24:33 -07:00 committed by GitHub
parent b1871b0f2e
commit 5d60cff21e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 2762 additions and 2871 deletions

View file

@ -18,11 +18,11 @@ func TestEncryptedBackend(t *testing.T) {
m := map[string]*anypb.Any{}
backend := &mockBackend{
put: func(ctx context.Context, id string, data *anypb.Any) error {
m[id] = data
put: func(ctx context.Context, record *databroker.Record) error {
m[record.GetId()] = record.GetData()
return nil
},
get: func(ctx context.Context, id string) (*databroker.Record, error) {
get: func(ctx context.Context, recordType, id string) (*databroker.Record, error) {
data, ok := m[id]
if !ok {
return nil, errors.New("not found")
@ -32,7 +32,7 @@ func TestEncryptedBackend(t *testing.T) {
Data: data,
}, nil
},
getAll: func(ctx context.Context) ([]*databroker.Record, error) {
getAll: func(ctx context.Context) ([]*databroker.Record, uint64, error) {
var records []*databroker.Record
for id, data := range m {
records = append(records, &databroker.Record{
@ -40,17 +40,7 @@ func TestEncryptedBackend(t *testing.T) {
Data: data,
})
}
return records, nil
},
list: func(ctx context.Context, sinceVersion string) ([]*databroker.Record, error) {
var records []*databroker.Record
for id, data := range m {
records = append(records, &databroker.Record{
Id: id,
Data: data,
})
}
return records, nil
return records, 0, nil
},
}
@ -61,7 +51,11 @@ func TestEncryptedBackend(t *testing.T) {
any, _ := anypb.New(wrapperspb.String("HELLO WORLD"))
err = e.Put(ctx, "TEST-1", any)
err = e.Put(ctx, &databroker.Record{
Type: "",
Id: "TEST-1",
Data: any,
})
if !assert.NoError(t, err) {
return
}
@ -70,7 +64,7 @@ func TestEncryptedBackend(t *testing.T) {
assert.NotEqual(t, any.Value, m["TEST-1"].Value, "value should be encrypted")
}
record, err := e.Get(ctx, "TEST-1")
record, err := e.Get(ctx, "", "TEST-1")
if !assert.NoError(t, err) {
return
}
@ -78,17 +72,7 @@ func TestEncryptedBackend(t *testing.T) {
assert.Equal(t, any.Value, record.Data.Value, "value should be preserved")
assert.Equal(t, any.TypeUrl, record.Type, "record type should be preserved")
records, err := e.List(ctx, "")
if !assert.NoError(t, err) {
return
}
if assert.Len(t, records, 1) {
assert.Equal(t, any.TypeUrl, records[0].Data.TypeUrl, "type should be preserved")
assert.Equal(t, any.Value, records[0].Data.Value, "value should be preserved")
assert.Equal(t, any.TypeUrl, records[0].Type, "record type should be preserved")
}
records, err = e.List(ctx, "")
records, _, err := e.GetAll(ctx)
if !assert.NoError(t, err) {
return
}