MXS-1840 Compile all routers as C++
Minimal changes, only what is needed in order to make it compile.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
if(AVRO_FOUND AND JANSSON_FOUND)
|
||||
include_directories(${AVRO_INCLUDE_DIR})
|
||||
include_directories(${JANSSON_INCLUDE_DIR})
|
||||
add_library(avrorouter SHARED avro.c ../binlogrouter/binlog_common.c avro_client.c avro_schema.c avro_rbr.c avro_file.c avro_index.c)
|
||||
add_library(avrorouter SHARED avro.cc ../binlogrouter/binlog_common.cc avro_client.cc avro_schema.cc avro_rbr.cc avro_file.cc avro_index.cc)
|
||||
set_target_properties(avrorouter PROPERTIES VERSION "1.0.0")
|
||||
set_target_properties(avrorouter PROPERTIES LINK_FLAGS -Wl,-z,defs)
|
||||
target_link_libraries(avrorouter maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro lzma)
|
||||
|
@ -195,7 +195,7 @@ static bool avro_handle_purge(const MODULECMD_ARG *args, json_t** output)
|
||||
*
|
||||
* @return The module object
|
||||
*/
|
||||
MXS_MODULE* MXS_CREATE_MODULE()
|
||||
extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
{
|
||||
spinlock_init(&instlock);
|
||||
instances = NULL;
|
||||
@ -297,7 +297,7 @@ bool create_tables(sqlite3* handle)
|
||||
NULL, NULL, &errmsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to create GTID index table '"GTID_TABLE_NAME"': %s",
|
||||
MXS_ERROR("Failed to create GTID index table '" GTID_TABLE_NAME "': %s",
|
||||
sqlite3_errmsg(handle));
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
@ -310,7 +310,7 @@ bool create_tables(sqlite3* handle)
|
||||
NULL, NULL, &errmsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to create used tables table '"USED_TABLES_TABLE_NAME"': %s",
|
||||
MXS_ERROR("Failed to create used tables table '" USED_TABLES_TABLE_NAME "': %s",
|
||||
sqlite3_errmsg(handle));
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
@ -321,17 +321,17 @@ bool create_tables(sqlite3* handle)
|
||||
NULL, NULL, &errmsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to create indexing progress table '"INDEX_TABLE_NAME"': %s",
|
||||
MXS_ERROR("Failed to create indexing progress table '" INDEX_TABLE_NAME "': %s",
|
||||
sqlite3_errmsg(handle));
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = sqlite3_exec(handle, "ATTACH DATABASE ':memory:' AS "MEMORY_DATABASE_NAME,
|
||||
rc = sqlite3_exec(handle, "ATTACH DATABASE ':memory:' AS " MEMORY_DATABASE_NAME,
|
||||
NULL, NULL, &errmsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to attach in-memory database '"MEMORY_DATABASE_NAME"': %s",
|
||||
MXS_ERROR("Failed to attach in-memory database '" MEMORY_DATABASE_NAME "': %s",
|
||||
sqlite3_errmsg(handle));
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
@ -344,8 +344,8 @@ bool create_tables(sqlite3* handle)
|
||||
NULL, NULL, &errmsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to create in-memory used tables table '"MEMORY_DATABASE_NAME
|
||||
"."MEMORY_TABLE_NAME"': %s",
|
||||
MXS_ERROR("Failed to create in-memory used tables table '" MEMORY_DATABASE_NAME
|
||||
"." MEMORY_TABLE_NAME "': %s",
|
||||
sqlite3_errmsg(handle));
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
@ -479,7 +479,7 @@ createInstance(SERVICE *service, char **options)
|
||||
AVRO_INSTANCE *inst;
|
||||
int i;
|
||||
|
||||
if ((inst = MXS_CALLOC(1, sizeof(AVRO_INSTANCE))) == NULL)
|
||||
if ((inst = static_cast<AVRO_INSTANCE*>(MXS_CALLOC(1, sizeof(AVRO_INSTANCE)))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -506,7 +506,7 @@ createInstance(SERVICE *service, char **options)
|
||||
inst->fileroot = MXS_STRDUP_A(config_get_string(params, "filestem"));
|
||||
inst->row_target = config_get_integer(params, "group_rows");
|
||||
inst->trx_target = config_get_integer(params, "group_trx");
|
||||
inst->codec = config_get_enum(params, "codec", codec_values);
|
||||
inst->codec = static_cast<mxs_avro_codec_type>(config_get_enum(params, "codec", codec_values));
|
||||
int first_file = config_get_integer(params, "start_index");
|
||||
inst->block_size = config_get_size(params, "block_size");
|
||||
|
||||
@ -798,7 +798,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session)
|
||||
|
||||
CHK_CLIENT_RSES(client);
|
||||
|
||||
return (void *) client;
|
||||
return reinterpret_cast<MXS_ROUTER_SESSION*>(client);
|
||||
}
|
||||
|
||||
/**
|
@ -156,7 +156,7 @@ avro_client_do_registration(AVRO_INSTANCE *router, AVRO_CLIENT *client, GWBUF *d
|
||||
*sep_ptr = '\0';
|
||||
}
|
||||
|
||||
if (strlen(uuid) < uuid_len)
|
||||
if (strlen(uuid) < static_cast<size_t>(uuid_len))
|
||||
{
|
||||
data_len -= (uuid_len - strlen(uuid));
|
||||
}
|
||||
@ -288,7 +288,7 @@ int gtid_query_cb_plain(void* data, int ncolumns, char** values, char** names)
|
||||
void add_used_tables(sqlite3 *handle, json_t* obj, gtid_pos_t* gtid)
|
||||
{
|
||||
char sql[AVRO_SQL_BUFFER_SIZE];
|
||||
snprintf(sql, sizeof(sql), "SELECT table_name FROM "USED_TABLES_TABLE_NAME
|
||||
snprintf(sql, sizeof(sql), "SELECT table_name FROM " USED_TABLES_TABLE_NAME
|
||||
" WHERE domain = %lu AND server_id = %lu AND sequence = %lu",
|
||||
gtid->domain, gtid->server_id, gtid->seq);
|
||||
|
||||
@ -320,7 +320,7 @@ void avro_get_used_tables(AVRO_INSTANCE *router, DCB* dcb)
|
||||
{
|
||||
sqlite3 *handle = router->sqlite_handle;
|
||||
char sql[AVRO_SQL_BUFFER_SIZE];
|
||||
snprintf(sql, sizeof(sql), "SELECT table_name FROM "USED_TABLES_TABLE_NAME
|
||||
snprintf(sql, sizeof(sql), "SELECT table_name FROM " USED_TABLES_TABLE_NAME
|
||||
" WHERE domain = %lu AND server_id = %lu AND sequence = %lu",
|
||||
router->gtid.domain, router->gtid.server_id, router->gtid.seq);
|
||||
|
||||
@ -366,7 +366,7 @@ int timestamp_query_cb(void* data, int ncolumns, char** values, char** names)
|
||||
void add_timestamp(sqlite3 *handle, json_t* obj, gtid_pos_t* gtid)
|
||||
{
|
||||
char sql[AVRO_SQL_BUFFER_SIZE];
|
||||
snprintf(sql, sizeof(sql), "SELECT DISTINCT binlog_timestamp FROM "USED_TABLES_TABLE_NAME
|
||||
snprintf(sql, sizeof(sql), "SELECT DISTINCT binlog_timestamp FROM " USED_TABLES_TABLE_NAME
|
||||
" WHERE domain = %lu AND server_id = %lu AND sequence = %lu",
|
||||
gtid->domain, gtid->server_id, gtid->seq);
|
||||
|
@ -103,7 +103,7 @@ void avro_close_binlog(int fd)
|
||||
AVRO_TABLE* avro_table_alloc(const char* filepath, const char* json_schema, const char *codec,
|
||||
size_t block_size)
|
||||
{
|
||||
AVRO_TABLE *table = MXS_CALLOC(1, sizeof(AVRO_TABLE));
|
||||
AVRO_TABLE *table = static_cast<AVRO_TABLE*>(MXS_CALLOC(1, sizeof(AVRO_TABLE)));
|
||||
if (table)
|
||||
{
|
||||
if (avro_schema_from_json_length(json_schema, strlen(json_schema),
|
||||
@ -163,7 +163,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router)
|
||||
FILE *config_file;
|
||||
char filename[PATH_MAX + 1];
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE".tmp", router->avrodir);
|
||||
snprintf(filename, sizeof(filename), "%s/" AVRO_PROGRESS_FILE ".tmp", router->avrodir);
|
||||
|
||||
/* open file for writing */
|
||||
config_file = fopen(filename, "wb");
|
||||
@ -184,7 +184,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router)
|
||||
|
||||
/* rename tmp file to right filename */
|
||||
char newname[PATH_MAX + 1];
|
||||
snprintf(newname, sizeof(newname), "%s/"AVRO_PROGRESS_FILE, router->avrodir);
|
||||
snprintf(newname, sizeof(newname), "%s/" AVRO_PROGRESS_FILE, router->avrodir);
|
||||
int rc = rename(filename, newname);
|
||||
|
||||
if (rc == -1)
|
||||
@ -266,7 +266,7 @@ bool avro_load_conversion_state(AVRO_INSTANCE *router)
|
||||
char filename[PATH_MAX + 1];
|
||||
bool rval = false;
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE, router->avrodir);
|
||||
snprintf(filename, sizeof(filename), "%s/" AVRO_PROGRESS_FILE, router->avrodir);
|
||||
|
||||
/** No stored state, this is the first time the router is started */
|
||||
if (access(filename, F_OK) == -1)
|
||||
@ -340,7 +340,7 @@ static avro_binlog_end_t rotate_to_next_file_if_exists(AVRO_INSTANCE* router, ui
|
||||
char next_binlog[BINLOG_FNAMELEN + 1];
|
||||
if (snprintf(next_binlog, sizeof(next_binlog),
|
||||
BINLOG_NAMEFMT, router->fileroot,
|
||||
blr_file_get_next_binlogname(router->binlog_name)) >= sizeof(next_binlog))
|
||||
blr_file_get_next_binlogname(router->binlog_name)) >= (int)sizeof(next_binlog))
|
||||
{
|
||||
MXS_ERROR("Next binlog name did not fit into the allocated buffer "
|
||||
"but was truncated, aborting: %s", next_binlog);
|
||||
@ -416,7 +416,7 @@ static GWBUF* read_event_data(AVRO_INSTANCE *router, REP_HEADER* hdr, uint64_t p
|
||||
/** NULL-terminate for QUERY_EVENT processing */
|
||||
data[hdr->event_size - BINLOG_EVENT_HDR_LEN] = '\0';
|
||||
|
||||
if (n != hdr->event_size - BINLOG_EVENT_HDR_LEN)
|
||||
if (n != static_cast<int>(hdr->event_size - BINLOG_EVENT_HDR_LEN))
|
||||
{
|
||||
if (n == -1)
|
||||
{
|
||||
@ -824,7 +824,8 @@ void avro_load_metadata_from_schemas(AVRO_INSTANCE *router)
|
||||
if (versionend == suffix)
|
||||
{
|
||||
snprintf(table_ident, sizeof(table_ident), "%s.%s", db, table);
|
||||
TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident);
|
||||
TABLE_CREATE *old =
|
||||
static_cast<TABLE_CREATE*>(hashtable_fetch(router->created_tables, table_ident));
|
||||
|
||||
if (old == NULL || version > old->version)
|
||||
{
|
||||
@ -860,7 +861,7 @@ void avro_flush_all_tables(AVRO_INSTANCE *router, enum avrorouter_file_op flush)
|
||||
char *key;
|
||||
while ((key = (char*)hashtable_next(iter)))
|
||||
{
|
||||
AVRO_TABLE *table = hashtable_fetch(router->open_tables, key);
|
||||
AVRO_TABLE *table = static_cast<AVRO_TABLE*>(hashtable_fetch(router->open_tables, key));
|
||||
|
||||
if (table)
|
||||
{
|
||||
@ -974,18 +975,18 @@ bool save_and_replace_table_create(AVRO_INSTANCE *router, TABLE_CREATE *created)
|
||||
snprintf(table_ident, sizeof(table_ident), "%s.%s", created->database, created->table);
|
||||
|
||||
spinlock_acquire(&router->lock); // Is this necessary?
|
||||
TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident);
|
||||
TABLE_CREATE *old = static_cast<TABLE_CREATE*>(hashtable_fetch(router->created_tables, table_ident));
|
||||
|
||||
if (old)
|
||||
{
|
||||
HASHITERATOR *iter = hashtable_iterator(router->table_maps);
|
||||
|
||||
char *key;
|
||||
while ((key = hashtable_next(iter)))
|
||||
while ((key = static_cast<char*>(hashtable_next(iter))))
|
||||
{
|
||||
if (strcmp(key, table_ident) == 0)
|
||||
{
|
||||
TABLE_MAP* map = hashtable_fetch(router->table_maps, key);
|
||||
TABLE_MAP* map = static_cast<TABLE_MAP*>(hashtable_fetch(router->table_maps, key));
|
||||
router->active_maps[map->id % MAX_MAPPED_TABLES] = NULL;
|
||||
hashtable_delete(router->table_maps, key);
|
||||
}
|
||||
@ -1066,7 +1067,7 @@ void handle_query_event(AVRO_INSTANCE *router, REP_HEADER *hdr, int *pending_tra
|
||||
db[dblen] = 0;
|
||||
|
||||
size_t sqlsz = len, tmpsz = len;
|
||||
char *tmp = MXS_MALLOC(len + 1);
|
||||
char *tmp = static_cast<char*>(MXS_MALLOC(len + 1));
|
||||
MXS_ABORT_IF_NULL(tmp);
|
||||
remove_mysql_comments((const char**)&sql, &sqlsz, &tmp, &tmpsz);
|
||||
sql = tmp;
|
||||
@ -1126,7 +1127,7 @@ void handle_query_event(AVRO_INSTANCE *router, REP_HEADER *hdr, int *pending_tra
|
||||
}
|
||||
else if (is_alter_table_statement(router, sql, len))
|
||||
{
|
||||
TABLE_CREATE *created = hashtable_fetch(router->created_tables, ident);
|
||||
TABLE_CREATE *created = static_cast<TABLE_CREATE*>(hashtable_fetch(router->created_tables, ident));
|
||||
|
||||
if (created)
|
||||
{
|
@ -76,7 +76,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename)
|
||||
|
||||
if (file)
|
||||
{
|
||||
char *name = strrchr(filename, '/');
|
||||
const char *name = strrchr(filename, '/');
|
||||
ss_dassert(name);
|
||||
|
||||
if (name)
|
||||
@ -86,7 +86,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename)
|
||||
long pos = -1;
|
||||
name++;
|
||||
|
||||
snprintf(sql, sizeof(sql), "SELECT position FROM "INDEX_TABLE_NAME
|
||||
snprintf(sql, sizeof(sql), "SELECT position FROM " INDEX_TABLE_NAME
|
||||
" WHERE filename=\"%s\";", name);
|
||||
|
||||
if (sqlite3_exec(router->sqlite_handle, sql, index_query_cb, &pos, &errmsg) != SQLITE_OK)
|
||||
@ -155,7 +155,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename)
|
||||
}
|
||||
sqlite3_free(errmsg);
|
||||
|
||||
snprintf(sql, sizeof(sql), "INSERT OR REPLACE INTO "INDEX_TABLE_NAME
|
||||
snprintf(sql, sizeof(sql), "INSERT OR REPLACE INTO " INDEX_TABLE_NAME
|
||||
" values (%lu, \"%s\");", file->block_start_pos, name);
|
||||
if (sqlite3_exec(router->sqlite_handle, sql, NULL, NULL,
|
||||
&errmsg) != SQLITE_OK)
|
||||
@ -194,7 +194,7 @@ void avro_update_index(AVRO_INSTANCE* router)
|
||||
|
||||
if (glob(path, 0, NULL, &files) != GLOB_NOMATCH)
|
||||
{
|
||||
for (int i = 0; i < files.gl_pathc; i++)
|
||||
for (size_t i = 0; i < files.gl_pathc; i++)
|
||||
{
|
||||
avro_index_file(router, files.gl_pathv[i]);
|
||||
}
|
||||
@ -204,7 +204,7 @@ void avro_update_index(AVRO_INSTANCE* router)
|
||||
}
|
||||
|
||||
/** The SQL for the in-memory used_tables table */
|
||||
static const char *insert_sql = "INSERT OR IGNORE INTO "MEMORY_TABLE_NAME
|
||||
static const char *insert_sql = "INSERT OR IGNORE INTO " MEMORY_TABLE_NAME
|
||||
"(domain, server_id, sequence, binlog_timestamp, table_name)"
|
||||
" VALUES (%lu, %lu, %lu, %u, \"%s\")";
|
||||
|
||||
@ -217,7 +217,7 @@ static const char *insert_sql = "INSERT OR IGNORE INTO "MEMORY_TABLE_NAME
|
||||
* @param router Avro router instance
|
||||
* @param table Table to add
|
||||
*/
|
||||
void add_used_table(AVRO_INSTANCE* router, char* table)
|
||||
void add_used_table(AVRO_INSTANCE* router, const char* table)
|
||||
{
|
||||
char sql[AVRO_SQL_BUFFER_SIZE], *errmsg;
|
||||
snprintf(sql, sizeof(sql), insert_sql, router->gtid.domain, router->gtid.server_id,
|
||||
@ -244,14 +244,14 @@ void update_used_tables(AVRO_INSTANCE* router)
|
||||
{
|
||||
char *errmsg;
|
||||
|
||||
if (sqlite3_exec(router->sqlite_handle, "INSERT INTO "USED_TABLES_TABLE_NAME
|
||||
" SELECT * FROM "MEMORY_TABLE_NAME, NULL, NULL, &errmsg) != SQLITE_OK)
|
||||
if (sqlite3_exec(router->sqlite_handle, "INSERT INTO " USED_TABLES_TABLE_NAME
|
||||
" SELECT * FROM " MEMORY_TABLE_NAME, NULL, NULL, &errmsg) != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to transfer used table data from memory to disk: %s", errmsg);
|
||||
}
|
||||
sqlite3_free(errmsg);
|
||||
|
||||
if (sqlite3_exec(router->sqlite_handle, "DELETE FROM "MEMORY_TABLE_NAME,
|
||||
if (sqlite3_exec(router->sqlite_handle, "DELETE FROM " MEMORY_TABLE_NAME,
|
||||
NULL, NULL, &errmsg) != SQLITE_OK)
|
||||
{
|
||||
MXS_ERROR("Failed to transfer used table data from memory to disk: %s", errmsg);
|
@ -100,12 +100,12 @@ bool handle_table_map_event(AVRO_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr
|
||||
int ev_len = router->event_type_hdr_lens[hdr->event_type];
|
||||
|
||||
read_table_info(ptr, ev_len, &id, table_ident, sizeof(table_ident));
|
||||
TABLE_CREATE* create = hashtable_fetch(router->created_tables, table_ident);
|
||||
TABLE_CREATE* create = static_cast<TABLE_CREATE*>(hashtable_fetch(router->created_tables, table_ident));
|
||||
|
||||
if (create)
|
||||
{
|
||||
ss_dassert(create->columns > 0);
|
||||
TABLE_MAP *old = hashtable_fetch(router->table_maps, table_ident);
|
||||
TABLE_MAP *old = static_cast<TABLE_MAP*>(hashtable_fetch(router->table_maps, table_ident));
|
||||
TABLE_MAP *map = table_map_alloc(ptr, ev_len, create);
|
||||
MXS_ABORT_IF_NULL(map); // Fatal error at this point
|
||||
|
||||
@ -292,7 +292,7 @@ bool handle_row_event(AVRO_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr)
|
||||
{
|
||||
char table_ident[MYSQL_TABLE_MAXLEN + MYSQL_DATABASE_MAXLEN + 2];
|
||||
snprintf(table_ident, sizeof(table_ident), "%s.%s", map->database, map->table);
|
||||
AVRO_TABLE* table = hashtable_fetch(router->open_tables, table_ident);
|
||||
AVRO_TABLE* table = static_cast<AVRO_TABLE*>(hashtable_fetch(router->open_tables, table_ident));
|
||||
TABLE_CREATE* create = map->table_create;
|
||||
ss_dassert(hashtable_fetch(router->created_tables, table_ident) == create);
|
||||
|
@ -642,9 +642,9 @@ int count_columns(const char* ptr)
|
||||
static int process_column_definition(const char *nameptr, char*** dest, char*** dest_types, int** dest_lens)
|
||||
{
|
||||
int n = count_columns(nameptr);
|
||||
*dest = MXS_MALLOC(sizeof(char*) * n);
|
||||
*dest_types = MXS_MALLOC(sizeof(char*) * n);
|
||||
*dest_lens = MXS_MALLOC(sizeof(int) * n);
|
||||
*dest = static_cast<char**>(MXS_MALLOC(sizeof(char*) * n));
|
||||
*dest_types = static_cast<char**>(MXS_MALLOC(sizeof(char*) * n));
|
||||
*dest_lens = static_cast<int*>(MXS_MALLOC(sizeof(int) * n));
|
||||
|
||||
char **names = *dest;
|
||||
char **types = *dest_types;
|
||||
@ -727,7 +727,7 @@ int resolve_table_version(const char* db, const char* table)
|
||||
*
|
||||
* @return New CREATE_TABLE object or NULL if an error occurred
|
||||
*/
|
||||
TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len)
|
||||
TABLE_CREATE* table_create_alloc(char* ident, const char* sql, int len)
|
||||
{
|
||||
/** Extract the table definition so we can get the column names from it */
|
||||
int stmt_len = 0;
|
||||
@ -753,7 +753,7 @@ TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len)
|
||||
TABLE_CREATE *rval = NULL;
|
||||
if (n_columns > 0)
|
||||
{
|
||||
if ((rval = MXS_MALLOC(sizeof(TABLE_CREATE))))
|
||||
if ((rval = static_cast<TABLE_CREATE*>(MXS_MALLOC(sizeof(TABLE_CREATE)))))
|
||||
{
|
||||
rval->version = resolve_table_version(database, table);
|
||||
rval->was_used = false;
|
||||
@ -990,15 +990,15 @@ TABLE_CREATE* table_create_copy(AVRO_INSTANCE *router, const char* sql, size_t l
|
||||
|
||||
strcat(table_ident, source);
|
||||
|
||||
TABLE_CREATE *old = hashtable_fetch(router->created_tables, table_ident);
|
||||
TABLE_CREATE *old = static_cast<TABLE_CREATE*>(hashtable_fetch(router->created_tables, table_ident));
|
||||
|
||||
if (old)
|
||||
{
|
||||
int n = old->columns;
|
||||
char** names = MXS_MALLOC(sizeof(char*) * n);
|
||||
char** types = MXS_MALLOC(sizeof(char*) * n);
|
||||
int* lengths = MXS_MALLOC(sizeof(int) * n);
|
||||
rval = MXS_MALLOC(sizeof(TABLE_CREATE));
|
||||
char** names = static_cast<char**>(MXS_MALLOC(sizeof(char*) * n));
|
||||
char** types = static_cast<char**>(MXS_MALLOC(sizeof(char*) * n));
|
||||
int* lengths = static_cast<int*>(MXS_MALLOC(sizeof(int) * n));
|
||||
rval = static_cast<TABLE_CREATE*>(MXS_MALLOC(sizeof(TABLE_CREATE)));
|
||||
|
||||
MXS_ABORT_IF_FALSE(names && types && lengths && rval);
|
||||
|
||||
@ -1402,7 +1402,7 @@ int get_column_index(TABLE_CREATE *create, const char *tok, int len)
|
||||
|
||||
fix_reserved_word(safe_tok);
|
||||
|
||||
for (int x = 0; x < create->columns; x++)
|
||||
for (size_t x = 0; x < create->columns; x++)
|
||||
{
|
||||
if (strcasecmp(create->column_names[x], safe_tok) == 0)
|
||||
{
|
||||
@ -1496,9 +1496,15 @@ bool table_create_alter(TABLE_CREATE *create, const char *sql, const char *end)
|
||||
|
||||
if (is_new)
|
||||
{
|
||||
create->column_names = MXS_REALLOC(create->column_names, sizeof(char*) * (create->columns + 1));
|
||||
create->column_types = MXS_REALLOC(create->column_types, sizeof(char*) * (create->columns + 1));
|
||||
create->column_lengths = MXS_REALLOC(create->column_lengths, sizeof(int) * (create->columns + 1));
|
||||
create->column_names =
|
||||
static_cast<char**>(MXS_REALLOC(create->column_names,
|
||||
sizeof(char*) * (create->columns + 1)));
|
||||
create->column_types =
|
||||
static_cast<char**>(MXS_REALLOC(create->column_types,
|
||||
sizeof(char*) * (create->columns + 1)));
|
||||
create->column_lengths =
|
||||
static_cast<int*>(MXS_REALLOC(create->column_lengths,
|
||||
sizeof(int) * (create->columns + 1)));
|
||||
|
||||
char field_type[200] = ""; // Enough to hold all types
|
||||
int field_length = extract_type_length(tok + len, field_type);
|
||||
@ -1526,9 +1532,15 @@ bool table_create_alter(TABLE_CREATE *create, const char *sql, const char *end)
|
||||
create->column_lengths[i] = create->column_lengths[i + 1];
|
||||
}
|
||||
|
||||
create->column_names = MXS_REALLOC(create->column_names, sizeof(char*) * (create->columns - 1));
|
||||
create->column_types = MXS_REALLOC(create->column_types, sizeof(char*) * (create->columns - 1));
|
||||
create->column_lengths = MXS_REALLOC(create->column_lengths, sizeof(int) * (create->columns - 1));
|
||||
create->column_names =
|
||||
static_cast<char**>(MXS_REALLOC(create->column_names,
|
||||
sizeof(char*) * (create->columns - 1)));
|
||||
create->column_types =
|
||||
static_cast<char**>(MXS_REALLOC(create->column_types,
|
||||
sizeof(char*) * (create->columns - 1)));
|
||||
create->column_lengths =
|
||||
static_cast<int*>(MXS_REALLOC(create->column_lengths,
|
||||
sizeof(int) * (create->columns - 1)));
|
||||
create->columns--;
|
||||
updates++;
|
||||
}
|
||||
@ -1657,7 +1669,7 @@ TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create)
|
||||
uint8_t* metadata = (uint8_t*)mxs_lestr_consume(&ptr, &metadata_size);
|
||||
uint8_t *nullmap = ptr;
|
||||
size_t nullmap_size = (column_count + 7) / 8;
|
||||
TABLE_MAP *map = MXS_MALLOC(sizeof(TABLE_MAP));
|
||||
TABLE_MAP *map = static_cast<TABLE_MAP*>(MXS_MALLOC(sizeof(TABLE_MAP)));
|
||||
|
||||
if (map)
|
||||
{
|
||||
@ -1665,11 +1677,11 @@ TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create)
|
||||
map->version = create->version;
|
||||
map->flags = flags;
|
||||
map->columns = column_count;
|
||||
map->column_types = MXS_MALLOC(column_count);
|
||||
map->column_types = static_cast<uint8_t*>(MXS_MALLOC(column_count));
|
||||
/** Allocate at least one byte for the metadata */
|
||||
map->column_metadata = MXS_CALLOC(1, metadata_size + 1);
|
||||
map->column_metadata = static_cast<uint8_t*>(MXS_CALLOC(1, metadata_size + 1));
|
||||
map->column_metadata_size = metadata_size;
|
||||
map->null_bitmap = MXS_MALLOC(nullmap_size);
|
||||
map->null_bitmap = static_cast<uint8_t*>(MXS_MALLOC(nullmap_size));
|
||||
map->database = MXS_STRDUP(schema_name);
|
||||
map->table = MXS_STRDUP(table_name);
|
||||
map->table_create = create;
|
@ -73,8 +73,8 @@ MXS_BEGIN_DECLS
|
||||
#define AVRO_MAX_FILENAME_LEN 255
|
||||
#endif
|
||||
|
||||
static char *avro_client_states[] = { "Unregistered", "Registered", "Processing", "Errored" };
|
||||
static char *avro_client_client_mode[] = { "Catch-up", "Busy", "Wait_for_data" };
|
||||
static const char *avro_client_states[] = { "Unregistered", "Registered", "Processing", "Errored" };
|
||||
static const char *avro_client_client_mode[] = { "Catch-up", "Busy", "Wait_for_data" };
|
||||
|
||||
static const char *avro_domain = "domain";
|
||||
static const char *avro_server_id = "server_id";
|
||||
@ -82,7 +82,7 @@ static const char *avro_sequence = "sequence";
|
||||
static const char *avro_event_number = "event_number";
|
||||
static const char *avro_event_type = "event_type";
|
||||
static const char *avro_timestamp = "timestamp";
|
||||
static char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" };
|
||||
static const char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" };
|
||||
|
||||
static inline bool is_reserved_word(const char* word)
|
||||
{
|
||||
@ -310,7 +310,7 @@ extern void read_table_info(uint8_t *ptr, uint8_t post_header_len, uint64_t *tab
|
||||
char* dest, size_t len);
|
||||
extern TABLE_MAP *table_map_alloc(uint8_t *ptr, uint8_t hdr_len, TABLE_CREATE* create);
|
||||
extern void table_map_free(TABLE_MAP *map);
|
||||
extern TABLE_CREATE* table_create_alloc(const char* ident, const char* sql, int len);
|
||||
extern TABLE_CREATE* table_create_alloc(char* ident, const char* sql, int len);
|
||||
extern TABLE_CREATE* table_create_copy(AVRO_INSTANCE *router, const char* sql, size_t len, const char* db);
|
||||
extern void table_create_free(TABLE_CREATE* value);
|
||||
extern bool table_create_save(TABLE_CREATE *create, const char *filename);
|
||||
|
@ -1,3 +1,3 @@
|
||||
add_executable(test_alter_parsing test_alter_parsing.c)
|
||||
add_executable(test_alter_parsing test_alter_parsing.cc)
|
||||
target_link_libraries(test_alter_parsing maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro sqlite3 lzma)
|
||||
add_test(test_alter_parsing test_alter_parsing)
|
||||
add_test(test_alter_parsing test_alter_parsing)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "../avro_schema.c"
|
||||
#include "../avro_schema.cc"
|
||||
|
||||
static struct
|
||||
{
|
Reference in New Issue
Block a user