Files
MaxScale/include/maxscale/protocol/mariadb_client.hh
Johan Wikman 8ea7d8898a MXS-1915 Remove id from mxs::Worker
The id has now been moved from mxs::Worker to mxs::RoutingWorker
and the implications are felt in many places.

The primary need for the id was to be able to access worker specfic
data, maintained outside of a routing worker, when given a worker
(the id is used to index into an array). Slightly related to that
was the need to be able to iterate over all workers. That obviously
implies some kind of collection.

That causes all sorts of issues if there is a need for being able
to create and destroy a worker at runtime. With the id removed from
mxs::Worker all those issues are gone, and its perfectly ok to create
and destory mxs::Workers as needed.

Further, while there is a need to broadcast a particular message to
all _routing_ workers, it hardly makes sense to broadcast a particular
message too _all_ workers. Consequently, only routing workers are kept
in a collection and all static member functions dealing with all
workers (e.g. broadcast) have now been moved to mxs::RoutingWorker.

Now, instead of passing the id around we instead deal directly
with the worker pointer. Later the data in all those external arrays
will be moved into mxs::[Worker|RoutingWorker] so that worker related
data is maintained in exactly one place.
2018-06-26 09:19:46 +03:00

87 lines
2.4 KiB
C++

#pragma once
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2022-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include <maxscale/cppdefs.hh>
#include <deque>
#include <maxscale/buffer.hh>
#include <maxscale/service.h>
#include <maxscale/protocol/mysql.h>
/** A DCB-like client abstraction which ignores responses */
class LocalClient: public MXS_POLL_DATA
{
LocalClient(const LocalClient&);
LocalClient& operator=(const LocalClient&);
public:
~LocalClient();
/**
* Create a local client for a service
*
* @param session Client session
* @param service Service to connect to
*
* @return New virtual client or NULL on error
*/
static LocalClient* create(MXS_SESSION* session, SERVICE* service);
static LocalClient* create(MXS_SESSION* session, SERVER* server);
/**
* Queue a new query for execution
*
* @param buffer Buffer containing the query
*
* @return True if query was successfully queued
*/
bool queue_query(GWBUF* buffer);
/**
* Destroy the client by sending a COM_QUIT to the backend
*
* @note After calling this function, object must be treated as a deleted object
*/
void self_destruct();
private:
static LocalClient* create(MXS_SESSION* session, const char* ip, uint64_t port);
LocalClient(MXS_SESSION* session, int fd);
static uint32_t poll_handler(struct mxs_poll_data* data, void* worker, uint32_t events);
void process(uint32_t events);
GWBUF* read_complete_packet();
void drain_queue();
void error();
void close();
/** Client states */
enum vc_state
{
VC_WAITING_HANDSHAKE, // Initial state
VC_RESPONSE_SENT, // Handshake received and response sent
VC_OK, // Authentication is complete, ready for queries
VC_ERROR // Something went wrong
};
vc_state m_state;
int m_sock;
mxs::Buffer m_partial;
size_t m_expected_bytes;
std::deque<mxs::Buffer> m_queue;
MYSQL_session m_client;
MySQLProtocol m_protocol;
bool m_self_destruct;
};