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

Downgrade poc #6

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4243ebd
e2e: add cluster version test for rolling start servers
YoyinZyc Oct 22, 2019
8adebf4
CHANGELOG: Add v3.4.3
spzala Nov 13, 2019
63dd73c
Merge pull request #11354 from spzala/issue11353
spzala Nov 13, 2019
cabf594
scripts/build-binary: Added s390x support for binary release
nirmannarang Nov 13, 2019
4b755e8
docs: Update the raft usage by adding Hyperledger project
yeasy Nov 14, 2019
a057116
feat: changed ETCD manager URL
gtamas Nov 19, 2019
b373cb9
Merge pull request #11373 from gtamas/master
jingyih Nov 19, 2019
28f40d7
mvcc: add "etcd_mvcc_put_size_in_bytes" to monitor the throughput of …
YoyinZyc Nov 19, 2019
a5e747b
mvcc: update to "etcd_debugging_mvcc_total_put_size_in_bytes"
YoyinZyc Nov 19, 2019
908ef19
Merge pull request #11374 from YoyinZyc/put_throughput_metrics
jingyih Nov 20, 2019
ec52217
Merge pull request #11363 from yeasy/patch-1
jingyih Nov 21, 2019
5a11023
e2e: only expect cluster's major version is > 3 in release upgrade te…
YoyinZyc Oct 16, 2019
cab4cac
tests: change MANUAL_VER to 3.4.3
YoyinZyc Nov 25, 2019
44fc9e3
Merge pull request #11266 from YoyinZyc/upgrade-downgrade-test
jingyih Nov 25, 2019
49c3f74
CHANGELOG: update from PR 11374
jingyih Nov 26, 2019
9c08316
Merge pull request #11395 from jingyih/update_changelog
wenjiaswe Nov 26, 2019
419ffb7
Merge pull request #11287 from YoyinZyc/version-test-rolling-start
jingyih Nov 26, 2019
6c0e2d3
etcdmain: remove duplicate codes.
johncming Nov 27, 2019
655df65
mvcc/kvstore:fixcompactbug
WIZARD-CXY Nov 27, 2019
3275e5f
Merge pull request #11399 from johncming/remove-dup-code
jingyih Nov 27, 2019
ccc52be
Merge pull request #11400 from WIZARD-CXY/compactfix
jingyih Nov 27, 2019
6be629c
CHANGELOG: update from PR 11403
jingyih Nov 27, 2019
d1139d3
Merge pull request #11404 from jingyih/update_changelog
jingyih Nov 27, 2019
b14c7cd
concurrency: make lock more reliable
xiang90 Dec 1, 2019
c8ffd92
auth: fix user.Options nil pointer
YoyinZyc Dec 2, 2019
ae2bc16
Merge pull request #11413 from YoyinZyc/fix-user-options-nil-pointer
xiang90 Dec 2, 2019
18e9e45
Merge pull request #11358 from linux-on-ibm-z/s390x-binary
xiang90 Dec 2, 2019
659f5a4
Update CHANGELOG-3.3.md
wenjiaswe Dec 4, 2019
e5356cc
Merge pull request #11408 from xiang90/lock
gyuho Dec 4, 2019
d4d7ad3
mirror: make etcdctl make-mirror subcommand accept --dest-user and --…
schlitzered Dec 4, 2019
c5887cd
mvcc: go style err check (#11419)
xiaoanyunfei Dec 5, 2019
fd2dddb
vendor: bump go-systemd to v22.0.0 to fix mod tidy error (#11387)
ms2008 Dec 5, 2019
1f8764b
integration: prevent goroutines leaks in test (#11318)
lzhfromustc Dec 5, 2019
dcd622b
etcdserver: add v3 request type for cluster attr
jingyih Nov 26, 2019
0c3401f
etcdserver: use V3 to update cluster version
YoyinZyc Nov 26, 2019
5cd2502
etcdserver: use v3 to publish member attr
jingyih Nov 27, 2019
ed5a01a
etcdserver: recover cluster version from backend
jingyih Dec 3, 2019
7784ca8
etcdserver: remove v2 version set; e2e: fix tests.
YoyinZyc Dec 5, 2019
9f81002
Merge pull request #11427 from YoyinZyc/migration-cluster-attr
gyuho Dec 9, 2019
aea34c1
auth: fix NoPassWord check when add user
YoyinZyc Dec 4, 2019
5127cfb
e2e: test curl auth on onoption user
YoyinZyc Dec 10, 2019
4f35794
Merge pull request #11418 from YoyinZyc/fix-add-user-grpc
jingyih Dec 10, 2019
69841bd
CHANGELOG-3.5: update for #11427
YoyinZyc Dec 11, 2019
b7d9f45
Merge pull request #11432 from YoyinZyc/changelog-11427
jingyih Dec 11, 2019
d702518
integration: gracefully shut down gRPC server (#11437)
hormes Dec 11, 2019
769d2f8
CHANGELOG: update for #11418
YoyinZyc Dec 12, 2019
378b05b
Merge pull request #11443 from YoyinZyc/changelog-11418
gyuho Dec 12, 2019
9298f84
etcdserver: Add downgrade support POC
wenjiaswe Oct 25, 2019
62280cc
etcdserver: add downgrade proto api
YoyinZyc Oct 24, 2019
1aa02da
clientV3: add downgrade api in maintenance
YoyinZyc Oct 24, 2019
336cef4
v3rpc: add downgrader api in maintenance server
YoyinZyc Oct 24, 2019
9da21e9
membership: add downgrade field into raftCluster
YoyinZyc Oct 24, 2019
2023979
etcdserver: implement EtcdServer.Downgrade; implement downgrade valid…
YoyinZyc Oct 24, 2019
5182d5e
membership: add downgrade backend support
YoyinZyc Oct 24, 2019
a81969f
membership: recover downgrade from backend when restart the server or…
YoyinZyc Oct 26, 2019
5df9185
etcdserver: add downgrade start and downgrade cancel
YoyinZyc Oct 28, 2019
1d80e74
etcdserver: add monitorDowngrade for monitoring the downgrade status
YoyinZyc Oct 28, 2019
4e429b7
etcdctl: add downgrade commands.
YoyinZyc Oct 29, 2019
fa150ce
etcdserver: update downgrade check for version when starting/restarti…
YoyinZyc Oct 31, 2019
ce75238
etcdserver: add unit&integration test for downgrade; etcdctl: add pri…
YoyinZyc Nov 6, 2019
87aaab6
etcdserver: add new http handler to fetch the downgrade status of a c…
YoyinZyc Nov 11, 2019
dbc383a
e2e: add etcd downgrade/upgrade test
YoyinZyc Nov 11, 2019
f01694a
test: ctl_downgrade_test
wenjiaswe Nov 11, 2019
2311bc4
e2e: fix ctl_v3_downgrade_test; etcdctl: update output messages
YoyinZyc Nov 12, 2019
fe53e35
etcdserver: remove Downgrade Action Status in rpc.proto
YoyinZyc Nov 12, 2019
5c7f7ee
etcdserver: change downgrade raft request type from ConfChange to Int…
YoyinZyc Nov 13, 2019
61082c8
etcdserver: allow previous binary to restart when downgrade. add new …
YoyinZyc Nov 14, 2019
197a8a6
etcdserver: fix TestCtlV3Migrate nil pointer issue
YoyinZyc Nov 14, 2019
6efeb79
etcdserver: change "/downgrade/enabled" endpoint to serve linearized …
YoyinZyc Nov 16, 2019
f961ac9
etcdserver: separate function isValidDowngrade from mustDetectDowngra…
YoyinZyc Nov 19, 2019
00a36b4
etcdserver: define error string and link grpc error code.
YoyinZyc Nov 23, 2019
22ddb23
etcdserver: add new raft internal request DowngradeInfoSetRequest
YoyinZyc Dec 16, 2019
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ script:
&& GO_BUILD_FLAGS='-v' GOOS=windows GOARCH=amd64 ./build \
&& GO_BUILD_FLAGS='-v' GOARCH=arm ./build \
&& GO_BUILD_FLAGS='-v' GOARCH=arm64 ./build \
&& GO_BUILD_FLAGS='-v' GOARCH=ppc64le ./build"
&& GO_BUILD_FLAGS='-v' GOARCH=ppc64le ./build \
&& GO_BUILD_FLAGS='-v' GOARCH=s390x ./build"
;;
linux-amd64-grpcproxy)
sudo HOST_TMP_DIR=/tmp TEST_OPTS="PASSES='build grpcproxy'" make docker-test
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The minimum recommended etcd versions to run in **production** are 3.1.11+, 3.2.
<hr>


## v3.3.18 (2019-TBD)
## v3.3.18 (2019-11-26)

### Metrics, Monitoring

Expand All @@ -17,6 +17,7 @@ See [List of metrics](https://github.com/etcd-io/etcd/tree/master/Documentation/
Note that any `etcd_debugging_*` metrics are experimental and subject to change.

- Add [`etcd_cluster_version`](https://github.com/etcd-io/etcd/pull/11261) Prometheus metric.
- Add [`etcd_debugging_mvcc_total_put_size_in_bytes`](https://github.com/etcd-io/etcd/pull/11374) Prometheus metric.

### etcdserver

Expand Down
38 changes: 34 additions & 4 deletions CHANGELOG-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@ The minimum recommended etcd versions to run in **production** are 3.1.11+, 3.2.
<hr>


## [v3.4.2](https://github.com/etcd-io/etcd/releases/tag/v3.4.2) (2019 TBD)
## [v3.4.4](https://github.com/etcd-io/etcd/releases/tag/v3.4.4) (2020 TBD)

See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.1...v3.4.2) and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md) for any breaking changes.
See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.3...v3.4.4) and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md) for any breaking changes.

**Again, before running upgrades from any previous release, please make sure to read change logs below and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md).**

### Dependency
### Metrics, Monitoring

- Upgrade [`google.golang.org/grpc`](https://github.com/grpc/grpc-go/releases) from [**`v1.23.1`**](https://github.com/grpc/grpc-go/releases/tag/v1.23.1) to [**`v1.24.0`**](https://github.com/grpc/grpc-go/releases/tag/v1.24.0).
See [List of metrics](https://github.com/etcd-io/etcd/tree/master/Documentation/metrics) for all metrics per release.

Note that any `etcd_debugging_*` metrics are experimental and subject to change.

- Add [`etcd_debugging_mvcc_total_put_size_in_bytes`](https://github.com/etcd-io/etcd/pull/11374) Prometheus metric.
- Fix bug where [etcd_debugging_mvcc_db_compaction_keys_total is always 0](https://github.com/etcd-io/etcd/pull/11400).

### Auth

- Fix [NoPassword check when adding user through GRPC gateway](https://github.com/etcd-io/etcd/pull/11418) ([issue#11414](https://github.com/etcd-io/etcd/issues/11414))

## [v3.4.3](https://github.com/etcd-io/etcd/releases/tag/v3.4.3) (2019-10-24)

See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.2...v3.4.3) and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md) for any breaking changes.

**Again, before running upgrades from any previous release, please make sure to read change logs below and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md).**

### Metrics, Monitoring

Expand All @@ -27,6 +42,21 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.

- Change [`etcd_cluster_version`](https://github.com/etcd-io/etcd/pull/11254) Prometheus metrics to include only major and minor version.

### Go

- Compile with [*Go 1.12.12*](https://golang.org/doc/devel/release.html#go1.12).


## [v3.4.2](https://github.com/etcd-io/etcd/releases/tag/v3.4.2) (2019-10-11)

See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.1...v3.4.2) and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md) for any breaking changes.

**Again, before running upgrades from any previous release, please make sure to read change logs below and [v3.4 upgrade guide](https://github.com/etcd-io/etcd/blob/master/Documentation/upgrades/upgrade_3_4.md).**

### Dependency

- Upgrade [`google.golang.org/grpc`](https://github.com/grpc/grpc-go/releases) from [**`v1.23.1`**](https://github.com/grpc/grpc-go/releases/tag/v1.23.1) to [**`v1.24.0`**](https://github.com/grpc/grpc-go/releases/tag/v1.24.0).

### etcdctl v3

- Fix [`etcdctl member add`](https://github.com/etcd-io/etcd/pull/11194) command to prevent potential timeout.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
- Add [`etcd_debugging_mvcc_current_revision`](https://github.com/etcd-io/etcd/pull/11126) Prometheus metric.
- Add [`etcd_debugging_mvcc_compact_revision`](https://github.com/etcd-io/etcd/pull/11126) Prometheus metric.
- Change [`etcd_cluster_version`](https://github.com/etcd-io/etcd/pull/11254) Prometheus metrics to include only major and minor version.
- Add [`etcd_debugging_mvcc_total_put_size_in_bytes`](https://github.com/etcd-io/etcd/pull/11374) Prometheus metric.

### etcd server

Expand All @@ -79,6 +80,7 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
- [`etcd --backend-bbolt-freelist-type`] flag is now stable.
- `etcd --experimental-backend-bbolt-freelist-type` has been deprecated.
- Support [rollback/downgrade](TODO).
- Deprecate v2 apply on cluster version. [Use v3 request to set cluster version and recover cluster version from v3 backend](https://github.com/etcd-io/etcd/pull/11427).

### Package `embed`

Expand All @@ -100,6 +102,10 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
- Deprecated [`/v3beta`](https://github.com/etcd-io/etcd/pull/9298).
- `curl -L http://localhost:2379/v3beta/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'` does work in v3.5. Use `curl -L http://localhost:2379/v3/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'` instead.

### Auth

- Fix [NoPassword check when adding user through GRPC gateway](https://github.com/etcd-io/etcd/pull/11418) ([issue#11414](https://github.com/etcd-io/etcd/issues/11414))

### Dependency

- Upgrade [`google.golang.org/grpc`](https://github.com/grpc/grpc-go/releases) from [**`v1.23.0`**](https://github.com/grpc/grpc-go/releases/tag/v1.23.0) to [**`v1.23.1`**](https://github.com/grpc/grpc-go/releases/tag/v1.23.1).
Expand Down
19 changes: 19 additions & 0 deletions Documentation/dev-guide/api_reference_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ This is a generated documentation. Please read the proto files for more.
| HashKV | HashKVRequest | HashKVResponse | HashKV computes the hash of all MVCC keys up to a given revision. It only iterates "key" bucket in backend storage. |
| Snapshot | SnapshotRequest | SnapshotResponse | Snapshot sends a snapshot of the entire backend from a member over a stream to a client. |
| MoveLeader | MoveLeaderRequest | MoveLeaderResponse | MoveLeader requests current leader node to transfer its leadership to transferee. |
| Downgrade | DowngradeRequest | DowngradeResponse | Downgrade requests downgrade, cancel downgrade on the cluster version. |



Expand Down Expand Up @@ -445,6 +446,24 @@ Empty field.



##### message `DowngradeRequest` (etcdserver/etcdserverpb/rpc.proto)

| Field | Description | Type |
| ----- | ----------- | ---- |
| action | action is the kind of downgrade request to issue. The action may VALIDATE the target version, DOWNGRADE the cluster version, or CANCEL the current downgrading job. | DowngradeAction |
| version | version is the target version to downgrade. | string |



##### message `DowngradeResponse` (etcdserver/etcdserverpb/rpc.proto)

| Field | Description | Type |
| ----- | ----------- | ---- |
| header | | ResponseHeader |
| version | version is the current cluster version. | string |



##### message `HashKVRequest` (etcdserver/etcdserverpb/rpc.proto)

| Field | Description | Type |
Expand Down
61 changes: 61 additions & 0 deletions Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,33 @@
}
}
},
"/v3/maintenance/downgrade": {
"post": {
"tags": [
"Maintenance"
],
"summary": "Downgrade requests downgrade, cancel downgrade on the cluster version.",
"operationId": "Downgrade",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/etcdserverpbDowngradeRequest"
}
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/etcdserverpbDowngradeResponse"
}
}
}
}
},
"/v3/maintenance/hash": {
"post": {
"tags": [
Expand Down Expand Up @@ -1156,6 +1183,15 @@
"LEASE"
]
},
"DowngradeRequestDowngradeAction": {
"type": "string",
"default": "VALIDATE",
"enum": [
"VALIDATE",
"ENABLE",
"CANCEL"
]
},
"EventEventType": {
"type": "string",
"default": "PUT",
Expand Down Expand Up @@ -1708,6 +1744,31 @@
}
}
},
"etcdserverpbDowngradeRequest": {
"type": "object",
"properties": {
"action": {
"description": "action is the kind of downgrade request to issue. The action may\nVALIDATE the target version, DOWNGRADE the cluster version,\nor CANCEL the current downgrading job.",
"$ref": "#/definitions/DowngradeRequestDowngradeAction"
},
"version": {
"description": "version is the target version to downgrade.",
"type": "string"
}
}
},
"etcdserverpbDowngradeResponse": {
"type": "object",
"properties": {
"header": {
"$ref": "#/definitions/etcdserverpbResponseHeader"
},
"version": {
"description": "version is the current cluster version.",
"type": "string"
}
}
},
"etcdserverpbHashKVRequest": {
"type": "object",
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion Documentation/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ title: Libraries and tools
- [etcdsh](https://github.com/kamilhark/etcdsh) - A command line client with support of command history and tab completion. Supports v2
- [etcdloadtest](https://github.com/sinsharat/etcdloadtest) - A command line load test client for etcd version 3.0 and above.
- [lucas](https://github.com/ringtail/lucas) - A web-based key-value viewer for kubernetes etcd3.0+ cluster.
- [etcd-manager](https://github.com/gtamas/etcdmanager) - A modern, efficient, multi-platform and free ETCD 3.x GUI & client tool. Available for Windows, Linux and Mac.
- [etcd-manager](https://etcdmanager.io) - A modern, efficient, multi-platform and free ETCD 3.x GUI & client tool. Available for Windows, Linux and Mac.
- [etcd-backup-restore](https://github.com/gardener/etcd-backup-restore) - Utility to periodic and incrementally backup and restore the etcd.

**Go libraries**
Expand Down
7 changes: 4 additions & 3 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (as *authStore) Authenticate(ctx context.Context, username, password string
return nil, ErrAuthFailed
}

if user.Options.NoPassword {
if user.Options != nil && user.Options.NoPassword {
return nil, ErrAuthFailed
}

Expand Down Expand Up @@ -344,7 +344,7 @@ func (as *authStore) CheckPassword(username, password string) (uint64, error) {
return 0, ErrAuthFailed
}

if user.Options.NoPassword {
if user.Options != nil && user.Options.NoPassword {
return 0, ErrAuthFailed
}

Expand Down Expand Up @@ -388,7 +388,8 @@ func (as *authStore) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse,
var hashed []byte
var err error

if r.Options != nil && !r.Options.NoPassword {
noPassword := r.Options != nil && r.Options.NoPassword
if !noPassword {
hashed, err = bcrypt.GenerateFromPassword([]byte(r.Password), as.bcryptCost)
if err != nil {
if as.lg != nil {
Expand Down
11 changes: 10 additions & 1 deletion bill-of-materials.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
]
},
{
"project": "github.com/coreos/go-systemd",
"project": "github.com/coreos/go-systemd/journal",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 0.9966703662597114
}
]
},
{
"project": "github.com/coreos/go-systemd/v22",
"licenses": [
{
"type": "Apache License 2.0",
Expand Down
17 changes: 16 additions & 1 deletion clientv3/concurrency/mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

// ErrLocked is returned by TryLock when Mutex is already locked by another session.
var ErrLocked = errors.New("mutex: Locked by another session")
var ErrSessionExpired = errors.New("mutex: session is expired")

// Mutex implements the sync Locker interface with etcd
type Mutex struct {
Expand Down Expand Up @@ -80,14 +81,28 @@ func (m *Mutex) Lock(ctx context.Context) error {
}
client := m.s.Client()
// wait for deletion revisions prior to myKey
// TODO: early termination if the session key is deleted before other session keys with smaller revisions.
hdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)
// release lock key if wait failed
if werr != nil {
m.Unlock(client.Ctx())
} else {
m.hdr = hdr
}
return werr

// make sure the session is not expired, and the owner key still exists.
gresp, werr := client.Get(ctx, m.myKey)
if werr != nil {
m.Unlock(client.Ctx())
return werr
}

if len(gresp.Kvs) == 0 { // is the session key lost?
return ErrSessionExpired
}
m.hdr = gresp.Header

return nil
}

func (m *Mutex) tryAcquire(ctx context.Context) (*v3.TxnResponse, error) {
Expand Down
71 changes: 71 additions & 0 deletions clientv3/concurrency/mutex_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2019 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package concurrency_test

import (
"context"
"testing"

"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
)

func TestMutexLockSessionExpired(t *testing.T) {
cli, err := clientv3.New(clientv3.Config{Endpoints: endpoints})
if err != nil {
t.Fatal(err)
}
defer cli.Close()

// create two separate sessions for lock competition
s1, err := concurrency.NewSession(cli)
if err != nil {
t.Fatal(err)
}
defer s1.Close()
m1 := concurrency.NewMutex(s1, "/my-lock/")

s2, err := concurrency.NewSession(cli)
if err != nil {
t.Fatal(err)
}
m2 := concurrency.NewMutex(s2, "/my-lock/")

// acquire lock for s1
if err := m1.Lock(context.TODO()); err != nil {
t.Fatal(err)
}

m2Locked := make(chan struct{})
var err2 error
go func() {
defer close(m2Locked)
// m2 blocks since m1 already acquired lock /my-lock/
if err2 = m2.Lock(context.TODO()); err2 == nil {
t.Fatal("expect session expired error")
}
}()

// revoke the session of m2 before unlock m1
err = s2.Close()
if err != nil {
t.Fatal(err)
}
if err := m1.Unlock(context.TODO()); err != nil {
t.Fatal(err)
}

<-m2Locked
}
2 changes: 1 addition & 1 deletion clientv3/integration/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ func TestKVLargeRequests(t *testing.T) {
expectError error
}{
{
maxRequestBytesServer: 1,
maxRequestBytesServer: 256,
maxCallSendBytesClient: 0,
maxCallRecvBytesClient: 0,
valueSize: 1024,
Expand Down
Loading