FS-11727: [core] Add SWITCH_DATABASE_FLAG_ROW_SIZE_LIMIT for databases unable to create wide tables.

This commit is contained in:
Andrey Volk 2019-03-24 12:13:26 +04:00
parent 07e0d4f90c
commit 7fc9eafa74
4 changed files with 71 additions and 1 deletions

View File

@ -2653,6 +2653,8 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t
SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *db, 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); const char *test_sql, const char *drop_sql, const char *reactive_sql);
SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *db,
const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries); SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries, SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries,
const char *pre_trans_execute, const char *pre_trans_execute,

View File

@ -619,6 +619,8 @@ struct switch_directory_handle {
struct switch_database_interface { struct switch_database_interface {
/*! the name of the interface */ /*! the name of the interface */
const char *interface_name; const char *interface_name;
/*! flags indicating database specifics, see switch_database_flag_t */
uint32_t flags;
switch_status_t(*handle_new)(char *dsn, switch_database_interface_handle_t **dih); switch_status_t(*handle_new)(char *dsn, switch_database_interface_handle_t **dih);
switch_status_t(*handle_destroy)(switch_database_interface_handle_t **dih); switch_status_t(*handle_destroy)(switch_database_interface_handle_t **dih);
switch_status_t(*flush)(switch_database_interface_handle_t *dih); switch_status_t(*flush)(switch_database_interface_handle_t *dih);

View File

@ -404,6 +404,18 @@ typedef enum {
SWITCH_DATABASE_INTERFACE, SWITCH_DATABASE_INTERFACE,
} switch_module_interface_name_t; } switch_module_interface_name_t;
/*!
\enum switch_database_flag_t
\brief Database flags
<pre>
SWITCH_DATABASE_FLAG_ROW_SIZE_LIMIT = (1 << 0) - Indicates that database has got row-size limit for the combined sizes of all columns.
</pre>
*/
typedef enum {
SWITCH_DATABASE_FLAG_ROW_SIZE_LIMIT = (1 << 0)
} switch_database_flag_enum_t;
typedef uint32_t switch_database_flag_t;
typedef enum { typedef enum {
SUF_NONE = 0, SUF_NONE = 0,
SUF_THREAD_RUNNING = (1 << 0), SUF_THREAD_RUNNING = (1 << 0),

View File

@ -1558,6 +1558,12 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_create_schema(switch_cache_db_ha
*/ */
SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh, SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh,
const char *test_sql, const char *drop_sql, const char *reactive_sql) const char *test_sql, const char *drop_sql, const char *reactive_sql)
{
return switch_cache_db_test_reactive_ex(dbh, test_sql, drop_sql, reactive_sql, NULL);
}
SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *dbh,
const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql)
{ {
switch_bool_t r = SWITCH_TRUE; switch_bool_t r = SWITCH_TRUE;
switch_mutex_t *io_mutex = dbh->io_mutex; switch_mutex_t *io_mutex = dbh->io_mutex;
@ -1596,6 +1602,12 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, reactive_sql, NULL)) != SWITCH_STATUS_SUCCESS) { if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, reactive_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
char tmp[100]; char tmp[100];
switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with reactive_sql", result); switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with reactive_sql", result);
if (row_size_limited_reactive_sql && switch_test_flag(database_interface, SWITCH_DATABASE_FLAG_ROW_SIZE_LIMIT)) {
if ((result = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, row_size_limited_reactive_sql, NULL)) != SWITCH_STATUS_SUCCESS) {
switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to test_reactive with row_size_limited_reactive_sql", result);
}
}
} }
r = result; r = result;
@ -3041,6 +3053,48 @@ static char create_channels_sql[] =
" initial_context VARCHAR(128)\n" " initial_context VARCHAR(128)\n"
");\n"; ");\n";
static char create_row_size_limited_channels_sql[] =
"CREATE TABLE channels (\n"
" uuid VARCHAR(256),\n"
" direction VARCHAR(32),\n"
" created VARCHAR(128),\n"
" created_epoch INTEGER,\n"
" name VARCHAR(1024),\n"
" state VARCHAR(64),\n"
" cid_name VARCHAR(1024),\n"
" cid_num VARCHAR(256),\n"
" ip_addr VARCHAR(256),\n"
" dest VARCHAR(1024),\n"
" application VARCHAR(128),\n"
" application_data VARCHAR(4096),\n"
" dialplan VARCHAR(128),\n"
" context VARCHAR(128),\n"
" read_codec VARCHAR(128),\n"
" read_rate VARCHAR(32),\n"
" read_bit_rate VARCHAR(32),\n"
" write_codec VARCHAR(128),\n"
" write_rate VARCHAR(32),\n"
" write_bit_rate VARCHAR(32),\n"
" secure VARCHAR(64),\n"
" hostname VARCHAR(256),\n"
" presence_id VARCHAR(4096),\n"
" presence_data TEXT,\n"
" accountcode VARCHAR(256),\n"
" callstate VARCHAR(64),\n"
" callee_name VARCHAR(1024),\n"
" callee_num VARCHAR(256),\n"
" callee_direction VARCHAR(5),\n"
" call_uuid VARCHAR(256),\n"
" sent_callee_name VARCHAR(1024),\n"
" sent_callee_num VARCHAR(256),\n"
" initial_cid_name VARCHAR(1024),\n"
" initial_cid_num VARCHAR(256),\n"
" initial_ip_addr VARCHAR(256),\n"
" initial_dest VARCHAR(1024),\n"
" initial_dialplan VARCHAR(128),\n"
" initial_context VARCHAR(128)\n"
");\n";
static char create_calls_sql[] = static char create_calls_sql[] =
"CREATE TABLE calls (\n" "CREATE TABLE calls (\n"
" call_uuid VARCHAR(255),\n" " call_uuid VARCHAR(255),\n"
@ -3758,7 +3812,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
char *err; char *err;
int result = 0; int result = 0;
switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name, initial_cid_name, initial_cid_num, initial_ip_addr, initial_dest, initial_dialplan, initial_context, accountcode from channels", "DROP TABLE channels", create_channels_sql); switch_cache_db_test_reactive_ex(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name, initial_cid_name, initial_cid_num, initial_ip_addr, initial_dest, initial_dialplan, initial_context, accountcode from channels", "DROP TABLE channels", create_channels_sql, create_row_size_limited_channels_sql);
switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql);
switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql);
switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql);