コード例 #1
0
static ngx_bool_t __check_parameter(ngx_str_t * backend_uri, ngx_http_request_t *r)
{
    enum { OFFSET = 0, SIZE, FILE, START, END };
    static const char * keys[] = { "offset", "size", "file", "start", "end" };
    static int value[] = { 0, 0, 0, 0, 0 };
    static const size_t size = sizeof(keys) / sizeof(char *);
    size_t i = 0;
    for (i = 0; i < size; ++i)
    {
        char * val = ngx_http_get_param_val(&r->args, keys[i], r->pool);
        if (!val)
        {
            return false;
        }
        value[i] = atoi(val);
    }
    if (!hustdb_ha_check_hash(value[FILE], value[START], value[END]))
    {
        return false;
    }
    if (!hustdb_ha_check_export(value[OFFSET], value[SIZE]))
    {
        return false;
    }
    return true;
}
コード例 #2
0
ngx_http_subrequest_peer_t * __get_peer_by_args(ngx_http_request_t *r)
{
    char * key = ngx_http_get_param_val(&r->args, "key", r->pool);
    if (!key)
    {
        return NULL;
    }
    return ngx_http_get_first_peer(hustdb_ha_get_readlist(key));
}
コード例 #3
0
static ngx_bool_t __check_parameter(ngx_str_t * backend_uri, ngx_http_request_t *r)
{
    // TODO: you can check the parameter of request here
    char * tb = ngx_http_get_param_val(&r->args, "tb", r->pool);
    if (tb)
    {
        static const char * keys[] = { "file", "start", "end" };
        static const size_t size = sizeof(keys) / sizeof(char *);
        size_t i = 0;
        for (i = 0; i < size; ++i)
        {
            char * val = ngx_http_get_param_val(&r->args, keys[i], r->pool);
            if (val)
            {
                return false; // mutex with "tb" & "type"
            }
        }
        return hustdb_ha_check_key(tb);
    }
    return __check_hash(r);
}
コード例 #4
0
static ngx_bool_t __check_stat_parameter(ngx_str_t * backend_uri, ngx_http_request_t *r)
{
    char * tb = ngx_http_get_param_val(&r->args, "tb", r->pool);
    if (tb)
    {
        if (!hustdb_ha_check_key(tb))
        {
            return false;
        }
    }
    return true;
}
コード例 #5
0
static ngx_bool_t __check_request(ngx_http_request_t *r, hustmq_ha_queue_dict_t * queue_dict, ngx_str_t * queue)
{
	char * val = ngx_http_get_param_val(&r->args, "priori", r->pool);
	if (!val)
	{
		return false;
	}
	size_t size = strlen(val);
	if (1 != size)
	{
		return false;
	}
	return '0' == val[0] || '1' == val[0] || '2' == val[0];
}
コード例 #6
0
static ngx_bool_t __check_zrangebyscore_parameter(ngx_str_t * backend_uri, ngx_http_request_t *r)
{
    static const char * keys[] = { "min", "max" };
    static const size_t size = sizeof(keys) / sizeof(char *);
    size_t i = 0;
    for (i = 0; i < size; ++i)
    {
        char * val = ngx_http_get_param_val(&r->args, keys[i], r->pool);
        if (!val)
        {
            return false;
        }
    }
    return hustdb_ha_check_keys(backend_uri, r);
}
コード例 #7
0
static ngx_bool_t __set_write_context(
    const char * key,
    ngx_bool_t has_tb,
    ngx_http_request_t *r,
    write_ctx_t * ctx)
{
    if (key)
    {
        ctx->key = key;
    }
    else
    {
        ctx->key = ngx_http_get_param_val(&r->args, "key", r->pool);
        if (!ctx->key)
        {
            return false;
        }
    }
    return __parse_args(has_tb, false, r, ctx);
}
コード例 #8
0
static ngx_bool_t __check_hash(ngx_http_request_t *r)
{
    enum { FILE = 0, START, END };
    static const char * keys[] = { "file", "start", "end" };
    static int value[] = { 0, 0, 0 };
    static const size_t size = sizeof(keys) / sizeof(char *);
    size_t i = 0;
    for (i = 0; i < size; ++i)
    {
        char * val = ngx_http_get_param_val(&r->args, keys[i], r->pool);
        if (!val)
        {
            return false;
        }
        value[i] = atoi(val);
    }
    if (!hustdb_ha_check_hash(value[FILE], value[START], value[END]))
    {
        return false;
    }
    return true;
}
コード例 #9
0
static ngx_bool_t __set_write_context(const char * key, ngx_bool_t has_tb, ngx_http_request_t *r, write_ctx_t * ctx)
{
    if (key)
    {
        ctx->key = key;
    }
    else
    {
        ctx->key = ngx_http_get_param_val(&r->args, "key", r->pool);
        if (!ctx->key)
        {
            return false;
        }
    }

    ctx->proto = HUSTDB_PROTO_BINARY;
    char * proto = ngx_http_get_param_val(&r->args, "proto", r->pool);
    if (proto)
    {
        int tmp = atoi(proto);
        if (HUSTDB_PROTO_JSON == tmp)
        {
            ctx->proto = HUSTDB_PROTO_JSON;
        }
        else if (HUSTDB_PROTO_BINARY == tmp)
        {
            ctx->proto = HUSTDB_PROTO_BINARY;
        }
        else
        {
            return false;
        }
    }

    ctx->tb = ngx_http_get_param_val(&r->args, "tb", r->pool);
    if (has_tb && !ctx->tb)
    {
        return false;
    }

    ctx->ttl = 0;
    char * val = ngx_http_get_param_val(&r->args, "ttl", r->pool);
    if (val)
    {
        ctx->ttl = atoi(val);
    }

    ngx_http_hustdb_ha_main_conf_t * mcf = hustdb_ha_get_module_main_conf(r);
    if (!mcf)
    {
        return false;
    }

    ctx->peer = hustdb_ha_get_writelist(ctx->key);
    if (!ctx->peer)
    {
        return false;
    }

    ctx->error_count = 0;
    ctx->error_peer = NULL;
    ctx->state = STATE_WRITE_MASTER1;

    ngx_bool_t alive = ngx_http_peer_is_alive(ctx->peer->peer);
    if (!alive) // master1
    {
        ++ctx->error_count;
        ctx->error_peer = ctx->peer;

        ctx->peer = ctx->peer->next;
        ctx->state = STATE_WRITE_MASTER2;
        alive = ngx_http_peer_is_alive(ctx->peer->peer);
        if (!alive) // master2
        {
            return false;
        }
    }
    return true;
}
コード例 #10
0
static ngx_bool_t __parse_args(
    ngx_bool_t has_tb,
    ngx_bool_t hash_by_tb,
    ngx_http_request_t *r,
    write_ctx_t * ctx)
{
    ctx->tb = ngx_http_get_param_val(&r->args, "tb", r->pool);
    if (has_tb && !ctx->tb)
    {
        return false;
    }

    ctx->ttl = 0;
    char * val = ngx_http_get_param_val(&r->args, "ttl", r->pool);
    if (val)
    {
        ctx->ttl = atoi(val);
    }

    ctx->score = 0;
    val = ngx_http_get_param_val(&r->args, "score", r->pool);
    if (val)
    {
        char * endptr;
        ctx->score = strtoull(val, &endptr, 10);
    }

    ctx->opt = 0;
    val = ngx_http_get_param_val(&r->args, "opt", r->pool);
    if (val)
    {
        ctx->opt = atoi(val);
    }

    ngx_http_hustdb_ha_main_conf_t * mcf = hustdb_ha_get_module_main_conf(r);
    if (!mcf)
    {
        return false;
    }

    ctx->peer = hustdb_ha_get_writelist(hash_by_tb ? ctx->tb : ctx->key);
    if (!ctx->peer)
    {
        return false;
    }

    ctx->error_count = 0;
    ctx->error_peer = NULL;
    ctx->state = STATE_WRITE_MASTER1;

    ngx_bool_t alive = ngx_http_peer_is_alive(ctx->peer->peer);
    if (!alive) // master1
    {
        ++ctx->error_count;
        ctx->error_peer = ctx->peer;

        ctx->peer = ctx->peer->next;
        ctx->state = STATE_WRITE_MASTER2;
        alive = ngx_http_peer_is_alive(ctx->peer->peer);
        if (!alive) // master2
        {
            return false;
        }
    }
    return true;
}