提交 c79643c8 authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Ken Rice

move recovery engine up into the core

上级 575f7b6c
......@@ -250,6 +250,11 @@ struct switch_runtime {
char *odbc_user;
char *odbc_pass;
char *dbname;
char *recovery_odbc_dsn;
char *recovery_odbc_user;
char *recovery_odbc_pass;
char *recovery_dbname;
switch_dbtype_t recovery_odbc_dbtype;
uint32_t debug_level;
uint32_t runlevel;
uint32_t tipping_point;
......
......@@ -2288,6 +2288,8 @@ SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh)
SWITCH_DECLARE(void) switch_cache_db_status(switch_stream_handle_t *stream);
SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line);
#define switch_core_db_handle(_a) _switch_core_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(switch_status_t) _switch_core_recovery_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line);
#define switch_core_recovery_db_handle(_a) _switch_core_recovery_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *db,
const char *test_sql, const char *drop_sql, const char *reactive_sql);
......@@ -2344,6 +2346,13 @@ SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl);
SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu);
SWITCH_DECLARE(void) switch_os_yield(void);
SWITCH_DECLARE(switch_status_t) switch_core_get_stacksizes(switch_size_t *cur, switch_size_t *max);
SWITCH_DECLARE(int) switch_core_recovery_recover(const char *technology, const char *profile_name);
SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session, switch_bool_t force);
SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session);
SWITCH_DECLARE(void) switch_core_recovery_flush(const char *technology, const char *profile_name);
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
......
......@@ -184,8 +184,12 @@ struct switch_endpoint_interface {
/* parent */
switch_loadable_module_interface_t *parent;
/* to facilitate linking */
struct switch_endpoint_interface *next;
switch_core_recover_callback_t recover_callback;
};
/*! \brief Abstract handler to a timer module */
......
......@@ -1237,6 +1237,10 @@ typedef enum {
CF_CONFIRM_BLIND_TRANSFER,
CF_NO_PRESENCE,
CF_CONFERENCE,
CF_RECOVERING,
CF_RECOVERING_BRIDGE,
CF_TRACKED,
CF_TRACKABLE,
/* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
/* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */
CF_FLAG_MAX
......@@ -1778,7 +1782,8 @@ typedef enum {
SCSC_SYNC_CLOCK_WHEN_IDLE,
SCSC_DEBUG_SQL,
SCSC_SQL,
SCSC_API_EXPANSION
SCSC_API_EXPANSION,
SCSC_RECOVER
} switch_session_ctl_t;
typedef enum {
......@@ -1891,6 +1896,7 @@ typedef switch_status_t (*switch_chat_application_function_t) (switch_event_t *,
typedef void (*switch_application_function_t) (switch_core_session_t *, const char *);
#define SWITCH_STANDARD_APP(name) static void name (switch_core_session_t *session, const char *data)
typedef int (*switch_core_recover_callback_t)(switch_core_session_t *session);
typedef void (*switch_event_callback_t) (switch_event_t *);
typedef switch_caller_extension_t *(*switch_dialplan_hunt_function_t) (switch_core_session_t *, void *, switch_caller_profile_t *);
#define SWITCH_STANDARD_DIALPLAN(name) static switch_caller_extension_t *name (switch_core_session_t *session, void *arg, switch_caller_profile_t *caller_profile)
......
......@@ -1789,7 +1789,7 @@ SWITCH_STANDARD_API(status_function)
return SWITCH_STATUS_SUCCESS;
}
#define CTL_SYNTAX "[send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"
#define CTL_SYNTAX "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"
SWITCH_STANDARD_API(ctl_function)
{
int argc;
......@@ -1808,6 +1808,13 @@ SWITCH_STANDARD_API(ctl_function)
arg = 1;
switch_core_session_ctl(SCSC_HUPALL, &arg);
stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "recover")) {
int r = switch_core_session_ctl(SCSC_RECOVER, argv[1]);
if (r < 0){
stream->write_function(stream, "+OK flushed\n");
} else {
stream->write_function(stream, "+OK %d session(s) recovered in total\n", r);
}
} else if (!strcasecmp(argv[0], "flush_db_handles")) {
switch_core_session_ctl(SCSC_FLUSH_DB_HANDLES, NULL);
stream->write_function(stream, "+OK\n");
......@@ -5646,6 +5653,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add fsctl pause_check inbound");
switch_console_set_complete("add fsctl pause_check outbound");
switch_console_set_complete("add fsctl ready_check");
switch_console_set_complete("add fsctl recover");
switch_console_set_complete("add fsctl shutdown_check");
switch_console_set_complete("add fsctl shutdown");
switch_console_set_complete("add fsctl shutdown asap");
......
......@@ -1882,6 +1882,18 @@ static void switch_load_core_config(const char *file)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
}
} else if (!strcasecmp(var, "core-recovery-db-dsn") && !zstr(val)) {
if (switch_odbc_available()) {
runtime.recovery_odbc_dsn = switch_core_strdup(runtime.memory_pool, val);
if ((runtime.recovery_odbc_user = strchr(runtime.recovery_odbc_dsn, ':'))) {
*runtime.recovery_odbc_user++ = '\0';
if ((runtime.recovery_odbc_pass = strchr(runtime.recovery_odbc_user, ':'))) {
*runtime.recovery_odbc_pass++ = '\0';
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
}
} else if (!strcasecmp(var, "core-odbc-required") && !zstr(val)) {
switch_set_flag((&runtime), SCF_CORE_ODBC_REQ);
} else if (!strcasecmp(var, "core-dbtype") && !zstr(val)) {
......@@ -2108,6 +2120,44 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
}
switch (cmd) {
case SCSC_RECOVER:
{
char *arg = (char *) val;
char *tech = NULL, *prof = NULL;
int r, flush = 0;
if (!zstr(arg)) {
tech = strdup(arg);
if ((prof = strchr(tech, ':'))) {
*prof++ = '\0';
}
if (!strcasecmp(tech, "flush")) {
flush++;
if (prof) {
tech = prof;
if ((prof = strchr(tech, ':'))) {
*prof++ = '\0';
}
}
}
}
if (flush) {
switch_core_recovery_flush(tech, prof);
r = -1;
} else {
r = switch_core_recovery_recover(tech, prof);
}
switch_safe_free(tech);
return r;
}
break;
case SCSC_DEBUG_SQL:
{
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
......
......@@ -1788,6 +1788,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_xml(switch_e
parse_array(flag_str, flags, CF_FLAG_MAX);
parse_array(cap_str, caps, CC_FLAG_MAX);
flags[CF_RECOVERING] = 0;
flags[CF_RECOVERING_BRIDGE] = 0;
flags[CF_TRACKED] = 0;
flags[CF_TRANSFER] = 0;
flags[CF_ACCEPT_CNG] = 0;
flags[CF_REDIRECT] = 0;
......
差异被折叠。
......@@ -43,9 +43,19 @@ static void switch_core_standard_on_init(switch_core_session_t *session)
static void switch_core_standard_on_hangup(switch_core_session_t *session)
{
switch_caller_extension_t *extension;
int rec;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard HANGUP, cause: %s\n",
switch_channel_get_name(session->channel), switch_channel_cause2str(switch_channel_get_cause(session->channel)));
rec = switch_channel_test_flag(session->channel, CF_RECOVERING);
switch_channel_clear_flag(session->channel, CF_RECOVERING);
if (!rec) {
switch_core_recovery_untrack(session, SWITCH_TRUE);
}
if (!switch_channel_test_flag(session->channel, CF_ZOMBIE_EXEC)) {
return;
......@@ -71,6 +81,9 @@ static void switch_core_standard_on_hangup(switch_core_session_t *session)
}
}
static void switch_core_standard_on_reporting(switch_core_session_t *session)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论