lettuce icon indicating copy to clipboard operation
lettuce copied to clipboard

Refresh topology on condition settings

Open 1ou opened this issue 1 year ago • 0 comments

Feature Request

Topology refresh on a provided predicate

Is your feature request related to a problem? Please describe

Periodic refresh is a costly operation. It is not a good idea to use low refresh period, sometimes when nodes go down in our Redis Cluster we wait N time until refresh will be initiated. We can easily catch the event of node failure by ourselves by tracking errors rate on a client side and tell Lettuce "please refresh topology".

Describe the solution you'd like

Some kind of predicate based pattern which is implemented by clients of lettuce in order to provide customization of refresh cluster triggering.

Teachability, Documentation, Adoption, Migration Strategy

For example, for Redis Cluster, we can add a new function to a ClusterTopologyRefreshOptions class. Something like enableRefreshOnCondition(Predicate<> predicate) so clients of lettuce are able to implement this interface providing their logic and returning TRUE in case of a mandatory refresh or FALSE. Later in ClusterTopologyRefreshScheduler we check if predicate returns TRUE and refresh topology in this case. When topology is refreshed, lettuce call method of interface to put predicate in a FALSE condition.

Something like, so all the complexity is on the client:

RefreshTopologyOnConditionStrategy {
    volatile boolean isFuseOpen = fasle;
    Supplier<Boolean> clientCondition;

    public boolean isRefreshRequired();
        if (!isFuseOpen && clientCondition.get()) {
             isFuseOpen = true;
             return true;
        }
        return false;
    }
      
    protected void resetFuse() // called from lettuce internals {
         isFuseOpen = false;
    }
}

1ou avatar Feb 04 '23 15:02 1ou