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

Using Redis with sentinels #11617 #11637

Merged
merged 7 commits into from
May 12, 2022
Merged

Using Redis with sentinels #11617 #11637

merged 7 commits into from
May 12, 2022

Conversation

mazuryv
Copy link
Contributor

@mazuryv mazuryv commented May 4, 2022

PR is created.

Fixes #11617

@dnfadmin
Copy link

dnfadmin commented May 4, 2022

CLA assistant check
All CLA requirements met.

@jtkech
Copy link
Member

jtkech commented May 5, 2022

Maybe we could keep the same pattern in the startup, meaning still doing a parse in a try/catch but just to validate the config string once and before registering the services, so here the only update would be to set options.Configuration to originalConfigurationString that you can rename to configurationString.

Then, looks good to parse it in the ConfigurationOptions getter.

What you think about this comment dotnet/aspnetcore#28367 (comment) saying the following

However, once the master fails and another master is elected by the sentinels, this connection object is no longer valid and the caching breaks. There is currently no way to re-instantiate the connection easily.

@mazuryv
Copy link
Contributor Author

mazuryv commented May 5, 2022

I check it:

However, once the master fails and another master is elected by the sentinels, this connection object is no longer valid and the caching breaks. There is currently no way to re-instantiate the connection easily.
When sentinels elect new master from slave - looks like connection object is still valid and connect to another server without reconection.

@mazuryv
Copy link
Contributor Author

mazuryv commented May 5, 2022

I use options.Configuration because same value is used in RedisCacheOptions

namespace Microsoft.Extensions.Caching.StackExchangeRedis
{
    public class RedisCacheOptions : IOptions<RedisCacheOptions>
    {
        /// <summary>
        /// The configuration used to connect to Redis.
        /// </summary>
        public string Configuration { get; set; }
        ...
    }
} 

I think try/catch protected only against parse exception, not against bad configuration.
When public ConfigurationOptions ConfigurationOptions => ConfigurationOptions.Parse(Configuration); is used, we always get correct configuration.

@jtkech
Copy link
Member

jtkech commented May 5, 2022

Okay cool, thanks for trying it.

I think try/catch protected only against parse exception, not against bad configuration.

Yes but still useful to do as a first level check before registering the related services. But yes keep the change to set the Configuration string options.Configuration = configurationString.

When public ConfigurationOptions ConfigurationOptions => ConfigurationOptions.Parse(Configuration); is used, we always get correct configuration.

Then yes, also keep this change.

Need to leave, will look at it again this night.

{
_logger.LogError("'Redis' features are not active on tenant '{TenantName}' as the 'Configuration' string is missing or invalid: " + e.Message, _tenant);
_logger.LogError("'Redis' features are not active on tenant '{TenantName}' as the 'Configuration' string is missing", _tenant);
Copy link
Member

Choose a reason for hiding this comment

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

Can you keep the error message in a different param? That might help investigate failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I kept it.

Copy link
Member

@jtkech jtkech left a comment

Choose a reason for hiding this comment

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

@mazuryv I approved

Just 2 comment suggestions to be applied.

@jtkech
Copy link
Member

jtkech commented May 5, 2022

@mazuryv I approved

Just 2 comment suggestions to be applied before merging

Edited: Just committed the 2 little suggestions ;)

/// <summary>
/// The configuration string used to connect to Redis.
/// </summary>
public string Configuration { get; set; }
Copy link
Member

@jtkech jtkech May 5, 2022

Choose a reason for hiding this comment

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

Last thing, please add a new line between each property, I can't edit your file.

Okay done, I could do it by making a suggested code and then committing it.

@jtkech
Copy link
Member

jtkech commented May 5, 2022

@mazuryv Last thing, please add a new line between each RedisOptions property, I can't edit your file.

Okay done, I could do it by making a suggested code and then committing it.

@mazuryv
Copy link
Contributor Author

mazuryv commented May 6, 2022

Sorry, I was offline.
I prepare little cosmetic change if you want to approve it.

@jtkech
Copy link
Member

jtkech commented May 6, 2022

No problem

I prepare little cosmetic change if you want to approve it.

I already approved it.

Only need to wait for the next triage ;)

@yusuf-kayikci yusuf-kayikci mentioned this pull request May 11, 2022
22 tasks
@sebastienros
Copy link
Member

What are the breaking changes to document with this PR?
Should users change some settings name after that PR? And would it just build without any change on source code?

@jtkech
Copy link
Member

jtkech commented May 12, 2022

There is no breaking change, we still generate ConfigurationOptions objects by parsing the Configuration string but lazily. The problem was that when connecting with sentinels the ConfigurationOptions is mutated, so e.g. after our service was connected, redis cache was trying to connect with a bad ConfigurationOptions, that we now generate lazily from the Configuration string.

@sebastienros sebastienros added this to the 1.4 milestone May 12, 2022
@sebastienros sebastienros merged commit e5d4254 into OrchardCMS:main May 12, 2022
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.

Using Redis with sentinels
4 participants