Merge branch '2.2' into develop

This commit is contained in:
Markus Mäkelä
2018-07-26 11:27:09 +03:00
29 changed files with 409 additions and 417 deletions

View File

@ -106,8 +106,10 @@ int Client::process(string url, string method, const char* upload_data, size_t *
if (m_data.length() &&
(json = json_loadb(m_data.c_str(), m_data.size(), 0, &err)) == NULL)
{
MHD_Response *response =
MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
string msg = string("{\"errors\": [ { \"detail\": \"Invalid JSON in request: ")
+ err.text + "\" } ] }";
MHD_Response *response = MHD_create_response_from_buffer(msg.size(), &msg[0],
MHD_RESPMEM_MUST_COPY);
MHD_queue_response(m_connection, MHD_HTTP_BAD_REQUEST, response);
MHD_destroy_response(response);
return MHD_YES;

View File

@ -761,15 +761,11 @@ gwbuf_get_property(GWBUF *buf, const char *name)
return prop ? prop->value : NULL;
}
GWBUF *
gwbuf_make_contiguous(GWBUF *orig)
GWBUF* gwbuf_make_contiguous(GWBUF *orig)
{
GWBUF *newbuf;
uint8_t *ptr;
int len;
if (orig == NULL)
{
ss_info_dassert(!true, "gwbuf_make_contiguous: NULL buffer");
return NULL;
}
if (orig->next == NULL)
@ -777,20 +773,21 @@ gwbuf_make_contiguous(GWBUF *orig)
return orig;
}
if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL)
{
newbuf->gwbuf_type = orig->gwbuf_type;
newbuf->hint = hint_dup(orig->hint);
ptr = GWBUF_DATA(newbuf);
GWBUF* newbuf = gwbuf_alloc(gwbuf_length(orig));
MXS_ABORT_IF_NULL(newbuf);
while (orig)
{
len = GWBUF_LENGTH(orig);
memcpy(ptr, GWBUF_DATA(orig), len);
ptr += len;
orig = gwbuf_consume(orig, len);
}
newbuf->gwbuf_type = orig->gwbuf_type;
newbuf->hint = hint_dup(orig->hint);
uint8_t* ptr = GWBUF_DATA(newbuf);
while (orig)
{
int len = GWBUF_LENGTH(orig);
memcpy(ptr, GWBUF_DATA(orig), len);
ptr += len;
orig = gwbuf_consume(orig, len);
}
return newbuf;
}
@ -888,7 +885,7 @@ static std::string dump_one_buffer(GWBUF* buffer)
return rval;
}
void gwbuf_hexdump(GWBUF* buffer)
void gwbuf_hexdump(GWBUF* buffer, int log_level)
{
std::stringstream ss;
@ -906,5 +903,5 @@ void gwbuf_hexdump(GWBUF* buffer)
n = 1024;
}
MXS_INFO("%.*s", n, ss.str().c_str());
MXS_LOG_MESSAGE(log_level, "%.*s", n, ss.str().c_str());
}

View File

@ -2953,45 +2953,23 @@ private:
bool dcb_foreach(bool(*func)(DCB *dcb, void *data), void *data)
{
ss_dassert(RoutingWorker::get_current() == RoutingWorker::get(RoutingWorker::MAIN));
SerialDcbTask task(func, data);
RoutingWorker::execute_serially(task);
return task.more();
}
/** Helper class for parallel iteration over all DCBs */
class ParallelDcbTask : public WorkerTask
void dcb_foreach_local(bool(*func)(DCB *dcb, void *data), void *data)
{
public:
int thread_id = RoutingWorker::get_current_id();
ParallelDcbTask(bool(*func)(DCB *, void *), void **data):
m_func(func),
m_data(data)
for (DCB *dcb = this_unit.all_dcbs[thread_id]; dcb; dcb = dcb->thread.next)
{
}
void execute(Worker& worker)
{
RoutingWorker& rworker = static_cast<RoutingWorker&>(worker);
int thread_id = rworker.id();
for (DCB *dcb = this_unit.all_dcbs[thread_id]; dcb; dcb = dcb->thread.next)
if (!func(dcb, data))
{
if (!m_func(dcb, m_data[thread_id]))
{
break;
}
break;
}
}
private:
bool(*m_func)(DCB *dcb, void *data);
void** m_data;
};
void dcb_foreach_parallel(bool(*func)(DCB *dcb, void *data), void **data)
{
ParallelDcbTask task(func, data);
RoutingWorker::execute_concurrently(task);
}
int dcb_get_port(const DCB *dcb)

View File

@ -488,6 +488,17 @@ int modutil_send_mysql_err_packet(DCB *dcb,
return dcb->func.write(dcb, buf);
}
// Helper function for debug assertions
static bool only_one_packet(GWBUF* buffer)
{
ss_dassert(buffer);
uint8_t header[4] = {};
gwbuf_copy_data(buffer, 0, MYSQL_HEADER_LEN, header);
size_t packet_len = gw_mysql_get_byte3(header);
size_t buffer_len = gwbuf_length(buffer);
return packet_len + MYSQL_HEADER_LEN == buffer_len;
}
/**
* Return the first packet from a buffer.
*
@ -534,6 +545,7 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf)
}
}
ss_dassert(!packet || only_one_packet(packet));
return packet;
}

View File

@ -182,6 +182,16 @@ bool foreach_table(QueryClassifier& qc,
}
}
if (tables)
{
for (int i = 0; i < n_tables; i++)
{
MXS_FREE(tables[i]);
}
MXS_FREE(tables);
}
return rval;
}