Skip to content

Conversation

giorio94
Copy link
Member

Currently, the information about the last WriteTxn is not reported correctly, as the internal variables are reset once a transaction gets committed or aborted. Let's get this fixed by only resetting the other fields, and add a new unit test to prevent regressions.

Currently, the information about the last WriteTxn is not reported
correctly, as the internal variables are reset once a transaction
gets committed or aborted. Let's get this fixed by only resetting
the other fields, and add a new unit test to prevent regressions.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 requested a review from a team as a code owner July 25, 2025 13:27
@giorio94 giorio94 requested review from derailed and joamaki and removed request for a team July 25, 2025 13:27
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 golang.org/x/text v0.14.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 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.715s	coverage: 83.5% of statements
ok  	github.com/cilium/statedb/index	0.005s	coverage: 28.7% of statements
ok  	github.com/cilium/statedb/internal	0.016s	coverage: 46.7% of statements
ok  	github.com/cilium/statedb/part	4.613s	coverage: 87.6% of statements
ok  	github.com/cilium/statedb/reconciler	0.246s	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	93.793s
ok  	github.com/cilium/statedb/index	1.014s
ok  	github.com/cilium/statedb/internal	1.025s
ok  	github.com/cilium/statedb/part	34.655s
ok  	github.com/cilium/statedb/reconciler	1.326s
?   	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                    	  530000	      2210 ns/op	    452472 objects/sec	    1448 B/op	      26 allocs/op
BenchmarkDB_WriteTxn_10-4                   	 1440309	       834.8 ns/op	   1197822 objects/sec	     513 B/op	       9 allocs/op
BenchmarkDB_WriteTxn_100-4                  	 1914282	       628.6 ns/op	   1590817 objects/sec	     431 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                 	 1770253	       676.2 ns/op	   1478840 objects/sec	     391 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4   	  566842	      1987 ns/op	    503288 objects/sec	    1258 B/op	      37 allocs/op
BenchmarkDB_NewWriteTxn-4                   	 1393648	       842.9 ns/op	     544 B/op	       8 allocs/op
BenchmarkDB_NewReadTxn-4                    	482006553	         2.489 ns/op	       0 B/op	       0 allocs/op
BenchmarkDB_Modify-4                        	    1623	    746011 ns/op	   1340463 objects/sec	  446569 B/op	    8136 allocs/op
BenchmarkDB_GetInsert-4                     	    1506	    821456 ns/op	   1217351 objects/sec	  430167 B/op	    8136 allocs/op
BenchmarkDB_RandomInsert-4                  	    1789	    684953 ns/op	   1459955 objects/sec	  422495 B/op	    7136 allocs/op
BenchmarkDB_RandomReplace-4                 	     374	   3213972 ns/op	    311141 objects/sec	 2023155 B/op	   49160 allocs/op
BenchmarkDB_SequentialInsert-4              	    1834	    676705 ns/op	   1477749 objects/sec	  391482 B/op	    7110 allocs/op
BenchmarkDB_SequentialInsert_Prefix-4       	     404	   2984536 ns/op	    335061 objects/sec	 3750165 B/op	   58568 allocs/op
BenchmarkDB_Changes_Baseline-4              	    1303	    855494 ns/op	   1168915 objects/sec	  465705 B/op	   10214 allocs/op
BenchmarkDB_Changes-4                       	     802	   1493536 ns/op	    669552 objects/sec	  819906 B/op	   14420 allocs/op
BenchmarkDB_RandomLookup-4                  	   21180	     56640 ns/op	  17655358 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_SequentialLookup-4              	   24715	     48493 ns/op	  20621399 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_Prefix_SecondaryIndex-4         	    6796	    167706 ns/op	   5962829 objects/sec	  125114 B/op	    1031 allocs/op
BenchmarkDB_FullIteration_All-4             	    1062	   1181805 ns/op	  84616299 objects/sec	     320 B/op	      11 allocs/op
BenchmarkDB_FullIteration_Get-4             	     202	   5984567 ns/op	  16709646 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_ReadTxnGet-4      	     199	   5953775 ns/op	  16796067 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4              	  584434	      1993 ns/op	        17.00 50th_µs	        20.00 90th_µs	        43.00 99th_µs	    1133 B/op	      22 allocs/op
BenchmarkWatchSet_4-4                       	 1309809	       923.2 ns/op	     500 B/op	       8 allocs/op
BenchmarkWatchSet_16-4                      	  506062	      2419 ns/op	    1699 B/op	       8 allocs/op
BenchmarkWatchSet_128-4                     	   57832	     19520 ns/op	   13398 B/op	       8 allocs/op
BenchmarkWatchSet_1024-4                    	    6112	    190105 ns/op	  104754 B/op	       8 allocs/op
PASS
ok  	github.com/cilium/statedb	33.646s
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        	    1293	    898248 ns/op	   1113278 items/sec	 2813223 B/op	   11035 allocs/op
Benchmark_Uint64Map_Sequential-4    	    1435	    841534 ns/op	   1188306 items/sec	 2591250 B/op	   11749 allocs/op
Benchmark_Insert_RootOnlyWatch-4    	   10000	    115206 ns/op	   8680084 objects/sec	   90621 B/op	    2044 allocs/op
Benchmark_Insert-4                  	    7006	    172157 ns/op	   5808641 objects/sec	  206592 B/op	    3076 allocs/op
Benchmark_Modify-4                  	   10000	    110560 ns/op	   9044837 objects/sec	  122204 B/op	    1052 allocs/op
Benchmark_GetInsert-4               	    7686	    150336 ns/op	   6651747 objects/sec	  122328 B/op	    1052 allocs/op
Benchmark_Replace-4                 	27411652	        43.65 ns/op	  22907906 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Replace_RootOnlyWatch-4   	27271753	        43.60 ns/op	  22934041 objects/sec	       0 B/op	       0 allocs/op
Benchmark_txn_1-4                   	 3275655	       366.3 ns/op	   2730221 objects/sec	     296 B/op	       5 allocs/op
Benchmark_txn_10-4                  	 8548117	       138.4 ns/op	   7226193 objects/sec	     113 B/op	       2 allocs/op
Benchmark_txn_100-4                 	10461093	       114.6 ns/op	   8727687 objects/sec	     130 B/op	       2 allocs/op
Benchmark_txn_1000-4                	 9109138	       128.1 ns/op	   7809125 objects/sec	     126 B/op	       2 allocs/op
Benchmark_txn_delete_1-4            	 1565482	       777.3 ns/op	   1286428 objects/sec	    3272 B/op	       8 allocs/op
Benchmark_txn_delete_10-4           	 7342156	       163.1 ns/op	   6132532 objects/sec	     368 B/op	       2 allocs/op
Benchmark_txn_delete_100-4          	11428250	       104.2 ns/op	   9596302 objects/sec	      82 B/op	       1 allocs/op
Benchmark_txn_delete_1000-4         	12166605	        97.99 ns/op	  10204897 objects/sec	      28 B/op	       1 allocs/op
Benchmark_Get-4                     	   34072	     35170 ns/op	  28433050 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterate-4                 	  171189	      7240 ns/op	 138115102 objects/sec	     104 B/op	       4 allocs/op
Benchmark_Hashmap_Insert-4          	   14864	     80752 ns/op	  12383529 objects/sec	   74265 B/op	      20 allocs/op
Benchmark_Hashmap_Get_Uint64-4      	  140041	      8611 ns/op	 116128417 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Hashmap_Get_Bytes-4       	  111090	     10786 ns/op	  92716406 objects/sec	       0 B/op	       0 allocs/op
PASS
ok  	github.com/cilium/statedb/part	26.905s
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.49 seconds (batch size 1000)
Throughput 401007.91 objects per second
1226MB total allocated, 6011107 in-use objects, 384MB bytes in use

@joamaki joamaki merged commit 15ea701 into main Jul 28, 2025
1 check passed
@joamaki joamaki deleted the pr/giorio94/fix-last-write-txn branch July 28, 2025 08:53
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