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

Implement Lame Duck Mode Event Handler #716

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pzajaczkowski
Copy link
Contributor

@pzajaczkowski pzajaczkowski commented Jan 15, 2025

Resolves #23

I had two ideas for approaching this issue:

  • Make WritableServerInfo property and add setter, that will check if LDM has changed to true
  • Add a trigger method that writes the event to a channel in NatsConnection and invoke it directly from NatsReadProtocolProcessor after recieving INFO from server with LDM.

I decided to go with first option.

There is one thing i am not sure of: should anything be passed as argument to the LameDuckModeActivated event? Currently, it is an empty string.

@mtmk
Copy link
Collaborator

mtmk commented Jan 16, 2025

@pzajaczkowski thanks for the PR. long overdue that issue ;)

  • Make WritableServerInfo property and add setter, that will check if LDM has changed to true
  • Add a trigger method that writes the event to a channel in NatsConnection and invoke it directly from NatsReadProtocolProcessor after recieving INFO from server with LDM.

I decided to go with first option.

I think that's fine.

There is one thing i am not sure of: should anything be passed as argument to the LameDuckModeActivated event? Currently, it is an empty string.

Potentially passing the host might be a interesting. Or a copy of the server info?

EDIT: What do you think about passing Uri of the host similar to the proposal in PR #712

@@ -505,6 +505,32 @@ public async Task ReconnectOnOpenConnection_ShouldDisconnectAndOpenNewConnection
openedCount.ShouldBe(1);
disconnectedCount.ShouldBe(1);
}

[Fact]
public async Task LameDuckModeActivated_EventHandlerShouldBeInvokedWhenInfoWithLDMRecievied()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this test won't run on Windows due to lack of posix signals?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can do this instead...

// var command = $"$SYS.REQ.SERVER.{serverId}.LDM";

RequestAsync(command , ....

Copy link
Member

Choose a reason for hiding this comment

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

Yes, @darkwatchuk is right, with LDM API introduced this is definately an easier way to test it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@pzajaczkowski are you ok to change the test to use the API above?

Copy link
Contributor Author

@pzajaczkowski pzajaczkowski Jan 21, 2025

Choose a reason for hiding this comment

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

Sorry for late response. I tried this approach:

I believe you can do this instead...

// var command = $"$SYS.REQ.SERVER.{serverId}.LDM";

RequestAsync(command , ....

but cannot make it work. When sending event with .LDM suffix i receive error:

{
  "error": {
    "code": 500,
    "description": "no such client id"
  }
}

Also i haven't found any documentation mentioning $SYS.REQ.SERVER.{serverId}.LDM event.
(https://docs.nats.io/running-a-nats-service/configuration/sys_accounts)

I think that the problem is not related to serverId because other examples from docs above like .STATSZ work as intended.

So i need some help please.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll have a look in the morning.

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.

Implement Lame Duck Mode Event Handler
4 participants