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: Shared Memory object header file *
20 * Author: Mladen Turk <mturk@jboss.com> *
21 * Author: Rainer Jung <rjung@apache.org> *
22 * Version: $Revision: 893253 $ *
23 ***************************************************************************/
27 #include "jk_global.h"
34 #endif /* __cplusplus */
38 * @brief Jk shared memory management
43 #define JK_SHM_MAJOR '1'
44 #define JK_SHM_MINOR '3'
45 #define JK_SHM_STR_SIZ 63
46 #define JK_SHM_URI_SIZ 127
47 #define JK_SHM_DYNAMIC 16
48 #define JK_SHM_MAGIC '!', 'J', 'K', 'S', 'H', 'M', JK_SHM_MAJOR, JK_SHM_MINOR
49 #define JK_SHM_MAGIC_SIZ 8
51 /* Really huge numbers, but 64 workers should be enough */
52 #define JK_SHM_MAX_WORKERS 64
53 #define JK_SHM_ALIGNMENT 64
54 #define JK_SHM_ALIGN(x) JK_ALIGN((x), JK_SHM_ALIGNMENT)
55 #define JK_SHM_AJP_WORKER_SIZE JK_SHM_ALIGN(sizeof(jk_shm_ajp_worker_t))
56 #define JK_SHM_LB_SUB_WORKER_SIZE JK_SHM_ALIGN(sizeof(jk_shm_lb_sub_worker_t))
57 #define JK_SHM_LB_WORKER_SIZE JK_SHM_ALIGN(sizeof(jk_shm_lb_worker_t))
58 #define JK_SHM_AJP_SIZE(x) ((x) * JK_SHM_AJP_WORKER_SIZE)
59 #define JK_SHM_LB_SUB_SIZE(x) ((x) * JK_SHM_LB_SUB_WORKER_SIZE)
60 #define JK_SHM_LB_SIZE(x) ((x) * JK_SHM_LB_WORKER_SIZE)
61 #define JK_SHM_DEF_SIZE JK_SHM_AJP_SIZE(JK_SHM_MAX_WORKERS) + JK_SHM_LB_SUB_SIZE(JK_SHM_MAX_WORKERS) + JK_SHM_LB_SIZE(JK_SHM_MAX_WORKERS)
63 /** jk shm generic worker record structure */
64 struct jk_shm_worker_header
69 char name[JK_SHM_STR_SIZ+1];
70 /* Sequence counter starting at 0 and increasing
71 * every time we change the config
73 volatile unsigned int sequence;
75 typedef struct jk_shm_worker_header jk_shm_worker_header_t;
77 /** jk shm ajp13/ajp14 worker record structure */
78 struct jk_shm_ajp_worker
80 jk_shm_worker_header_t h;
81 char host[JK_SHM_STR_SIZ+1];
83 volatile int addr_sequence;
85 /* Configuration data mirrored from ajp_worker */
91 unsigned int recovery_opts;
94 unsigned int max_packet_size;
95 /* current error state (runtime) of the worker */
97 /* Statistical data */
98 /* Number of currently connected channels */
99 volatile int connected;
100 /* Number of currently busy channels */
102 /* Maximum number of busy channels */
103 volatile int max_busy;
104 volatile time_t error_time;
105 /* Number of bytes read from remote */
106 volatile jk_uint64_t readed;
107 /* Number of bytes transferred to remote */
108 volatile jk_uint64_t transferred;
109 /* Number of times the worker was used */
110 volatile jk_uint64_t used;
111 /* Number of times the worker was used - snapshot during maintenance */
112 volatile jk_uint64_t used_snapshot;
113 /* Number of non 200 responses */
114 volatile jk_uint32_t errors;
115 /* Decayed number of reply_timeout errors */
116 volatile jk_uint32_t reply_timeouts;
117 /* Number of client errors */
118 volatile jk_uint32_t client_errors;
119 /* Last reset time */
120 volatile time_t last_reset;
121 volatile time_t last_maintain_time;
123 typedef struct jk_shm_ajp_worker jk_shm_ajp_worker_t;
125 /** jk shm lb sub worker record structure */
126 struct jk_shm_lb_sub_worker
128 jk_shm_worker_header_t h;
131 char route[JK_SHM_STR_SIZ+1];
133 char domain[JK_SHM_STR_SIZ+1];
134 /* worker redirect route */
135 char redirect[JK_SHM_STR_SIZ+1];
136 /* Number of currently busy channels */
138 /* worker distance */
139 volatile int distance;
140 /* current activation state (config) of the worker */
141 volatile int activation;
142 /* current error state (runtime) of the worker */
144 /* Current lb factor */
145 volatile int lb_factor;
146 /* Current lb reciprocal factor */
147 volatile jk_uint64_t lb_mult;
148 /* Current lb value */
149 volatile jk_uint64_t lb_value;
150 /* Statistical data */
151 volatile time_t error_time;
152 /* Number of times the worker was elected - snapshot during maintenance */
153 volatile jk_uint64_t elected_snapshot;
154 /* Number of non 200 responses */
155 volatile jk_uint32_t errors;
157 typedef struct jk_shm_lb_sub_worker jk_shm_lb_sub_worker_t;
159 /** jk shm lb worker record structure */
160 struct jk_shm_lb_worker
162 jk_shm_worker_header_t h;
164 /* Number of currently busy channels */
166 /* Maximum number of busy channels */
167 volatile int max_busy;
169 int sticky_session_force;
170 int recover_wait_time;
171 int error_escalation_time;
172 int max_reply_timeouts;
177 unsigned int max_packet_size;
178 /* Last reset time */
179 volatile time_t last_reset;
180 volatile time_t last_maintain_time;
182 char session_cookie[JK_SHM_STR_SIZ+1];
184 char session_path[JK_SHM_STR_SIZ+1];
187 typedef struct jk_shm_lb_worker jk_shm_lb_worker_t;
189 const char *jk_shm_name(void);
191 /* Calculate needed shm size */
192 size_t jk_shm_calculate_size(jk_map_t *init_data, jk_logger_t *l);
194 /* Open the shared memory creating file if needed
196 int jk_shm_open(const char *fname, size_t sz, jk_logger_t *l);
198 /* Close the shared memory
200 void jk_shm_close(void);
202 /* Attach the shared memory in child process.
203 * File has to be opened in parent.
205 int jk_shm_attach(const char *fname, size_t sz, jk_logger_t *l);
207 /* allocate shm memory
208 * If there is no shm present the pool will be used instead
210 void *jk_shm_alloc(jk_pool_t *p, size_t size);
212 /* allocate shm ajp worker record
213 * If there is no shm present the pool will be used instead
215 jk_shm_ajp_worker_t *jk_shm_alloc_ajp_worker(jk_pool_t *p);
217 /* allocate shm lb sub worker record
218 * If there is no shm present the pool will be used instead
220 jk_shm_lb_sub_worker_t *jk_shm_alloc_lb_sub_worker(jk_pool_t *p);
222 /* allocate shm lb worker record
223 * If there is no shm present the pool will be used instead
225 jk_shm_lb_worker_t *jk_shm_alloc_lb_worker(jk_pool_t *p);
227 /* Return workers.properties last modified time
229 time_t jk_shm_get_workers_time(void);
231 /* Set workers.properties last modified time
233 void jk_shm_set_workers_time(time_t t);
235 /* Check if the shared memory has been modified
236 * by some other process.
238 int jk_shm_is_modified(void);
240 /* Synchronize access and modification time.
241 * This function should be called when the shared memory
242 * is modified and after we update the config acording
243 * to the current shared memory data.
245 void jk_shm_sync_access_time(void);
248 /* Lock shared memory for thread safe access */
249 int jk_shm_lock(void);
251 /* Unlock shared memory for thread safe access */
252 int jk_shm_unlock(void);
257 #endif /* __cplusplus */
258 #endif /* _JK_SHM_H */