Skip to content

Commit

Permalink
Default Field CRDT Type to LWW_Register
Browse files Browse the repository at this point in the history
Oddly, everywhere in our codebase apart from a single line in the P2P code hardcodes field CRDT Type to LWW_Register, even if FieldDescription.Typ is readily available.
  • Loading branch information
AndrewSisley committed Mar 27, 2023
1 parent 4d0f0e2 commit 687b0e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 44 deletions.
6 changes: 6 additions & 0 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ func (db *db) updateCollection(
field.ID = client.FieldID(i)
desc.Schema.Fields[i] = field
}

if field.Typ == client.NONE_CRDT {
// If no CRDT Type has been provided, default to LWW_REGISTER.
field.Typ = client.LWW_REGISTER
desc.Schema.Fields[i] = field
}
}

globalSchemaBuf, err := json.Marshal(desc.Schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ func TestP2PPeerCreateWithNewFieldSyncsDocsToNewerSchemaVersion(t *testing.T) {
testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

// Documentation test: This is undesirable behaviour and the test should be
// updated once the behaviour has been fixed.
// Issue: https://github.com/sourcenetwork/defradb/issues/1185
func TestP2PPeerCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
Expand Down Expand Up @@ -188,7 +185,6 @@ func TestP2PPeerCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T)
},
testUtils.WaitForSync{},
testUtils.Request{
NodeID: immutable.Some(0),
Request: `query {
Users {
Name
Expand All @@ -202,23 +198,6 @@ func TestP2PPeerCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T)
},
},
},
testUtils.Request{
// Even though 'Email' exists on both nodes, the value of the field has not
// successfully been synced.
NodeID: immutable.Some(1),
Request: `query {
Users {
Name
Email
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Email": nil,
},
},
},
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ func TestP2POneToOneReplicatorCreateWithNewFieldSyncsDocsToNewerSchemaVersion(t
testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

// Documentation test: This is undesirable behaviour and the test should be
// updated once the behaviour has been fixed.
// Issue: https://github.com/sourcenetwork/defradb/issues/1185
func TestP2POneToOneReplicatorCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
Expand Down Expand Up @@ -158,7 +155,6 @@ func TestP2POneToOneReplicatorCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(
},
testUtils.WaitForSync{},
testUtils.Request{
NodeID: immutable.Some(0),
Request: `query {
Users {
Name
Expand All @@ -172,23 +168,6 @@ func TestP2POneToOneReplicatorCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(
},
},
},
testUtils.Request{
// Even though 'Email' exists on both nodes, the value of the field has not
// successfully been synced.
NodeID: immutable.Some(1),
Request: `query {
Users {
Name
Email
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Email": nil,
},
},
},
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndVersionJoin(t *testing.T) {
initialSchemaVersionId := "bafkreicg3xcpjlt3ecguykpcjrdx5ogi4n7cq2fultyr6vippqdxnrny3u"
updatedSchemaVersionId := "bafkreicnj2kiq6vqxozxnhrc4mlbkdp5rr44awaetn5x5hcdymk6lxrxdy"
updatedSchemaVersionId := "bafkreicquhkxvwfzmjnoptu4cf5ib4tameu6wmq5wzwg3ooc32zqbvtif4"

test := testUtils.TestCase{
Description: "Test schema update, add field with update after schema update, verison join",
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndVersionJoi

func TestSchemaUpdatesAddFieldWithCreateWithUpdateAfterSchemaUpdateAndCommitQuery(t *testing.T) {
initialSchemaVersionId := "bafkreicg3xcpjlt3ecguykpcjrdx5ogi4n7cq2fultyr6vippqdxnrny3u"
updatedSchemaVersionId := "bafkreicnj2kiq6vqxozxnhrc4mlbkdp5rr44awaetn5x5hcdymk6lxrxdy"
updatedSchemaVersionId := "bafkreicquhkxvwfzmjnoptu4cf5ib4tameu6wmq5wzwg3ooc32zqbvtif4"

test := testUtils.TestCase{
Description: "Test schema update, add field with update after schema update, commits query",
Expand Down

0 comments on commit 687b0e8

Please sign in to comment.