2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /***************************************************************************
19 * Description: load balance worker header file *
20 * Author: Gal Shachor <shachor@il.ibm.com> *
21 * Author: Rainer Jung <rjung@apache.org> *
22 * Version: $Revision: 751916 $ *
23 ***************************************************************************/
25 #ifndef JK_LB_WORKER_H
26 #define JK_LB_WORKER_H
28 #include "jk_logger.h"
29 #include "jk_service.h"
36 #endif /* __cplusplus */
38 #define JK_LB_WORKER_NAME ("lb")
39 #define JK_LB_WORKER_TYPE (5)
40 #define JK_LB_SUB_WORKER_TYPE (7)
41 #define JK_LB_DEF_DOMAIN_NAME ("unknown")
43 #define JK_LB_METHOD_REQUESTS (0)
44 #define JK_LB_METHOD_TRAFFIC (1)
45 #define JK_LB_METHOD_BUSYNESS (2)
46 #define JK_LB_METHOD_SESSIONS (3)
47 #define JK_LB_METHOD_DEF (JK_LB_METHOD_REQUESTS)
48 #define JK_LB_METHOD_MAX (JK_LB_METHOD_SESSIONS)
49 #define JK_LB_METHOD_TEXT_REQUESTS ("Request")
50 #define JK_LB_METHOD_TEXT_TRAFFIC ("Traffic")
51 #define JK_LB_METHOD_TEXT_BUSYNESS ("Busyness")
52 #define JK_LB_METHOD_TEXT_SESSIONS ("Sessions")
53 #define JK_LB_METHOD_TEXT_DEF (JK_LB_METHOD_TEXT_REQUESTS)
54 #define JK_LB_LOCK_OPTIMISTIC (0)
55 #define JK_LB_LOCK_PESSIMISTIC (1)
56 #define JK_LB_LOCK_DEF (JK_LB_LOCK_OPTIMISTIC)
57 #define JK_LB_LOCK_MAX (JK_LB_LOCK_PESSIMISTIC)
58 #define JK_LB_LOCK_TEXT_OPTIMISTIC ("Optimistic")
59 #define JK_LB_LOCK_TEXT_PESSIMISTIC ("Pessimistic")
60 #define JK_LB_LOCK_TEXT_DEF (JK_LB_LOCK_TEXT_OPTIMISTIC)
62 * The following definitions for state and activation
63 * need to be kept in sync with the two macros
64 * JK_WORKER_USABLE() and JK_WORKER_USABLE_STICKY() in jk_lb_worker.c.
65 * Since we use ordered comparisons there instead of multiple
66 * equal/unequal compares, order of the values is critical here.
68 #define JK_LB_STATE_IDLE (0)
69 #define JK_LB_STATE_OK (1)
70 #define JK_LB_STATE_RECOVER (2)
71 #define JK_LB_STATE_FORCE (3)
72 #define JK_LB_STATE_BUSY (4)
73 #define JK_LB_STATE_ERROR (5)
74 #define JK_LB_STATE_PROBE (6)
75 #define JK_LB_STATE_DEF (JK_LB_STATE_IDLE)
76 #define JK_LB_STATE_TEXT_IDLE ("OK/IDLE")
77 #define JK_LB_STATE_TEXT_OK ("OK")
78 #define JK_LB_STATE_TEXT_RECOVER ("ERR/REC")
79 #define JK_LB_STATE_TEXT_FORCE ("ERR/FRC")
80 #define JK_LB_STATE_TEXT_BUSY ("OK/BUSY")
81 #define JK_LB_STATE_TEXT_ERROR ("ERR")
82 #define JK_LB_STATE_TEXT_PROBE ("ERR/PRB")
83 #define JK_LB_STATE_TEXT_MAX (JK_LB_STATE_PROBE)
84 #define JK_LB_STATE_TEXT_DEF (JK_LB_STATE_TEXT_IDLE)
85 /* All JK_LB_ACTIVATION_* values must be single digit. */
86 /* Otherwise the string encoding of the activation array */
87 /* fails e.g. in the isapi redirector. */
88 /* JK_LB_ACTIVATION_UNSET is not allowed as an actual worker state. */
89 /* It will not work e.g. when the status worker tries to show the state. */
90 /* It is only used in rule extension data to indicate, that the */
91 /* activation state should not be overwritten. */
92 #define JK_LB_ACTIVATION_ACTIVE (0)
93 #define JK_LB_ACTIVATION_DISABLED (1)
94 #define JK_LB_ACTIVATION_STOPPED (2)
95 #define JK_LB_ACTIVATION_UNSET (9)
96 #define JK_LB_ACTIVATION_DEF (JK_LB_ACTIVATION_ACTIVE)
97 #define JK_LB_ACTIVATION_MAX (JK_LB_ACTIVATION_STOPPED)
98 #define JK_LB_ACTIVATION_TEXT_ACTIVE ("ACT")
99 #define JK_LB_ACTIVATION_TEXT_DISABLED ("DIS")
100 #define JK_LB_ACTIVATION_TEXT_STOPPED ("STP")
101 #define JK_LB_ACTIVATION_TEXT_DEF (JK_LB_ACTIVATION_TEXT_ACTIVE)
103 #define JK_LB_UINT64_STR_SZ (21)
104 #define JK_LB_NOTES_COUNT (9)
105 #define JK_NOTE_LB_FIRST_NAME ("JK_LB_FIRST_NAME")
106 #define JK_NOTE_LB_FIRST_VALUE ("JK_LB_FIRST_VALUE")
107 #define JK_NOTE_LB_FIRST_ACCESSED ("JK_LB_FIRST_ACCESSED")
108 #define JK_NOTE_LB_FIRST_READ ("JK_LB_FIRST_READ")
109 #define JK_NOTE_LB_FIRST_TRANSFERRED ("JK_LB_FIRST_TRANSFERRED")
110 #define JK_NOTE_LB_FIRST_ERRORS ("JK_LB_FIRST_ERRORS")
111 #define JK_NOTE_LB_FIRST_BUSY ("JK_LB_FIRST_BUSY")
112 #define JK_NOTE_LB_FIRST_ACTIVATION ("JK_LB_FIRST_ACTIVATION")
113 #define JK_NOTE_LB_FIRST_STATE ("JK_LB_FIRST_STATE")
114 #define JK_NOTE_LB_LAST_NAME ("JK_LB_LAST_NAME")
115 #define JK_NOTE_LB_LAST_VALUE ("JK_LB_LAST_VALUE")
116 #define JK_NOTE_LB_LAST_ACCESSED ("JK_LB_LAST_ACCESSED")
117 #define JK_NOTE_LB_LAST_READ ("JK_LB_LAST_READ")
118 #define JK_NOTE_LB_LAST_TRANSFERRED ("JK_LB_LAST_TRANSFERRED")
119 #define JK_NOTE_LB_LAST_ERRORS ("JK_LB_LAST_ERRORS")
120 #define JK_NOTE_LB_LAST_BUSY ("JK_LB_LAST_BUSY")
121 #define JK_NOTE_LB_LAST_ACTIVATION ("JK_LB_LAST_ACTIVATION")
122 #define JK_NOTE_LB_LAST_STATE ("JK_LB_LAST_STATE")
124 /* Time to wait before retry. */
125 #define WAIT_BEFORE_RECOVER (60)
126 /* We accept doing global maintenance if we are */
127 /* JK_LB_MAINTAIN_TOLERANCE seconds early. */
128 #define JK_LB_MAINTAIN_TOLERANCE (2)
129 /* We divide load values by 2^x during global maintenance. */
130 /* The exponent x is JK_LB_DECAY_MULT*#MAINT_INTV_SINCE_LAST_MAINT */
131 #define JK_LB_DECAY_MULT (1)
136 /* Shared memory worker data */
137 jk_shm_lb_sub_worker_t *s;
139 char name[JK_SHM_STR_SIZ+1];
140 /* Sequence counter starting at 0 and increasing
141 * every time we change the config
143 volatile unsigned int sequence;
146 char route[JK_SHM_STR_SIZ+1];
148 char domain[JK_SHM_STR_SIZ+1];
149 /* worker redirect route */
150 char redirect[JK_SHM_STR_SIZ+1];
151 /* worker distance */
153 /* current activation state (config) of the worker */
155 /* Current lb factor */
157 /* Current worker index */
159 /* Current lb reciprocal factor */
162 typedef struct lb_sub_worker lb_sub_worker_t;
167 /* Shared memory worker data */
168 jk_shm_lb_worker_t *s;
170 char name[JK_SHM_STR_SIZ+1];
171 /* Sequence counter starting at 0 and increasing
172 * every time we change the config
174 volatile unsigned int sequence;
177 jk_pool_atom_t buf[TINY_POOL_SIZE];
181 lb_sub_worker_t *lb_workers;
182 unsigned int num_of_workers;
184 int sticky_session_force;
185 int recover_wait_time;
186 int error_escalation_time;
187 int max_reply_timeouts;
193 unsigned int max_packet_size;
194 unsigned int next_offset;
196 char session_cookie[JK_SHM_STR_SIZ+1];
198 char session_path[JK_SHM_STR_SIZ+1];
200 typedef struct lb_worker lb_worker_t;
202 int JK_METHOD lb_worker_factory(jk_worker_t **w,
203 const char *name, jk_logger_t *l);
205 const char *jk_lb_get_lock(lb_worker_t *p, jk_logger_t *l);
206 int jk_lb_get_lock_code(const char *v);
207 const char *jk_lb_get_method(lb_worker_t *p, jk_logger_t *l);
208 int jk_lb_get_method_code(const char *v);
209 const char *jk_lb_get_state(lb_sub_worker_t *p, jk_logger_t *l);
210 int jk_lb_get_state_code(const char *v);
211 const char *jk_lb_get_activation_direct(int activation, jk_logger_t *l);
212 const char *jk_lb_get_activation(lb_sub_worker_t *p, jk_logger_t *l);
213 int jk_lb_get_activation_code(const char *v);
214 void reset_lb_values(lb_worker_t *p, jk_logger_t *l);
215 void jk_lb_pull(lb_worker_t * p, int locked, jk_logger_t *l);
216 void jk_lb_push(lb_worker_t * p, int locked, jk_logger_t *l);
217 void update_mult(lb_worker_t * p, jk_logger_t *l);
221 #endif /* __cplusplus */
222 #endif /* JK_LB_WORKER_H */