Fix (foreign|own)_session, call_duration stats: modify call_get_or_create to set stats and foreign call state

pull/225/head
Lucian Balaceanu 10 years ago
parent 8fb677bccb
commit 859a5058e6

@ -2286,7 +2286,7 @@ static struct call *call_create(const str *callid, struct callmaster *m) {
} }
/* returns call with master_lock held in W */ /* returns call with master_lock held in W */
struct call *call_get_or_create(const str *callid, struct callmaster *m) { struct call *call_get_or_create(const str *callid, struct callmaster *m, enum call_type type) {
struct call *c; struct call *c;
restart: restart:
@ -2304,12 +2304,21 @@ restart:
goto restart; goto restart;
} }
g_hash_table_insert(m->callhash, &c->callid, obj_get(c)); g_hash_table_insert(m->callhash, &c->callid, obj_get(c));
if(! IS_BACKUP_CALL(c)) {
if (type == CT_OWN_CALL) {
mutex_lock(&m->totalstats_interval.managed_sess_lock); mutex_lock(&m->totalstats_interval.managed_sess_lock);
m->totalstats_interval.managed_sess_max = MAX(m->totalstats_interval.managed_sess_max, m->totalstats_interval.managed_sess_max = MAX(
g_hash_table_size(m->callhash) - atomic64_get(&m->stats.foreign_sessions)); m->totalstats_interval.managed_sess_max,
g_hash_table_size(m->callhash)
- atomic64_get(&m->stats.foreign_sessions));
mutex_unlock(&m->totalstats_interval.managed_sess_lock); mutex_unlock(&m->totalstats_interval.managed_sess_lock);
} }
else if (type == CT_FOREIGN_CALL) { /* foreign call*/
c->redis_foreign_call = 1;
c->is_backup_call = 1;
atomic64_inc(&m->stats.foreign_sessions);
atomic64_inc(&m->totalstats.total_foreign_sessions);
}
rwlock_lock_w(&c->master_lock); rwlock_lock_w(&c->master_lock);
rwlock_unlock_w(&m->hashlock); rwlock_unlock_w(&m->hashlock);
} }
@ -2345,7 +2354,7 @@ struct call *call_get(const str *callid, struct callmaster *m) {
/* returns call with master_lock held in W, or possibly NULL iff opmode == OP_ANSWER */ /* returns call with master_lock held in W, or possibly NULL iff opmode == OP_ANSWER */
struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_opmode opmode) { struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_opmode opmode) {
if (opmode == OP_OFFER) if (opmode == OP_OFFER)
return call_get_or_create(callid, m); return call_get_or_create(callid, m, CT_OWN_CALL);
return call_get(callid, m); return call_get(callid, m);
} }

@ -79,6 +79,11 @@ enum call_stream_state {
CSS_RUNNING, CSS_RUNNING,
}; };
enum call_type {
CT_OWN_CALL = 0,
CT_FOREIGN_CALL,
};
#include "obj.h" #include "obj.h"
#include "aux.h" #include "aux.h"
#include "bencode.h" #include "bencode.h"
@ -491,7 +496,7 @@ void __monologue_viabranch(struct call_monologue *ml, const str *viabranch);
struct packet_stream *__packet_stream_new(struct call *call); struct packet_stream *__packet_stream_new(struct call *call);
struct call *call_get_or_create(const str *callid, struct callmaster *m); struct call *call_get_or_create(const str *callid, struct callmaster *m, enum call_type);
struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_opmode opmode); struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_opmode opmode);
struct call_monologue *call_get_mono_dialogue(struct call *call, const str *fromtag, const str *totag, struct call_monologue *call_get_mono_dialogue(struct call *call, const str *fromtag, const str *totag,
const str *viabranch); const str *viabranch);

@ -233,7 +233,7 @@ int str_cut(char *str, int begin, int len) {
return len; return len;
} }
static void redis_restore_call(struct redis *r, struct callmaster *m, const redisReply *id); static void redis_restore_call(struct redis *r, struct callmaster *m, const redisReply *id, enum call_type);
static int redis_check_conn(struct redis *r); static int redis_check_conn(struct redis *r);
void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) { void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
@ -315,15 +315,7 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
rlog(LOG_INFO, "Redis-Notifier: Call already exists with this callid:%s\n", rr->element[2]->str); rlog(LOG_INFO, "Redis-Notifier: Call already exists with this callid:%s\n", rr->element[2]->str);
goto err; goto err;
} }
redis_restore_call(r, cm, rr->element[2]); redis_restore_call(r, cm, rr->element[2], CT_FOREIGN_CALL);
// we lookup again to retrieve the call to insert the kayspace db id
c = g_hash_table_lookup(cm->callhash, &callid);
if (c) {
c->redis_foreign_call = 1;
c->is_backup_call = 1;
atomic64_inc(&cm->stats.foreign_sessions);
atomic64_inc(&cm->totalstats.total_foreign_sessions);
}
} }
if (strncmp(rr->element[3]->str,"del",3)==0) { if (strncmp(rr->element[3]->str,"del",3)==0) {
@ -1211,7 +1203,7 @@ static int redis_link_maps(struct redis *r, struct call *c, struct redis_list *m
} }
static void redis_restore_call(struct redis *r, struct callmaster *m, const redisReply *id) { static void redis_restore_call(struct redis *r, struct callmaster *m, const redisReply *id, enum call_type type) {
struct redis_hash call; struct redis_hash call;
struct redis_list tags, sfds, streams, medias, maps; struct redis_list tags, sfds, streams, medias, maps;
struct call *c = NULL; struct call *c = NULL;
@ -1241,7 +1233,7 @@ static void redis_restore_call(struct redis *r, struct callmaster *m, const redi
str_init_len(&s, id->str, id->len); str_init_len(&s, id->str, id->len);
//s.s = id->str; //s.s = id->str;
//s.len = id->len; //s.len = id->len;
c = call_get_or_create(&s, m); c = call_get_or_create(&s, m, type);
err = "failed to create call struct"; err = "failed to create call struct";
if (!c) if (!c)
goto err8; goto err8;
@ -1348,7 +1340,7 @@ static void restore_thread(void *call_p, void *ctx_p) {
r = g_queue_pop_head(&ctx->r_q); r = g_queue_pop_head(&ctx->r_q);
mutex_unlock(&ctx->r_m); mutex_unlock(&ctx->r_m);
redis_restore_call(r, ctx->m, call); redis_restore_call(r, ctx->m, call, CT_OWN_CALL);
mutex_lock(&ctx->r_m); mutex_lock(&ctx->r_m);
g_queue_push_tail(&ctx->r_q, r); g_queue_push_tail(&ctx->r_q, r);

Loading…
Cancel
Save