[
https://issues.apache.org/jira/browse/KNOX-3146?focusedWorklogId=979402&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-979402
]
ASF GitHub Bot logged work on KNOX-3146:
----------------------------------------
Author: ASF GitHub Bot
Created on: 18/Aug/25 20:52
Start Date: 18/Aug/25 20:52
Worklog Time Spent: 10m
Work Description: moresandeep commented on code in PR #1049:
URL: https://github.com/apache/knox/pull/1049#discussion_r2283438950
##########
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:
Could there be a case where there is an HA request but no cookie? i.e. no
sticky session, will it blow up here?
Issue Time Tracking
-------------------
Worklog Id: (was: 979402)
Time Spent: 2h (was: 1h 50m)
> 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
> 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)