Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] ovsdb: don't create sized arrays for OVS Sets #333

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
"github.com/ovn-org/libovsdb/test"
"github.com/ovn-org/libovsdb/test/helpers"
"github.com/ovn-org/libovsdb/updates"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -2037,7 +2038,8 @@ func BenchmarkPopulate2UpdateArray(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
for i := 0; i < numRows; i++ {
updatedRow := ovsdb.Row(map[string]interface{}{"array": ovsdb.OvsSet{GoSet: updateSet}})
ovsSet := testhelpers.MakeOvsSet(b, ovsdb.TypeString, updateSet)
updatedRow := ovsdb.Row(map[string]interface{}{"array": ovsSet})
err := tc.Populate2(ovsdb.TableUpdates2{
"Open_vSwitch": {
"foo": &ovsdb.RowUpdate2{
Expand Down Expand Up @@ -2714,7 +2716,7 @@ func BenchmarkPopulate2SingleModify(b *testing.B) {
UUID string `ovsdb:"_uuid"`
Set []string `ovsdb:"set"`
}
aFooSet, _ := ovsdb.NewOvsSet([]string{"foo"})
aFooSet, _ := ovsdb.NewOvsSet(ovsdb.TypeString, []string{"foo"})
base := &testDBModel{Set: []string{}}
for i := 0; i < 57000; i++ {
base.Set = append(base.Set, fmt.Sprintf("foo%d", i))
Expand Down
31 changes: 16 additions & 15 deletions client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ovn-org/libovsdb/cache"
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
"github.com/ovn-org/libovsdb/test/helpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -914,7 +915,7 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testOvsSet(t, []string{"1.1.1.1"})}},
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"1.1.1.1"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID0}}},
},
},
Expand All @@ -940,19 +941,19 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testOvsSet(t, []string{"2.2.2.2"})}},
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"2.2.2.2"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID0}}},
},
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testOvsSet(t, []string{"2.2.2.2"})}},
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"2.2.2.2"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID1}}},
},
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testOvsSet(t, []string{"2.2.2.2"})}},
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"2.2.2.2"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID2}}},
},
},
Expand All @@ -976,7 +977,7 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationDelete, Value: testOvsSet(t, []string{"foo"})}},
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationDelete, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"foo"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID2}}},
},
},
Expand All @@ -1000,7 +1001,7 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationDelete, Value: testOvsSet(t, []string{"foo"})}},
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationDelete, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeString, []string{"foo"})}},
Where: []ovsdb.Condition{{Column: "name", Function: ovsdb.ConditionEqual, Value: "foo"}},
},
},
Expand All @@ -1024,7 +1025,7 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testOvsMap(t, map[string]string{"bar": "baz"})}},
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsMap(t, map[string]string{"bar": "baz"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID2}}},
},
},
Expand All @@ -1048,13 +1049,13 @@ func TestAPIMutate(t *testing.T) {
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testOvsMap(t, map[string]string{"bar": "baz"})}},
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsMap(t, map[string]string{"bar": "baz"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID0}}},
},
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testOvsMap(t, map[string]string{"bar": "baz"})}},
Mutations: []ovsdb.Mutation{{Column: "external_ids", Mutator: ovsdb.MutateOperationInsert, Value: testhelpers.MakeOvsMap(t, map[string]string{"bar": "baz"})}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: aUUID1}}},
},
},
Expand Down Expand Up @@ -1136,10 +1137,10 @@ func TestAPIUpdate(t *testing.T) {
tcache := apiTestCache(t, testData)

testObj := testLogicalSwitchPort{}
testRow := ovsdb.Row(map[string]interface{}{"type": "somethingElse", "tag": testOvsSet(t, []int{6})})
tagRow := ovsdb.Row(map[string]interface{}{"tag": testOvsSet(t, []int{6})})
testRow := ovsdb.Row(map[string]interface{}{"type": "somethingElse", "tag": testhelpers.MakeOvsSet(t, ovsdb.TypeInteger, []int{6})})
tagRow := ovsdb.Row(map[string]interface{}{"tag": testhelpers.MakeOvsSet(t, ovsdb.TypeInteger, []int{6})})
var nilInt *int
testNilRow := ovsdb.Row(map[string]interface{}{"type": "somethingElse", "tag": testOvsSet(t, nilInt)})
testNilRow := ovsdb.Row(map[string]interface{}{"type": "somethingElse", "tag": testhelpers.MakeOvsSet(t, ovsdb.TypeInteger, nilInt)})
typeRow := ovsdb.Row(map[string]interface{}{"type": "somethingElse"})
fields := []interface{}{&testObj.Tag, &testObj.Type}

Expand Down Expand Up @@ -1350,7 +1351,7 @@ func TestAPIUpdate(t *testing.T) {
Row: tagRow,
Where: []ovsdb.Condition{
{Column: "type", Function: ovsdb.ConditionEqual, Value: "sometype"},
{Column: "enabled", Function: ovsdb.ConditionIncludes, Value: testOvsSet(t, &trueVal)},
{Column: "enabled", Function: ovsdb.ConditionIncludes, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeBoolean, &trueVal)},
},
},
},
Expand Down Expand Up @@ -1403,7 +1404,7 @@ func TestAPIUpdate(t *testing.T) {
Op: ovsdb.OperationUpdate,
Table: "Logical_Switch_Port",
Row: tagRow,
Where: []ovsdb.Condition{{Column: "tag", Function: ovsdb.ConditionNotEqual, Value: testOvsSet(t, &one)}},
Where: []ovsdb.Condition{{Column: "tag", Function: ovsdb.ConditionNotEqual, Value: testhelpers.MakeOvsSet(t, ovsdb.TypeInteger, &one)}},
},
},
err: false,
Expand Down Expand Up @@ -1944,7 +1945,7 @@ func TestAPIWait(t *testing.T) {
{
Column: "up",
Function: ovsdb.ConditionNotEqual,
Value: ovsdb.OvsSet{GoSet: []interface{}{true}},
Value: testhelpers.MakeOvsSet(t, ovsdb.TypeBoolean, []interface{}{true}),
},
},
Until: string(ovsdb.WaitConditionNotEqual),
Expand Down
14 changes: 1 addition & 13 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Bridge struct {
DatapathVersion string `ovsdb:"datapath_version"`
ExternalIDs map[string]string `ovsdb:"external_ids"`
FailMode *BridgeFailMode `ovsdb:"fail_mode"`
FloodVLANs [4096]int `ovsdb:"flood_vlans"`
FloodVLANs []int `ovsdb:"flood_vlans"`
FlowTables map[int]string `ovsdb:"flow_tables"`
IPFIX *string `ovsdb:"ipfix"`
McastSnoopingEnable bool `ovsdb:"mcast_snooping_enable"`
Expand Down Expand Up @@ -488,18 +488,6 @@ var schema = `{
}
}`

func testOvsSet(t *testing.T, set interface{}) ovsdb.OvsSet {
oSet, err := ovsdb.NewOvsSet(set)
assert.Nil(t, err)
return oSet
}

func testOvsMap(t *testing.T, set interface{}) ovsdb.OvsMap {
oMap, err := ovsdb.NewOvsMap(set)
assert.Nil(t, err)
return oMap
}

func updateBenchmark(ovs *ovsdbClient, updates []byte, b *testing.B) {
for n := 0; n < b.N; n++ {
params := []json.RawMessage{[]byte(`{"databaseName":"Open_vSwitch","id":"v1"}`), updates}
Expand Down
9 changes: 5 additions & 4 deletions client/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ovn-org/libovsdb/cache"
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
"github.com/ovn-org/libovsdb/test/helpers"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -330,7 +331,7 @@ func TestExplicitConditionalWithNoCache(t *testing.T) {
{
Column: "external_ids",
Function: ovsdb.ConditionIncludes,
Value: testOvsMap(t, map[string]string{"foo": "baz"}),
Value: testhelpers.MakeOvsMap(t, map[string]string{"foo": "baz"}),
}}},
},
{
Expand All @@ -347,7 +348,7 @@ func TestExplicitConditionalWithNoCache(t *testing.T) {
{
Column: "enabled",
Function: ovsdb.ConditionEqual,
Value: testOvsSet(t, &trueVal),
Value: testhelpers.MakeOvsSet(t, ovsdb.TypeBoolean, &trueVal),
}}},
},
{
Expand All @@ -369,7 +370,7 @@ func TestExplicitConditionalWithNoCache(t *testing.T) {
{
Column: "enabled",
Function: ovsdb.ConditionEqual,
Value: testOvsSet(t, &trueVal),
Value: testhelpers.MakeOvsSet(t, ovsdb.TypeBoolean, &trueVal),
}},
{
{
Expand All @@ -396,7 +397,7 @@ func TestExplicitConditionalWithNoCache(t *testing.T) {
{
Column: "enabled",
Function: ovsdb.ConditionEqual,
Value: testOvsSet(t, &trueVal),
Value: testhelpers.MakeOvsSet(t, ovsdb.TypeBoolean, &trueVal),
},
{
Column: "name",
Expand Down
Loading