Skip to content

Commit

Permalink
fix(lease): reworks the previous fix addressing renewal issues (#1105)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Klick <nathan@swirldslabs.com>
  • Loading branch information
nathanklick authored Jan 3, 2025
1 parent 1297cb5 commit 5edb9c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 6 additions & 2 deletions docs/content/User/StepByStepGuide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Advanced User Guide

For those who would like to have more control or need some customized setups, here are some step by step instructions of how to setup and deploy a solo network.

### Setup Kubernetes cluster

#### Remote cluster
Expand Down Expand Up @@ -28,6 +30,7 @@ Then run the following command to set the kubectl context to the new cluster:
```bash
kind create cluster -n "${SOLO_CLUSTER_NAME}"
```

Example output

```
Expand All @@ -48,7 +51,6 @@ Thanks for using kind! 😊

You may now view pods in your cluster using `k9s -A` as below:


```
Context: kind-solo <0> all <a> Attach <ctr… ____ __.________
Cluster: kind-solo <ctrl-d> Delete <l> | |/ _/ __ \______
Expand All @@ -75,7 +77,6 @@ You may now view pods in your cluster using `k9s -A` as below:
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```


### Step by Step Instructions

* Initialize `solo` directories:
Expand Down Expand Up @@ -136,13 +137,16 @@ Kubernetes Cluster : kind-solo
✔ Generate gRPC TLS Keys
✔ Finalize
```

PEM key files are generated in `~/.solo/keys` directory.

```
hedera-node1.crt hedera-node3.crt s-private-node1.pem s-public-node1.pem unused-gossip-pem
hedera-node1.key hedera-node3.key s-private-node2.pem s-public-node2.pem unused-tls
hedera-node2.crt hedera-node4.crt s-private-node3.pem s-public-node3.pem
hedera-node2.key hedera-node4.key s-private-node4.pem s-public-node4.pem
```

* Setup cluster with shared components

```
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* make sure that your current kubeconfig context is pointing to the cluster that you want to deploy to
* run `task` which will do the rest and deploy the network and take care of many of the pre-requisites

NOTES:
NOTES:

* Some of these examples are for running against large clusters with a lot of resources available.
* the `env` environment variables if set in your shell will take precedence over what is in the Taskfile.yml. e.g. `export HEDERA_SERVICES_ROOT=<path-to-hedera-services-root>`
Expand Down
12 changes: 5 additions & 7 deletions src/core/lease/interval_lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {sleep} from '../helpers.js';
import {Duration} from '../time/duration.js';
import type {Lease, LeaseRenewalService} from './lease.js';
import {StatusCodes} from 'http-status-codes';
import chalk from 'chalk';

/**
* Concrete implementation of a Kubernetes based time-based mutually exclusive lock via the Coordination API.
Expand Down Expand Up @@ -144,14 +143,16 @@ export class IntervalLease implements Lease {
async acquire(): Promise<void> {
const lease = await this.retrieveLease();

if (!lease || IntervalLease.checkExpiration(lease) || this.heldBySameProcess(lease)) {
if (!lease || this.heldBySameProcess(lease)) {
return this.createOrRenewLease(lease);
} else if (IntervalLease.checkExpiration(lease)) {
return this.transferLease(lease);
}

const otherHolder: LeaseHolder = LeaseHolder.fromJson(lease.spec.holderIdentity);

if (this.heldBySameMachineIdentity(lease) && !otherHolder.isProcessAlive()) {
return await this.transferLease(lease);
return this.transferLease(lease);
}

throw new LeaseAcquisitionError(
Expand Down Expand Up @@ -220,7 +221,6 @@ export class IntervalLease implements Lease {
* @throws LeaseRelinquishmentError - If the lease is already acquired by another process or an error occurs during relinquishment.
*/
async release(): Promise<void> {
this.client.logger.showUser(`${chalk.gray('releasing lease')}`);
const lease = await this.retrieveLease();

if (this.scheduleId) {
Expand Down Expand Up @@ -329,10 +329,8 @@ export class IntervalLease implements Lease {
this.leaseHolder.toJson(),
this.durationSeconds,
);
} else if (this.leaseHolder.equals(LeaseHolder.fromJson(lease.spec.holderIdentity))) {
await this.client.renewNamespaceLease(this.leaseName, this.namespace, lease);
} else {
await this.client.transferNamespaceLease(lease, this.leaseHolder.toJson());
await this.client.renewNamespaceLease(this.leaseName, this.namespace, lease);
}

if (!this.scheduleId) {
Expand Down

0 comments on commit 5edb9c9

Please sign in to comment.