Change session id to 64bit
The server internal session id may be larger than 4 bytes (MariaDB uses 8) but only 4 are sent in the handshake. The full value can be queried from the server, but this query is not supported by MaxScale yet. In any case, both the protocol and MXS_SESSION now have 64 bit counters. Only the low 32 bits are sent in the handshake, similar to server.
This commit is contained in:
parent
9c12e78cce
commit
aebe839990
@ -313,7 +313,7 @@ int dcb_isvalid(DCB *); /* Check the DCB is in the linked li
|
||||
int dcb_count_by_usage(DCB_USAGE); /* Return counts of DCBs */
|
||||
int dcb_persistent_clean_count(DCB *, int, bool); /* Clean persistent and return count */
|
||||
void dcb_hangup_foreach (struct server* server);
|
||||
uint32_t dcb_get_session_id(DCB* dcb);
|
||||
uint64_t dcb_get_session_id(DCB* dcb);
|
||||
char *dcb_role_name(DCB *); /* Return the name of a role */
|
||||
int dcb_accept_SSL(DCB* dcb);
|
||||
int dcb_connect_SSL(DCB* dcb);
|
||||
|
@ -320,7 +320,7 @@ typedef struct
|
||||
uint32_t server_capabilities; /*< server capabilities, created or received */
|
||||
uint32_t client_capabilities; /*< client capabilities, created or received */
|
||||
uint32_t extra_capabilities; /*< MariaDB 10.2 capabilities */
|
||||
uint32_t tid; /*< MySQL Thread ID, in handshake */
|
||||
uint64_t thread_id; /*< MySQL Thread ID. Send only 32bits in handshake. */
|
||||
unsigned int charset; /*< MySQL character set at connect time */
|
||||
int ignore_replies; /*< How many replies should be discarded */
|
||||
GWBUF* stored_query; /*< Temporarily stored queries */
|
||||
|
@ -134,7 +134,7 @@ typedef struct session
|
||||
{
|
||||
skygw_chk_t ses_chk_top;
|
||||
mxs_session_state_t state; /*< Current descriptor state */
|
||||
uint32_t ses_id; /*< Unique session identifier */
|
||||
uint64_t ses_id; /*< Unique session identifier */
|
||||
struct dcb *client_dcb; /*< The client connection */
|
||||
struct mxs_router_session *router_session; /*< The router instance data */
|
||||
MXS_SESSION_STATS stats; /*< Session statistics */
|
||||
@ -194,7 +194,7 @@ MXS_SESSION *session_alloc(struct service *, struct dcb *);
|
||||
* @param id Id for the new session.
|
||||
* @return The newly created session or NULL if an error occurred
|
||||
*/
|
||||
MXS_SESSION *session_alloc_with_id(struct service *, struct dcb *, uint32_t);
|
||||
MXS_SESSION *session_alloc_with_id(struct service *, struct dcb *, uint64_t);
|
||||
|
||||
MXS_SESSION *session_set_dummy(struct dcb *);
|
||||
|
||||
@ -352,14 +352,14 @@ static inline bool session_set_autocommit(MXS_SESSION* ses, bool autocommit)
|
||||
*
|
||||
* @note The caller must free the session reference by calling session_put_ref
|
||||
*/
|
||||
MXS_SESSION* session_get_by_id(uint32_t id);
|
||||
MXS_SESSION* session_get_by_id(uint64_t id);
|
||||
|
||||
/**
|
||||
* Get the next available unique (assuming no overflow) session id number.
|
||||
*
|
||||
* @return An unused session id.
|
||||
*/
|
||||
uint32_t session_get_next_id();
|
||||
uint64_t session_get_next_id();
|
||||
|
||||
/**
|
||||
* @brief Close a session
|
||||
|
@ -163,7 +163,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, int thread_id, uint32_t ev);
|
||||
static void dcb_process_fake_events(DCB *dcb, int thread_id);
|
||||
static bool dcb_session_check(DCB *dcb, const char *);
|
||||
|
||||
uint32_t dcb_get_session_id(DCB *dcb)
|
||||
uint64_t dcb_get_session_id(DCB *dcb)
|
||||
{
|
||||
return (dcb && dcb->session) ? dcb->session->ses_id : 0;
|
||||
}
|
||||
@ -1673,7 +1673,7 @@ dprintDCB(DCB *pdcb, DCB *dcb)
|
||||
|
||||
if (dcb->session && dcb->session->state != SESSION_STATE_DUMMY)
|
||||
{
|
||||
dcb_printf(pdcb, "\tOwning Session: %" PRIu32 "\n", dcb->session->ses_id);
|
||||
dcb_printf(pdcb, "\tOwning Session: %" PRIu64 "\n", dcb->session->ses_id);
|
||||
}
|
||||
|
||||
if (dcb->writeq)
|
||||
|
@ -61,7 +61,7 @@ using std::stringstream;
|
||||
/** Global session id counter. Must be updated atomically. Value 0 is reserved for
|
||||
* dummy/unused sessions.
|
||||
*/
|
||||
static uint32_t next_session_id = 1;
|
||||
static uint64_t next_session_id = 1;
|
||||
|
||||
static struct session session_dummy_struct;
|
||||
|
||||
@ -162,7 +162,7 @@ MXS_SESSION* session_alloc(SERVICE *service, DCB *client_dcb)
|
||||
return session_alloc_body(service, client_dcb, session);
|
||||
}
|
||||
|
||||
MXS_SESSION* session_alloc_with_id(SERVICE *service, DCB *client_dcb, uint32_t id)
|
||||
MXS_SESSION* session_alloc_with_id(SERVICE *service, DCB *client_dcb, uint64_t id)
|
||||
{
|
||||
MXS_SESSION *session = (MXS_SESSION *)(MXS_MALLOC(sizeof(*session)));
|
||||
if (session == NULL)
|
||||
@ -263,13 +263,13 @@ static MXS_SESSION* session_alloc_body(SERVICE* service, DCB* client_dcb,
|
||||
|
||||
if (session->client_dcb->user == NULL)
|
||||
{
|
||||
MXS_INFO("Started session [%" PRIu32 "] for %s service ",
|
||||
MXS_INFO("Started session [%" PRIu64 "] for %s service ",
|
||||
session->ses_id,
|
||||
service->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_INFO("Started %s client session [%" PRIu32 "] for '%s' from %s",
|
||||
MXS_INFO("Started %s client session [%" PRIu64 "] for '%s' from %s",
|
||||
service->name,
|
||||
session->ses_id,
|
||||
session->client_dcb->user,
|
||||
@ -278,7 +278,7 @@ static MXS_SESSION* session_alloc_body(SERVICE* service, DCB* client_dcb,
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_INFO("Start %s client session [%" PRIu32 "] for '%s' from %s failed, will be "
|
||||
MXS_INFO("Start %s client session [%" PRIu64 "] for '%s' from %s failed, will be "
|
||||
"closed as soon as all related DCBs have been closed.",
|
||||
service->name,
|
||||
session->ses_id,
|
||||
@ -448,7 +448,7 @@ static void session_free(MXS_SESSION *session)
|
||||
MXS_FREE(session->filters);
|
||||
}
|
||||
|
||||
MXS_INFO("Stopped %s client session [%" PRIu32 "]", session->service->name, session->ses_id);
|
||||
MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id);
|
||||
|
||||
/** If session doesn't have parent referencing to it, it can be freed */
|
||||
if (!session->ses_is_child)
|
||||
@ -560,7 +560,7 @@ dprintSession(DCB *dcb, MXS_SESSION *print_session)
|
||||
char buf[30];
|
||||
int i;
|
||||
|
||||
dcb_printf(dcb, "Session %" PRIu32 "\n", print_session->ses_id);
|
||||
dcb_printf(dcb, "Session %" PRIu64 "\n", print_session->ses_id);
|
||||
dcb_printf(dcb, "\tState: %s\n", session_state(print_session->state));
|
||||
dcb_printf(dcb, "\tService: %s\n", print_session->service->name);
|
||||
|
||||
@ -600,7 +600,7 @@ bool dListSessions_cb(DCB *dcb, void *data)
|
||||
{
|
||||
DCB *out_dcb = (DCB*)data;
|
||||
MXS_SESSION *session = dcb->session;
|
||||
dcb_printf(out_dcb, "%-16" PRIu32 " | %-15s | %-14s | %s\n", session->ses_id,
|
||||
dcb_printf(out_dcb, "%-16" PRIu64 " | %-15s | %-14s | %s\n", session->ses_id,
|
||||
session->client_dcb && session->client_dcb->remote ?
|
||||
session->client_dcb->remote : "",
|
||||
session->service && session->service->name ?
|
||||
@ -964,7 +964,7 @@ static bool ses_find_id(DCB *dcb, void *data)
|
||||
{
|
||||
void **params = (void**)data;
|
||||
MXS_SESSION **ses = (MXS_SESSION**)params[0];
|
||||
uint32_t *id = (uint32_t*)params[1];
|
||||
uint64_t *id = (uint64_t*)params[1];
|
||||
bool rval = true;
|
||||
|
||||
if (dcb->session->ses_id == *id)
|
||||
@ -976,7 +976,7 @@ static bool ses_find_id(DCB *dcb, void *data)
|
||||
return rval;
|
||||
}
|
||||
|
||||
MXS_SESSION* session_get_by_id(uint32_t id)
|
||||
MXS_SESSION* session_get_by_id(uint64_t id)
|
||||
{
|
||||
MXS_SESSION *session = NULL;
|
||||
void *params[] = {&session, &id};
|
||||
@ -1048,9 +1048,9 @@ void session_clear_stmt(MXS_SESSION *session)
|
||||
session->stmt.target = NULL;
|
||||
}
|
||||
|
||||
uint32_t session_get_next_id()
|
||||
uint64_t session_get_next_id()
|
||||
{
|
||||
return atomic_add_uint32(&next_session_id, 1);
|
||||
return atomic_add_uint64(&next_session_id, 1);
|
||||
}
|
||||
|
||||
void session_broadcast_kill_command(MXS_SESSION* issuer, uint64_t target_id)
|
||||
|
@ -241,9 +241,10 @@ int MySQLSendHandshake(DCB* dcb)
|
||||
memcpy(mysql_filler_ten + 6, &new_flags, sizeof(new_flags));
|
||||
}
|
||||
|
||||
// Get the equivalent of the server process id.
|
||||
protocol->tid = session_get_next_id();
|
||||
gw_mysql_set_byte4(mysql_thread_id_num, protocol->tid);
|
||||
// Get the equivalent of the server thread id.
|
||||
protocol->thread_id = session_get_next_id();
|
||||
// Send only the low 32bits in the handshake.
|
||||
gw_mysql_set_byte4(mysql_thread_id_num, (uint32_t)(protocol->thread_id));
|
||||
memcpy(mysql_scramble_buf, server_scramble, 8);
|
||||
|
||||
memcpy(mysql_plugin_data, server_scramble + 8, 12);
|
||||
@ -668,7 +669,7 @@ gw_read_do_authentication(DCB *dcb, GWBUF *read_buffer, int nbytes_read)
|
||||
* normal data handling function instead of this one.
|
||||
*/
|
||||
MXS_SESSION *session =
|
||||
session_alloc_with_id(dcb->service, dcb, protocol->tid);
|
||||
session_alloc_with_id(dcb->service, dcb, protocol->thread_id);
|
||||
|
||||
if (session != NULL)
|
||||
{
|
||||
|
@ -1410,7 +1410,6 @@ gw_decode_mysql_server_handshake(MySQLProtocol *conn, uint8_t *payload)
|
||||
uint8_t *server_version_end = NULL;
|
||||
uint16_t mysql_server_capabilities_one = 0;
|
||||
uint16_t mysql_server_capabilities_two = 0;
|
||||
unsigned long tid = 0;
|
||||
uint8_t scramble_data_1[GW_SCRAMBLE_LENGTH_323] = "";
|
||||
uint8_t scramble_data_2[GW_MYSQL_SCRAMBLE_SIZE - GW_SCRAMBLE_LENGTH_323] = "";
|
||||
uint8_t capab_ptr[4] = "";
|
||||
@ -1433,8 +1432,10 @@ gw_decode_mysql_server_handshake(MySQLProtocol *conn, uint8_t *payload)
|
||||
payload = server_version_end + 1;
|
||||
|
||||
// get ThreadID: 4 bytes
|
||||
tid = gw_mysql_get_byte4(payload);
|
||||
memcpy(&conn->tid, &tid, 4);
|
||||
uint32_t tid = gw_mysql_get_byte4(payload);
|
||||
/* TODO: Correct value of thread id could be queried later from backend if
|
||||
* there is any worry it might be larger than 32bit allows. */
|
||||
conn->thread_id = tid;
|
||||
|
||||
payload += 4;
|
||||
|
||||
|
@ -363,7 +363,7 @@ int32_t SchemaRouterSession::routeQuery(GWBUF* pPacket)
|
||||
if (m_config->debug)
|
||||
{
|
||||
sprintf(errbuf + strlen(errbuf),
|
||||
" ([%" PRIu32 "]: DB change failed)",
|
||||
" ([%" PRIu64 "]: DB change failed)",
|
||||
m_client->session->ses_id);
|
||||
}
|
||||
|
||||
@ -991,7 +991,7 @@ bool SchemaRouterSession::handle_default_db()
|
||||
sprintf(errmsg, "Unknown database '%s'", m_connect_db.c_str());
|
||||
if (m_config->debug)
|
||||
{
|
||||
sprintf(errmsg + strlen(errmsg), " ([%" PRIu32 "]: DB not found on connect)",
|
||||
sprintf(errmsg + strlen(errmsg), " ([%" PRIu64 "]: DB not found on connect)",
|
||||
m_client->session->ses_id);
|
||||
}
|
||||
write_error_to_client(m_client,
|
||||
|
Loading…
x
Reference in New Issue
Block a user