[ 
https://issues.apache.org/jira/browse/KNOX-3146?focusedWorklogId=979432&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-979432
 ]

ASF GitHub Bot logged work on KNOX-3146:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Aug/25 06:46
            Start Date: 19/Aug/25 06:46
    Worklog Time Spent: 10m 
      Work Description: hanicz commented on code in PR #1049:
URL: https://github.com/apache/knox/pull/1049#discussion_r2284291670


##########
gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/CommonHaDispatch.java:
##########
@@ -225,19 +223,88 @@ default void shiftActiveURL(boolean userAgentDisabled, 
Optional<URI> backendURI)
          *    needs to be loadbalanced. If a request has BACKEND coookie and 
Loadbalance=on then
          *    there should be no loadbalancing.
          */
-        if (isLoadBalancingEnabled() && !userAgentDisabled) {
+        if (getHaConfigurations().isLoadBalancingEnabled() && 
!userAgentDisabled) {
             /* check sticky session enabled */
-            if (isStickySessionEnabled()) {
+            if (getHaConfigurations().isStickySessionEnabled()) {
                 /* loadbalance only when sticky session enabled and no backend 
url cookie */
                 if (!backendURI.isPresent()) {
-                    
getHaProvider().makeNextActiveURLAvailable(getServiceRole());
+                    
getHaConfigurations().getHaProvider().makeNextActiveURLAvailable(getServiceRole());
                 } else {
                     /* sticky session enabled and backend url cookie is valid 
no need to loadbalance */
                     /* do nothing */
                 }
             } else {
-                getHaProvider().makeNextActiveURLAvailable(getServiceRole());
+                
getHaConfigurations().getHaProvider().makeNextActiveURLAvailable(getServiceRole());
+            }
+        }
+    }
+
+    /**
+     * A helper method that marks an endpoint failed.
+     * Changes HA Provider state.
+     * Changes ActiveUrl state.
+     * Changes for inbound urls should be handled by calling functions.
+     *
+     * @param outboundRequest
+     * @param inboundRequest
+     * @return current failover counter
+     */
+    default AtomicInteger markEndpointFailed(final HttpUriRequest 
outboundRequest, final HttpServletRequest inboundRequest) {
+        synchronized (this) {
+            
getHaConfigurations().getHaProvider().markFailedURL(getServiceRole(), 
outboundRequest.getURI().toString());
+            AtomicInteger counter = (AtomicInteger) 
inboundRequest.getAttribute(FAILOVER_COUNTER_ATTRIBUTE);
+            if (counter == null) {
+                counter = new AtomicInteger(0);
+            }
+
+            if (counter.incrementAndGet() <= 
getHaConfigurations().getMaxFailoverAttempts()) {
+                setupUrlHashLookup(); // refresh the url hash after failing a 
url
+                /* in case of failover update the activeURL variable */
+                getActiveURL().set(outboundRequest.getURI().toString());
+            }
+            return counter;
+        }
+    }
+
+    default HttpServletRequest prepareForFailover(HttpUriRequest 
outboundRequest, HttpServletRequest inboundRequest) {
+        //null out target url so that rewriters run again
+        
inboundRequest.setAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME,
 null);
+        // Make sure to remove the ha cookie from the request
+        inboundRequest = new 
StickySessionCookieRemovedRequest(getHaConfigurations().getStickySessionCookieName(),
 inboundRequest);

Review Comment:
   No, it just makes sure it is removed in case there is one. This logic was 
just moved into the interface, I didn't touch it.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 979432)
    Time Spent: 2h 10m  (was: 2h)

> Failover ability for SSEHaDispatch
> ----------------------------------
>
>                 Key: KNOX-3146
>                 URL: https://issues.apache.org/jira/browse/KNOX-3146
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: Server
>    Affects Versions: 2.2.0
>            Reporter: Tamás Hanicz
>            Assignee: Tamás Hanicz
>            Priority: Major
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> The failover ability is missing for SSEHaDispatch. It would be beneficial to 
> add it.  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to