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 2 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.

set
{
var current = Interlocked.CompareExchange(ref _writableServerInfo, null, null);
if (current?.LameDuckMode == false && value?.LameDuckMode == true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we might encounter another ld server. probably better not to check a state change but fire every time.

@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?

@@ -109,6 +109,8 @@ public NatsConnection(NatsOpts opts)

public event AsyncEventHandler<NatsMessageDroppedEventArgs>? MessageDropped;

public event AsyncEventHandler<NatsEventArgs>? LameDuckModeActivated;
Copy link
Collaborator

@mtmk mtmk Jan 17, 2025

Choose a reason for hiding this comment

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

@pzajaczkowski let's also pass a copy of server info host Uri here so the application can be aware of which host etc.

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