45 Commits
Author SHA1 Message Date
Chun-Hung Tseng f5912263cc Add missing watch response header
Signed-off-by: Chun-Hung Tseng <henrytseng@google.com>
2026-05-20 16:14:19 +08:00
Wei Fu df2b18b65d *: switch to new protobuf struct
goos: linux
goarch: amd64
pkg: go.etcd.io/etcd/server/v3/etcdserver/txn
cpu: AMD Ryzen 7 5800H with Radeon Graphics
                                       │ /tmp/etcd-main-benchmark-warn-protosize.txt │ /tmp/etcd-current-benchmark-warn-protosize.txt │
                                       │                   sec/op                    │         sec/op          vs base                │
WarnOfExpensiveRequestWithProtoSize-16                                   3.530µ ± 1%              2.785µ ± 2%  -21.12% (p=0.000 n=10)

                                       │ /tmp/etcd-main-benchmark-warn-protosize.txt │ /tmp/etcd-current-benchmark-warn-protosize.txt │
                                       │                    B/op                     │          B/op           vs base                │
WarnOfExpensiveRequestWithProtoSize-16                                  1.822Ki ± 0%             1.315Ki ± 0%  -27.81% (p=0.000 n=10)

                                       │ /tmp/etcd-main-benchmark-warn-protosize.txt │ /tmp/etcd-current-benchmark-warn-protosize.txt │
                                       │                  allocs/op                  │       allocs/op         vs base                │
WarnOfExpensiveRequestWithProtoSize-16                                    15.00 ± 0%               28.00 ± 0%  +86.67% (p=0.000 n=10)

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-15 10:59:37 -04:00
Wei Fu c790e524da server/proxy/grpcproxy: clone or copy instead of assignment copy
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-11 16:23:26 -04:00
Wei Fu 50a472ee61 mvcc/watch: switch gogopb kv/event paths to pointer slices
stop passing mvcc gogopb structs around by value in txn/watch paths.

- change mvcc interfaces/results to pointer forms:
  - RangeResult.KVs: []mvccpb.KeyValue -> []*mvccpb.KeyValue
  - TxnWrite.Changes: []mvccpb.KeyValue -> []*mvccpb.KeyValue
  - watch event batches: []mvccpb.Event -> []*mvccpb.Event
- update txn rpc assembly to reuse pointers directly instead of &slice[i] copies
- update watch send/filter pipeline (mvcc, v3rpc, grpcproxy) to pointer events
- update sendFragments to build per-fragment WatchResponse explicitly (avoid proto struct value copy)
  - add TestWatchResponseProtoFieldCount to catch future WatchResponse field additions
- adjust compare/filter helpers to pointer args
- update affected mvcc/watch tests accordingly

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-11 14:51:50 -04:00
Wei Fu 2214d9f136 client/v3: move Event helper methods into pb package
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-06 07:13:09 -04:00
Wei Fu 36d0f9ac8d client/v3: use pointer header in WatchResponse
Keep close/progress responses safe by always providing a non-nil header,
and update downstream users to match pointer semantics:

- cache demux progress responses
- concurrency election observe path
- grpcproxy watcher/watch cancel path
- etcdctl watch printers

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-05 10:08:54 -04:00
Wei FuandJordan Liggitt 160684ae08 client/v3: switch to pointer for clientv3.Cmp
Add client/v3/internal/pb/clone.go as a temporary gogo clone helper,
keep clone boundaries when txn/op code retains compare state, and update
the namespace/leasing/grpcproxy/etcdctl/robustness paths to use the new
representation.

----

It uses `Cmp` to hide the underlying pointer, so any modifications must go
through the exported methods.

There are two major changes:

* Users can no longer construct a `Cmp` value with a composite literal such as
  `Cmp{key: value}`.

* The original implementation only performed a shadow copy. The new change
  performs a deep copy of `Key []byte` and `RangeEnd []byte`.

The original implementation does not copy `Cmp` in these three functions.
This change performs a deep copy of `Cmp` in all three functions.

* (clientv3.txn).If
* (clientv3.Op).toTxnRequest
* (clientv3).OpTxn

Within Kubernetes, kube-apiserver uses `Cmp` when performing `OptimisticPut`,
`OptimisticDelete`, and updating `compactRevKey`.

Based on the benchmark results, which still use gogo-generated protobuf
structs, simply passing values instead of performing a deep copy does not seem
to have a significant impact. Anyway, Let's use deep copy first.

```
goos: linux
goarch: amd64
pkg: go.etcd.io/etcd/client/v3
cpu: AMD Ryzen 7 5800H with Radeon Graphics
			     │ /tmp/bench-old.txt │           /tmp/bench-new.txt            │    /tmp/bench-new-without-clone.txt     │
			     │       sec/op       │    sec/op      vs base                  │    sec/op      vs base                  │
TxnIfSingleCmp-16                          160.6n ± ∞ ¹   1383.0n ± ∞ ¹         ~ (p=1.000 n=1) ²    643.2n ± ∞ ¹         ~ (p=1.000 n=1) ²
KubernetesOptimisticPutTxnBuild-16         953.5n ± ∞ ¹   2286.0n ± ∞ ¹         ~ (p=1.000 n=1) ²   1494.0n ± ∞ ¹         ~ (p=1.000 n=1) ²
OpTxnSingleCmpToTxnRequest-16              880.1n ± ∞ ¹   2794.0n ± ∞ ¹         ~ (p=1.000 n=1) ²   1247.0n ± ∞ ¹         ~ (p=1.000 n=1) ²
geomean                                    512.7n          2.067µ        +303.19%                    1.062µ        +107.17%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

			     │ /tmp/bench-old.txt │           /tmp/bench-new.txt           │   /tmp/bench-new-without-clone.txt    │
			     │        B/op        │     B/op       vs base                 │     B/op       vs base                │
TxnIfSingleCmp-16                           304.0 ± ∞ ¹     600.0 ± ∞ ¹        ~ (p=1.000 n=1) ²     448.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
KubernetesOptimisticPutTxnBuild-16        2.008Ki ± ∞ ¹   2.297Ki ± ∞ ¹        ~ (p=1.000 n=1) ²   2.148Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
OpTxnSingleCmpToTxnRequest-16             1.867Ki ± ∞ ¹   1.844Ki ± ∞ ¹        ~ (p=1.000 n=1) ²   1.539Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                   1.036Ki         1.354Ki        +30.64%                   1.131Ki        +9.13%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

			     │ /tmp/bench-old.txt │          /tmp/bench-new.txt           │   /tmp/bench-new-without-clone.txt   │
			     │     allocs/op      │  allocs/op    vs base                 │  allocs/op   vs base                 │
TxnIfSingleCmp-16                           5.000 ± ∞ ¹   10.000 ± ∞ ¹        ~ (p=1.000 n=1) ²   7.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
KubernetesOptimisticPutTxnBuild-16          22.00 ± ∞ ¹    27.00 ± ∞ ¹        ~ (p=1.000 n=1) ²   24.00 ± ∞ ¹        ~ (p=1.000 n=1) ²
OpTxnSingleCmpToTxnRequest-16               21.00 ± ∞ ¹    28.00 ± ∞ ¹        ~ (p=1.000 n=1) ²   21.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
geomean                                     13.22          19.63        +48.47%                   15.22        +15.16%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05
³ all samples are equal
```

Co-authored-by: Jordan Liggitt <liggitt@google.com>
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-05-01 14:57:41 -04:00
Jefftree fd2cc937c9 *: implement server-side RangeStream
Wire up the RangeStream handler end to end: the v3rpc layer streams
chunks out, the txn range path honors the pinned revision and
CountOnly semantics, and retry, mock, and the grpcproxy adapter learn
about the new method so clients and proxies route it correctly.
Integration tests cover the chunking behavior and header handling.

Signed-off-by: Jefftree <jeffrey.ying86@live.com>
2026-04-27 11:12:22 -04:00
Jefftree 10e8d50321 grpcproxy: address review comments on io.EOF handling
Signed-off-by: Jefftree <jeffrey.ying86@live.com>
2026-04-20 10:48:09 -04:00
Jefftree 967feb0d6d grpcproxy: return io.EOF at end of server-streaming RPCs
Signed-off-by: Jefftree <jeffrey.ying86@live.com>
2026-04-17 16:00:58 -04:00
Jordan Liggitt 68b1500533 recover: Embed unimplemented grpc interfaces
Signed-off-by: Jordan Liggitt <liggitt@google.com>
2026-02-10 11:15:04 -05:00
Davanum Srinivas 9ea06e6659 Replace github.com/golang/groupcache with k8s.io/utils/lru
Replace the groupcache LRU cache dependency with the equivalent
implementation from k8s.io/utils/lru. The APIs are compatible,
requiring only an import path change.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2026-02-05 11:49:18 -05:00
Antonio Ojea 87de8541ae enable linter for deprecated functions
enable the linter and just tag each exception with a TODO so we
have identified the existing ones but we can gate to avoid adding
new deprecated functions.

Signed-off-by: Antonio Ojea <aojea@google.com>
2026-01-09 16:35:01 +00:00
Ivan Valdes 343f7242f3 Enable goheader golangi-lint linter
Update source code files that were missing or had incorrect license
headers. For those that had the incorrect license, set the date to 2025.

Signed-off-by: Ivan Valdes <ivan@vald.es>
2025-10-19 21:36:39 -07:00
yajianggroup ab7ba34005 chore: fix some typos in comment
Signed-off-by: yajianggroup <yajianggroup@outlook.com>
2025-09-28 16:00:23 +08:00
Marek Siarkowicz afeab20ac5 Reject watch request with -1 revision and make rangeEvents safe against negative revision
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
2025-09-23 12:25:37 +02:00
Rafael da Fonseca 85d90d9dd9 fix: grpcproxy can get stuck in and endless loop causing high cpu usage
Signed-off-by: Rafael da Fonseca <rafael.fonseca@wildlifestudios.com>
2025-03-07 11:11:59 +00:00
Matthieu MORELandIván Valdés Castillo 10d7cea552 chore: enable early-return and superfluous-else from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Co-authored-by: Iván Valdés Castillo <iv@nvald.es>
2025-01-18 09:44:58 +01:00
Jes Cok 2415c826c2 all: simplify and clean up
This patch modernizes the for-range-loop code to copy a map with
"maps.Clone" and "maps.Copy", also eliminates "copyFloats" with
"slices.Clone".

Also simplify "aggSort" and "sortMap" with slices and maps functions.

Signed-off-by: Jes Cok <xigua67damn@gmail.com>
2025-01-08 21:35:32 +08:00
Matthieu MOREL 69efe31ea0 fix: enable gofumpt instead of gofmt linter in server
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-11-27 07:22:36 +01:00
Matthieu MOREL 3abdf612b3 fix: enable errorlint in server directory
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-10-26 08:16:47 +02:00
redwrasse 0739142ee3 server: errors.Is conversions
Signed-off-by: redwrasse <mail@redwrasse.io>
2024-09-29 05:23:47 -07:00
Siyuan Zhang 7a57e06eca etcdserver: add livez and ready http endpoints for etcd.
Add two separate probes, one for liveness and one for readiness. The liveness probe would check that the local individual node is up and running, or else restart the node, while the readiness probe would check that the cluster is ready to serve traffic. This would make etcd health-check fully Kubernetes API complient.

Signed-off-by: Siyuan Zhang <sizhang@google.com>
2023-10-14 22:32:16 -07:00
Chao Chen c25f1dff82 http health check bug fixes
Signed-off-by: Chao Chen <chaochn@amazon.com>
2023-10-12 16:59:34 -07:00
Wei Fu aa97484166 *: enable goimports in verify-lint
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-09-21 21:14:09 +08:00
Wei Fu 9c3edfa0af *: fix staticcheck lint
Changed TraceKey/StartTimeKey/TokenFieldNameGRPCKey to struct{} to
follow the correct usage of context. Similar patch to #8901.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-09-21 11:24:26 +08:00
chenyahui c0aa3b613b Use any instead of interface{}
Signed-off-by: chenyahui <cyhone@qq.com>
2023-09-17 17:41:58 +08:00
yellowzf ca221208d2 grpcproxy: fix memberlist results not update when proxy node down
If start grpc proxy with --resolver-prefix, memberlist will return all alive proxy nodes, when one grpc proxy node is down, it is expected to not return the down node, but it is still return

Signed-off-by: yellowzf <zzhf3311@163.com>
2023-05-15 10:59:02 +08:00
Msk233 26fdf46001 close the session to avoid leak goroutine
Signed-off-by: Mskxn <118117161+Mskxn@users.noreply.github.com>
2023-04-26 20:45:13 +08:00
Piotr Tabor 9e1abbab6e Fix goimports in all existing files. Execution of ./scripts/fix.sh
Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-29 09:41:31 +01:00
Sasha Melentyev c3b6cbdb73 all: goimports -w .
Signed-off-by: Sasha Melentyev <sasha@melentyev.io>
2022-11-17 19:07:04 +03:00
Kafuu Chino f1d4935e91 *: avoid closing a watch with ID 0 incorrectly
Signed-off-by: Kafuu Chino <KafuuChinoQ@gmail.com>

add test
2022-09-26 20:30:33 +08:00
demoManito 72cf0cc04a etcd: modify declaring empty slices
declare an empty slice to var s []int replace  s :=[]int{}, https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices

Signed-off-by: demoManito <1430482733@qq.com>
2022-09-16 14:41:14 +08:00
SimFG a6bbf7c10b proxy: Put the pb object into the struct
Avoid repeated creation of pb objects.

Signed-off-by: SimFG <1142838399@qq.com>
2022-06-25 10:15:03 +08:00
Marek Siarkowicz c836905a1d proxy: Fix proxy not passing Linearizable field by using GRPC client 2022-01-28 11:39:19 +01:00
ahrtr 09ff05108b enhance health check endpoint to support serializable request 2021-11-15 05:57:54 +08:00
Eng Zer Jun 2a151c8982 *: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-10-28 00:05:28 +08:00
Marek Siarkowicz 5e40a8b00c server: Create storage package and move mvcc files to it 2021-07-12 15:37:21 +02:00
Lili Cosic 1a718a958e Add initial Tracing with OpenTelemetry 2021-05-10 10:44:40 +02:00
Chao Chen 140ea4fa29 etcdhttp/metrics.go: exclude alarms from health check conditionally with ?exclude=NOSPACE 2021-04-20 13:17:09 -07:00
wpedrak dac6e37ea1 *: over 20 staticcheck fixes 2021-03-18 15:06:17 +01:00
Piotr Tabor 4a1c24556c clientv3: PS: Replace balancer with upstream grpc solution
Addresses comments from: https://github.com/etcd-io/etcd/pull/12671#pullrequestreview-593942302
2021-02-23 10:03:15 +01:00
Piotr Tabor a836a8045b Get rid of legacy client/v3/naming API.
Update grpcproxy to use the new abstractions.
2021-02-09 11:56:28 +01:00
Piotr Tabor aaf423e962 server: Update imports.
find -name '*.go' | xargs sed -i --follow-symlinks 's|etcd/v3/|etcd/server/v3/|g'
2020-10-26 13:02:32 +01:00
Piotr Tabor 4a5e9d1261 server: Move server files to 'server' directory.
26  git mv mvcc wal auth etcdserver etcdmain proxy embed/ lease/ server
   36  git mv go.mod go.sum server
2020-10-26 12:57:19 +01:00