Skip to content

statedb: Add TableWritable as constraint on NewTable, add NewTableAny #100

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

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Jul 31, 2025

Let's start enforcing the TableWritable on the tables so we have proper "db/show" output for all tables.

To make it possible to have StateDB tables without having to introduce a wrapper type for types we don't control add a NewTableAny constructor which takes TableHeader() and TableRow() as arguments.

Let's start enforcing the TableWritable on the tables so we have proper
"db/show" output for all tables.

To make it possible to have StateDB tables without having to introduce
a wrapper type for types we don't control add a NewTableAny constructor
which takes TableHeader() and TableRow() as arguments.

Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
@joamaki joamaki requested a review from a team as a code owner July 31, 2025 12:38
@joamaki joamaki requested review from derailed and removed request for a team July 31, 2025 12:38
Copy link

$ make
go build ./...
go: downloading go1.24.0 (linux/amd64)
go: downloading go.yaml.in/yaml/v3 v3.0.3
go: downloading github.com/cilium/hive v0.0.0-20250522123230-2946c4940f41
go: downloading golang.org/x/time v0.5.0
go: downloading github.com/spf13/cobra v1.8.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/cilium/stream v0.0.0-20240209152734-a0792b51812d
go: downloading github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
go: downloading github.com/spf13/viper v1.18.2
go: downloading go.uber.org/dig v1.17.1
go: downloading golang.org/x/term v0.16.0
go: downloading github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
go: downloading github.com/go-viper/mapstructure/v2 v2.2.1
go: downloading golang.org/x/sys v0.17.0
go: downloading golang.org/x/tools v0.17.0
go: downloading github.com/spf13/cast v1.6.0
go: downloading github.com/fsnotify/fsnotify v1.7.0
go: downloading github.com/mitchellh/mapstructure v1.5.0
go: downloading github.com/sagikazarmark/slog-shim v0.1.0
go: downloading github.com/spf13/afero v1.11.0
go: downloading github.com/subosito/gotenv v1.6.0
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading gopkg.in/ini.v1 v1.67.0
go: downloading github.com/magiconair/properties v1.8.7
go: downloading github.com/pelletier/go-toml/v2 v2.1.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading golang.org/x/text v0.14.0
go test ./... -cover -vet=all -test.count 1
go: downloading github.com/stretchr/testify v1.8.4
go: downloading go.uber.org/goleak v1.3.0
go: downloading golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
go: downloading github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
ok  	github.com/cilium/statedb	21.902s	coverage: 83.5% of statements
ok  	github.com/cilium/statedb/index	0.007s	coverage: 28.7% of statements
ok  	github.com/cilium/statedb/internal	0.024s	coverage: 46.7% of statements
ok  	github.com/cilium/statedb/part	4.863s	coverage: 87.6% of statements
ok  	github.com/cilium/statedb/reconciler	0.278s	coverage: 88.9% of statements
	github.com/cilium/statedb/reconciler/benchmark		coverage: 0.0% of statements
	github.com/cilium/statedb/reconciler/example		coverage: 0.0% of statements
go test -race ./... -test.count 1
ok  	github.com/cilium/statedb	99.824s
ok  	github.com/cilium/statedb/index	1.014s
ok  	github.com/cilium/statedb/internal	1.023s
ok  	github.com/cilium/statedb/part	34.780s
ok  	github.com/cilium/statedb/reconciler	1.294s
?   	github.com/cilium/statedb/reconciler/benchmark	[no test files]
?   	github.com/cilium/statedb/reconciler/example	[no test files]
go test ./... -bench . -benchmem -test.run xxx
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkDB_WriteTxn_1-4                    	  527271	      2219 ns/op	    450728 objects/sec	    1416 B/op	      26 allocs/op
BenchmarkDB_WriteTxn_10-4                   	 1316934	       847.9 ns/op	   1179332 objects/sec	     481 B/op	       9 allocs/op
BenchmarkDB_WriteTxn_100-4                  	 1854493	       631.6 ns/op	   1583379 objects/sec	     400 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                 	 1797454	       667.9 ns/op	   1497241 objects/sec	     364 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4   	  563070	      2038 ns/op	    490744 objects/sec	    1212 B/op	      37 allocs/op
BenchmarkDB_NewWriteTxn-4                   	 1493865	       802.4 ns/op	     544 B/op	       8 allocs/op
BenchmarkDB_NewReadTxn-4                    	480655815	         2.491 ns/op	       0 B/op	       0 allocs/op
BenchmarkDB_Modify-4                        	    1640	    733312 ns/op	   1363677 objects/sec	  423920 B/op	    8144 allocs/op
BenchmarkDB_GetInsert-4                     	    1494	    836541 ns/op	   1195399 objects/sec	  404936 B/op	    8140 allocs/op
BenchmarkDB_RandomInsert-4                  	    1741	    696740 ns/op	   1435256 objects/sec	  396712 B/op	    7140 allocs/op
BenchmarkDB_RandomReplace-4                 	     368	   3258042 ns/op	    306933 objects/sec	 1976862 B/op	   49162 allocs/op
BenchmarkDB_SequentialInsert-4              	    1849	    665138 ns/op	   1503447 objects/sec	  363845 B/op	    7114 allocs/op
BenchmarkDB_SequentialInsert_Prefix-4       	     393	   2994135 ns/op	    333986 objects/sec	 3718033 B/op	   58568 allocs/op
BenchmarkDB_Changes_Baseline-4              	    1398	    856021 ns/op	   1168195 objects/sec	  433531 B/op	   10214 allocs/op
BenchmarkDB_Changes-4                       	     810	   1491527 ns/op	    670454 objects/sec	  755790 B/op	   14420 allocs/op
BenchmarkDB_RandomLookup-4                  	   21661	     55464 ns/op	  18029596 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_SequentialLookup-4              	   24830	     48351 ns/op	  20682024 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_Prefix_SecondaryIndex-4         	    6898	    162347 ns/op	   6159660 objects/sec	  125114 B/op	    1031 allocs/op
BenchmarkDB_FullIteration_All-4             	    1158	   1046532 ns/op	  95553714 objects/sec	     320 B/op	      11 allocs/op
BenchmarkDB_FullIteration_Get-4             	     200	   5955845 ns/op	  16790228 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_ReadTxnGet-4      	     201	   5928611 ns/op	  16867356 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4              	  581269	      2014 ns/op	        18.00 50th_µs	        20.00 90th_µs	        42.00 99th_µs	    1070 B/op	      22 allocs/op
BenchmarkWatchSet_4-4                       	 1321648	       907.6 ns/op	     500 B/op	       8 allocs/op
BenchmarkWatchSet_16-4                      	  509336	      2406 ns/op	    1700 B/op	       8 allocs/op
BenchmarkWatchSet_128-4                     	   61879	     19264 ns/op	   13387 B/op	       8 allocs/op
BenchmarkWatchSet_1024-4                    	    5930	    190403 ns/op	  105252 B/op	       8 allocs/op
PASS
ok  	github.com/cilium/statedb	33.641s
PASS
ok  	github.com/cilium/statedb/index	0.003s
PASS
ok  	github.com/cilium/statedb/internal	0.003s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/part
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark_Uint64Map_Random-4        	    1292	    898114 ns/op	   1113444 items/sec	 2809068 B/op	   11026 allocs/op
Benchmark_Uint64Map_Sequential-4    	    1422	    840026 ns/op	   1190439 items/sec	 2591251 B/op	   11749 allocs/op
Benchmark_Insert_RootOnlyWatch-4    	    9938	    120229 ns/op	   8317484 objects/sec	   74539 B/op	    2044 allocs/op
Benchmark_Insert-4                  	    6874	    176297 ns/op	   5672237 objects/sec	  190508 B/op	    3076 allocs/op
Benchmark_Modify-4                  	   12043	     99579 ns/op	  10042231 objects/sec	   72001 B/op	    1028 allocs/op
Benchmark_GetInsert-4               	    8337	    143027 ns/op	   6991705 objects/sec	   72012 B/op	    1028 allocs/op
Benchmark_Replace-4                 	27825145	        42.98 ns/op	  23265070 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Replace_RootOnlyWatch-4   	27824517	        43.32 ns/op	  23084368 objects/sec	       0 B/op	       0 allocs/op
Benchmark_txn_1-4                   	 3243650	       370.3 ns/op	   2700602 objects/sec	     280 B/op	       5 allocs/op
Benchmark_txn_10-4                  	 8392411	       140.1 ns/op	   7135831 objects/sec	      97 B/op	       2 allocs/op
Benchmark_txn_100-4                 	10400574	       114.8 ns/op	   8707461 objects/sec	      91 B/op	       2 allocs/op
Benchmark_txn_1000-4                	 9478424	       124.8 ns/op	   8014967 objects/sec	      78 B/op	       2 allocs/op
Benchmark_txn_delete_1-4            	 1523386	       790.7 ns/op	   1264698 objects/sec	    3272 B/op	       8 allocs/op
Benchmark_txn_delete_10-4           	 7162620	       168.3 ns/op	   5940458 objects/sec	     368 B/op	       2 allocs/op
Benchmark_txn_delete_100-4          	11117978	       107.8 ns/op	   9279916 objects/sec	      83 B/op	       1 allocs/op
Benchmark_txn_delete_1000-4         	11825062	       100.9 ns/op	   9915460 objects/sec	      28 B/op	       1 allocs/op
Benchmark_Get-4                     	   33285	     36138 ns/op	  27671765 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterate-4                 	  170793	      7603 ns/op	 131531379 objects/sec	     104 B/op	       4 allocs/op
Benchmark_Hashmap_Insert-4          	   14902	     80518 ns/op	  12419618 objects/sec	   74265 B/op	      20 allocs/op
Benchmark_Hashmap_Get_Uint64-4      	  136294	      8795 ns/op	 113703095 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Hashmap_Get_Bytes-4       	  112154	     10759 ns/op	  92942996 objects/sec	       0 B/op	       0 allocs/op
PASS
ok  	github.com/cilium/statedb/part	27.192s
PASS
ok  	github.com/cilium/statedb/reconciler	0.004s
?   	github.com/cilium/statedb/reconciler/benchmark	[no test files]
?   	github.com/cilium/statedb/reconciler/example	[no test files]
go run ./reconciler/benchmark -quiet
1000000 objects reconciled in 2.45 seconds (batch size 1000)
Throughput 407790.66 objects per second
1167MB total allocated, 6011119 in-use objects, 353MB bytes in use

@joamaki joamaki requested a review from giorio94 July 31, 2025 12:53
Copy link
Member

@giorio94 giorio94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@joamaki joamaki merged commit 7039507 into main Jul 31, 2025
1 check passed
@joamaki joamaki deleted the pr/joamaki/newtable-tablewritable-constraint branch July 31, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants