Skip to content
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
2 changes: 1 addition & 1 deletion cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cache

import (
"encoding/json"
"fmt"
"math/rand"
"testing"

"github.com/go-logr/logr"
"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/ovn-kubernetes/libovsdb/test"
Expand Down
2 changes: 1 addition & 1 deletion client/api_test_model.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package client

import (
"encoding/json"
"testing"

"github.com/ovn-kubernetes/libovsdb/cache"
"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"net"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/cenkalti/rpc2/jsonrpc"
"github.com/go-logr/logr"
"github.com/ovn-kubernetes/libovsdb/cache"
"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/mapper"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"math/rand"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/google/uuid"
"github.com/ovn-kubernetes/libovsdb/cache"
"github.com/ovn-kubernetes/libovsdb/database/inmemory"
"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/mapper"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
Expand Down
2 changes: 1 addition & 1 deletion client/monitor_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
"encoding/json"
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion cmd/modelgen/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/modelgen"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/print_schema/print_schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io"
Expand All @@ -10,6 +9,7 @@ import (
"runtime"
"runtime/pprof"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
)

Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/ovn-kubernetes/libovsdb
go 1.23.0

require (
github.com/bytedance/sonic v1.14.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/cenkalti/rpc2 v1.0.4
github.com/go-logr/logr v1.4.3
Expand All @@ -21,8 +22,10 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cenkalti/hub v1.0.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/containerd/continuity v0.4.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v27.4.1+incompatible // indirect
Expand All @@ -35,6 +38,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand All @@ -50,9 +54,11 @@ require (
github.com/prometheus/common v0.65.0 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
Expand Down
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/hub v1.0.2 h1:Nqv9TNaA9boeO2wQFW8o87BY3zKthtnzXmWGmJqhAV8=
Expand All @@ -18,6 +23,9 @@ github.com/cenkalti/rpc2 v1.0.4 h1:MJWmm7mbt8r/ZkQS+qr/e2KMMrhMLPr/62CYZIHybdI=
github.com/cenkalti/rpc2 v1.0.4/go.mod h1:2yfU5b86vOr16+iY1jN3MvT6Kxc9Nf8j5iZWwUf7iaw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -63,6 +71,9 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -104,10 +115,17 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand All @@ -119,6 +137,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down Expand Up @@ -166,3 +186,4 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
67 changes: 67 additions & 0 deletions internal/json/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package json_test

import (
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
)

func benchmarkSetMarshalJSON(s []ovsdb.Operation, b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := json.Marshal(s)
if err != nil {
b.Fatal(err)
}
}
}

func operationDataset(n int) []ovsdb.Operation {
var result []ovsdb.Operation
oSet, _ := ovsdb.NewOvsSet([]string{"1.1.1.1"})
var testOperations = []ovsdb.Operation{
{
Op: ovsdb.OperationMutate,
Table: "Logical_Switch_Port",
Mutations: []ovsdb.Mutation{{Column: "addresses", Mutator: ovsdb.MutateOperationInsert, Value: oSet}},
Where: []ovsdb.Condition{{Column: "_uuid", Function: ovsdb.ConditionEqual, Value: ovsdb.UUID{GoUUID: "9ea1d0f7-e389-48a3-9563-fcf1a80fdb1e"}}},
},
}
for range n {
result = append(result, testOperations...)
}
return result
}

func BenchmarkSetMarshalJSONOperations1(b *testing.B) {
benchmarkSetMarshalJSON(operationDataset(1), b)
}
func BenchmarkSetMarshalJSONOperations2(b *testing.B) {
benchmarkSetMarshalJSON(operationDataset(2), b)
}
func BenchmarkSetMarshalJSONOperations3(b *testing.B) {
benchmarkSetMarshalJSON(operationDataset(3), b)
}
func BenchmarkSetMarshalJSONOperations5(b *testing.B) {
benchmarkSetMarshalJSON(operationDataset(5), b)
}
func BenchmarkSetMarshalJSONOperations8(b *testing.B) {
benchmarkSetMarshalJSON(operationDataset(8), b)
}

func benchmarkSetUnmarshalJSON(data []byte, b *testing.B) {
for n := 0; n < b.N; n++ {
var s ovsdb.TableUpdate2
err := json.Unmarshal(data, &s)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkSetUnmarshalJSONTableUpdate1(b *testing.B) {
benchmarkSetUnmarshalJSON([]byte(`{"Port_Binding":{"77189bff-b4e3-4c15-9967-4518036b9a11":{"modify":{"virtual_parent":"06:73:24:4c:a3:97~2024-09-25 08:02:04.295"}}}}`), b)
}
func BenchmarkSetUnmarshalJSONTableUpdate2(b *testing.B) {
benchmarkSetUnmarshalJSON([]byte(`{"Port_Binding":{"77189bff-b4e3-4c15-9967-4518036b9a11":{"modify":{"virtual_parent":"06:73:24:4c:a3:97~2024-09-25 08:02:04.295","tag":["set",[]]}}}}`), b)
}
12 changes: 12 additions & 0 deletions internal/json/sonic_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package json

import (
"github.com/bytedance/sonic"
)

var (
Marshal = sonic.Marshal
Unmarshal = sonic.Unmarshal
)

type RawMessage = sonic.NoCopyRawMessage
2 changes: 1 addition & 1 deletion mapper/info_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mapper

import (
"encoding/json"
"fmt"
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion mapper/mapper_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mapper

import (
"encoding/json"
"fmt"
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package model

import (
"encoding/json"
"fmt"
"reflect"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
)

Expand Down
2 changes: 1 addition & 1 deletion model/model_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package model

import (
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion modelgen/dbmodel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modelgen/table_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package modelgen

import (
"encoding/json"
"fmt"
"reflect"
"testing"
"text/template"

"github.com/google/uuid"
"github.com/ovn-kubernetes/libovsdb/example/vswitchd"
"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/ovn-kubernetes/libovsdb/model"
"github.com/ovn-kubernetes/libovsdb/ovsdb"
"github.com/stretchr/testify/assert"
Expand Down
6 changes: 3 additions & 3 deletions ovsdb/bindings_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ovsdb

import (
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/ovn-kubernetes/libovsdb/internal/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -705,7 +705,7 @@ func TestOvsToNativeErr(t *testing.T) {
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf(tt.name), func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var column ColumnSchema
err := json.Unmarshal(tt.schema, &column)
require.NoError(t, err)
Expand Down Expand Up @@ -782,7 +782,7 @@ func TestNativeToOvsErr(t *testing.T) {
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf(tt.name), func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var column ColumnSchema
if err := json.Unmarshal(tt.schema, &column); err != nil {
t.Fatal(err)
Expand Down
Loading
Loading