[asterisk-commits] tilghman: branch tilghman/adaptive_realtime r116764 - in /team/tilghman/adapt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 16 12:05:32 CDT 2008
Author: tilghman
Date: Fri May 16 12:05:31 2008
New Revision: 116764
URL: http://svn.digium.com/view/asterisk?view=rev&rev=116764
Log:
Following debugging, add another API that clears the cache when a related realtime family is unloaded
Modified:
team/tilghman/adaptive_realtime/apps/app_meetme.c
team/tilghman/adaptive_realtime/apps/app_queue.c
team/tilghman/adaptive_realtime/apps/app_voicemail.c
team/tilghman/adaptive_realtime/channels/chan_iax2.c
team/tilghman/adaptive_realtime/channels/chan_sip.c
team/tilghman/adaptive_realtime/include/asterisk/config.h
team/tilghman/adaptive_realtime/main/config.c
team/tilghman/adaptive_realtime/res/res_config_odbc.c
Modified: team/tilghman/adaptive_realtime/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_meetme.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_meetme.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_meetme.c Fri May 16 12:05:31 2008
@@ -5679,6 +5679,7 @@
sla_destroy();
res |= ast_custom_function_unregister(&meetme_info_acf);
+ ast_unload_realtime("meetme");
return res;
}
@@ -5716,6 +5717,7 @@
static int reload(void)
{
+ ast_unload_realtime("meetme");
return load_config(1);
}
Modified: team/tilghman/adaptive_realtime/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_queue.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_queue.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_queue.c Fri May 16 12:05:31 2008
@@ -6233,6 +6233,7 @@
}
ao2_ref(queues, -1);
devicestate_tps = ast_taskprocessor_unreference(devicestate_tps);
+ ast_unload_realtime("queue_members");
return res;
}
@@ -6291,6 +6292,7 @@
static int reload(void)
{
+ ast_unload_realtime("queue_members");
reload_queues(1);
return 0;
}
Modified: team/tilghman/adaptive_realtime/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_voicemail.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_voicemail.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_voicemail.c Fri May 16 12:05:31 2008
@@ -9367,6 +9367,9 @@
int tmpadsi[4];
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+ ast_unload_realtime("voicemail");
+ ast_unload_realtime("voicemail_data");
+
if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
return 0;
@@ -10050,6 +10053,8 @@
stop_poll_thread();
mwi_subscription_tps = ast_taskprocessor_unreference(mwi_subscription_tps);
+ ast_unload_realtime("voicemail");
+ ast_unload_realtime("voicemail_data");
return res;
}
Modified: team/tilghman/adaptive_realtime/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/channels/chan_iax2.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/channels/chan_iax2.c (original)
+++ team/tilghman/adaptive_realtime/channels/chan_iax2.c Fri May 16 12:05:31 2008
@@ -11141,6 +11141,7 @@
reload_firmware(0);
iax_provision_reload(1);
+ ast_unload_realtime("iaxpeers");
return 0;
}
@@ -11891,7 +11892,7 @@
con = ast_context_find(regcontext);
if (con)
ast_context_destroy(con, "IAX2");
-
+ ast_unload_realtime("iaxpeers");
return 0;
}
Modified: team/tilghman/adaptive_realtime/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/channels/chan_sip.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/channels/chan_sip.c (original)
+++ team/tilghman/adaptive_realtime/channels/chan_sip.c Fri May 16 12:05:31 2008
@@ -21263,7 +21263,8 @@
time_t run_start, run_end;
run_start = time(0);
-
+ ast_unload_realtime("sipregs");
+ ast_unload_realtime("sippeers");
cfg = ast_config_load(config, config_flags);
/* We *must* have a config file otherwise stop immediately */
@@ -22818,6 +22819,8 @@
con = ast_context_find(used_context);
if (con)
ast_context_destroy(con, "SIP");
+ ast_unload_realtime("sipregs");
+ ast_unload_realtime("sippeers");
return 0;
}
Modified: team/tilghman/adaptive_realtime/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/include/asterisk/config.h?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/include/asterisk/config.h (original)
+++ team/tilghman/adaptive_realtime/include/asterisk/config.h Fri May 16 12:05:31 2008
@@ -82,6 +82,7 @@
typedef int realtime_store(const char *database, const char *table, va_list ap);
typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
typedef int realtime_require(const char *database, const char *table, va_list ap);
+typedef int realtime_unload(const char *database, const char *table);
/*! \brief Configuration engine structure, used to define realtime drivers */
struct ast_config_engine {
@@ -93,6 +94,7 @@
realtime_store *store_func;
realtime_destroy *destroy_func;
realtime_require *require_func;
+ realtime_unload *unload_func;
struct ast_config_engine *next;
};
@@ -197,6 +199,14 @@
*/
struct ast_variable *ast_load_realtime(const char *family, ...) attribute_sentinel;
struct ast_variable *ast_load_realtime_all(const char *family, ...) attribute_sentinel;
+
+/*!
+ * \brief Release any resources cached for a realtime family
+ * \param family which family/config to destroy
+ * Various backends may cache attributes about a realtime data storage
+ * facility; on reload, a front end resource may request to purge that cache.
+ */
+int ast_unload_realtime(const char *family);
/*!
* \brief Inform realtime what fields that may be stored
Modified: team/tilghman/adaptive_realtime/main/config.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/main/config.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/main/config.c (original)
+++ team/tilghman/adaptive_realtime/main/config.c Fri May 16 12:05:31 2008
@@ -2115,6 +2115,20 @@
return res;
}
+int ast_unload_realtime(const char *family)
+{
+ struct ast_config_engine *eng;
+ char db[256] = "";
+ char table[256] = "";
+ int res = -1;
+
+ eng = find_engine(family, db, sizeof(db), table, sizeof(table));
+ if (eng && eng->unload_func) {
+ res = eng->unload_func(db, table);
+ }
+ return res;
+}
+
struct ast_config *ast_load_realtime_multientry(const char *family, ...)
{
struct ast_config_engine *eng;
Modified: team/tilghman/adaptive_realtime/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/res/res_config_odbc.c?view=diff&rev=116764&r1=116763&r2=116764
==============================================================================
--- team/tilghman/adaptive_realtime/res/res_config_odbc.c (original)
+++ team/tilghman/adaptive_realtime/res/res_config_odbc.c Fri May 16 12:05:31 2008
@@ -59,6 +59,7 @@
static void destroy_table_cache(struct odbc_cache_tables *table) {
struct odbc_cache_columns *col;
+ ast_debug(1, "Destroying table cache for %s\n", table->table);
AST_RWLIST_WRLOCK(&table->columns);
while ((col = AST_RWLIST_REMOVE_HEAD(&table->columns, list))) {
ast_free(col);
@@ -78,7 +79,7 @@
* When a structure is returned, the contained columns list will be
* rdlock'ed, to ensure that it will be retained in memory.
*/
-static struct odbc_cache_tables *find_table(const char *database, const char *table)
+static struct odbc_cache_tables *find_table(const char *database, const char *tablename)
{
struct odbc_cache_tables *tableptr;
struct odbc_cache_columns *entry;
@@ -90,18 +91,18 @@
AST_RWLIST_RDLOCK(&odbc_tables);
AST_RWLIST_TRAVERSE(&odbc_tables, tableptr, list) {
- if (strcmp(tableptr->connection, database) == 0 && strcmp(tableptr->table, table) == 0) {
+ if (strcmp(tableptr->connection, database) == 0 && strcmp(tableptr->table, tablename) == 0) {
break;
}
}
- if (table) {
+ if (tableptr) {
AST_RWLIST_RDLOCK(&tableptr->columns);
AST_RWLIST_UNLOCK(&odbc_tables);
return tableptr;
}
if (!obj) {
- ast_log(LOG_WARNING, "Unable to retrieve database handle for table description '%s@%s'\n", table, database);
+ ast_log(LOG_WARNING, "Unable to retrieve database handle for table description '%s@%s'\n", tablename, database);
return NULL;
}
@@ -119,7 +120,7 @@
break;
}
- res = SQLColumns(stmt, NULL, 0, NULL, 0, (unsigned char *)table, SQL_NTS, (unsigned char *)"%", SQL_NTS);
+ res = SQLColumns(stmt, NULL, 0, NULL, 0, (unsigned char *)tablename, SQL_NTS, (unsigned char *)"%", SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
if (try == 0) {
try = 1;
@@ -131,22 +132,22 @@
break;
}
- if (!(tableptr = ast_calloc(sizeof(char), sizeof(*table) + strlen(database) + 1 + strlen(table) + 1))) {
- ast_log(LOG_ERROR, "Out of memory creating entry for table '%s' on connection '%s'\n", table, database);
+ if (!(tableptr = ast_calloc(sizeof(char), sizeof(*tableptr) + strlen(database) + 1 + strlen(tablename) + 1))) {
+ ast_log(LOG_ERROR, "Out of memory creating entry for table '%s' on connection '%s'\n", tablename, database);
break;
}
tableptr->connection = (char *)tableptr + sizeof(*tableptr);
tableptr->table = (char *)tableptr + sizeof(*tableptr) + strlen(database) + 1;
strcpy(tableptr->connection, database); /* SAFE */
- strcpy(tableptr->table, table); /* SAFE */
+ strcpy(tableptr->table, tablename); /* SAFE */
AST_RWLIST_HEAD_INIT(&(tableptr->columns));
while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
SQLGetData(stmt, 4, SQL_C_CHAR, columnname, sizeof(columnname), &sqlptr);
if (!(entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(columnname) + 1))) {
- ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, table, database);
+ ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, tablename, database);
error = 1;
break;
}
@@ -181,7 +182,7 @@
if (error) {
destroy_table_cache(tableptr);
- table = NULL;
+ tableptr = NULL;
}
if (obj) {
ast_odbc_release_obj(obj);
@@ -955,10 +956,30 @@
break;
}
}
+ if (!col) {
+ ast_log(LOG_WARNING, "Table %s@%s requires column '%s', but that column does not exist!\n", table, database, elm);
+ }
}
va_end(ap);
AST_RWLIST_UNLOCK(&tableptr->columns);
return 0;
+}
+
+static int unload_odbc(const char *database, const char *tablename)
+{
+ struct odbc_cache_tables *tableptr;
+
+ AST_RWLIST_RDLOCK(&odbc_tables);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&odbc_tables, tableptr, list) {
+ if (strcmp(tableptr->connection, database) == 0 && strcmp(tableptr->table, tablename) == 0) {
+ AST_LIST_REMOVE_CURRENT(list);
+ destroy_table_cache(tableptr);
+ break;
+ }
+ }
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&odbc_tables);
+ return tableptr ? 0 : -1;
}
static struct ast_config_engine odbc_engine = {
@@ -970,11 +991,22 @@
.destroy_func = destroy_odbc,
.update_func = update_odbc,
.require_func = require_odbc,
+ .unload_func = unload_odbc,
};
static int unload_module (void)
{
+ struct odbc_cache_tables *table;
+
ast_config_engine_deregister(&odbc_engine);
+
+ /* Empty the cache */
+ AST_RWLIST_WRLOCK(&odbc_tables);
+ while ((table = AST_RWLIST_REMOVE_HEAD(&odbc_tables, list))) {
+ destroy_table_cache(table);
+ }
+ AST_RWLIST_UNLOCK(&odbc_tables);
+
ast_verb(1, "res_config_odbc unloaded.\n");
return 0;
}
More information about the asterisk-commits
mailing list