Skip to content

Commit 09b3753

Browse files
committed
Basic load balancer for #286
1 parent 237eb5f commit 09b3753

File tree

8 files changed

+350
-11
lines changed

8 files changed

+350
-11
lines changed

src/c/ngx_http_clojure_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4565,7 +4565,7 @@ int ngx_http_clojure_register_script(ngx_int_t phase, ngx_str_t *handler_type,
45654565
return NGX_HTTP_CLOJURE_JVM_OK;
45664566
}
45674567

4568-
int ngx_http_clojure_eval(int cid, ngx_http_request_t *r, ngx_chain_t *c) {
4568+
int ngx_http_clojure_eval(int cid, ngx_http_request_t *r, void *c) {
45694569
JNIEnv *env = jvm_env;
45704570
int rc;
45714571
/* log_debug1(ngx_http_clojure_global_cycle->log, "ngx clojure eval request: %ul", (uintptr_t)r);*/

src/c/ngx_http_clojure_mem.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef unsigned __int64 uint64_t;
4141
#define JVM_CP_SEP_S ":"
4242
#endif
4343

44-
#define nginx_clojure_ver 6001 /*0.6.0*/
44+
#define nginx_clojure_ver 6001 /*0.6.1*/
4545

4646
/*the least jar version required*/
4747
#define nginx_clojure_required_rt_lver 5002
@@ -50,6 +50,9 @@ typedef unsigned __int64 uint64_t;
5050

5151
#define NGINX_CLOJURE_VER "nginx-clojure/" NGINX_CLOJURE_VER_NUM_STR
5252

53+
/*fake phase for load balance handler*/
54+
#define NGX_HTTP_LOAD_BALANCE_PHASE 16
55+
5356
/*fake phase for filter*/
5457
#define NGX_HTTP_INIT_PROCESS_PHASE 17
5558
#define NGX_HTTP_HEADER_FILTER_PHASE 18
@@ -86,6 +89,7 @@ typedef struct {
8689
unsigned enable_body_filter :1;
8790
unsigned enable_access_handler : 1;
8891
unsigned enable_log_handler : 1;
92+
unsigned enable_load_balancer : 1;
8993
ngx_str_t jvm_handler_type;
9094
ngx_str_t jvm_init_handler_code;
9195
ngx_int_t jvm_init_handler_id;
@@ -146,6 +150,27 @@ typedef struct {
146150
size_t write_page_size;
147151
} ngx_http_clojure_loc_conf_t;
148152

153+
154+
typedef struct {
155+
unsigned enable_load_balancer :1;
156+
ngx_str_t load_balancer_type;
157+
ngx_str_t load_balancer_code;
158+
ngx_int_t load_balancer_id;
159+
ngx_str_t load_balancer_name;
160+
ngx_array_t *load_balancer_properties;
161+
} ngx_http_clojure_srv_conf_t;
162+
163+
typedef struct {
164+
/* the round robin data must be first */
165+
ngx_http_upstream_rr_peer_data_t rrp;
166+
ngx_http_clojure_srv_conf_t *conf;
167+
ngx_http_request_t *r;
168+
ngx_int_t peer_pos_or_len;
169+
u_char *peer_url;
170+
/* ngx_uint_t tries; */
171+
/* ngx_event_get_peer_pt get_rr_peer; */
172+
} ngx_http_clojure_upstream_load_balancer_peer_data_t;
173+
149174
typedef struct ngx_http_clojure_listener_node_s {
150175
void *listener;
151176
void *data;
@@ -606,7 +631,7 @@ int ngx_http_clojure_destroy_memory_util(ngx_log_t *log);
606631
int ngx_http_clojure_register_script(ngx_int_t phase, ngx_str_t *handler_type,
607632
ngx_str_t *handler, ngx_str_t *code, ngx_array_t *pros, ngx_int_t *pcid);
608633

609-
int ngx_http_clojure_eval(int cid, ngx_http_request_t *r, ngx_chain_t *c);
634+
int ngx_http_clojure_eval(int cid, ngx_http_request_t *r, void *c);
610635

611636
ngx_int_t ngx_http_clojure_hijack_send_header(ngx_http_request_t *r, ngx_int_t flag);
612637

0 commit comments

Comments
 (0)