mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-25 18:06:29 +00:00
Query parser 3.0 (#23)
* Starting query parsing * Query parser * working config * disable by default * fix tsets * introducing log crate; test for query router; comments * typo * fixes for banning * added test for prepared stmt
This commit is contained in:
@@ -10,7 +10,6 @@ use tokio::net::{
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::config::Role;
|
||||
use crate::constants::*;
|
||||
use crate::errors::Error;
|
||||
use crate::messages::*;
|
||||
@@ -47,10 +46,6 @@ pub struct Client {
|
||||
// to connect and cancel a query.
|
||||
client_server_map: ClientServerMap,
|
||||
|
||||
// Unless client specifies, route queries to the servers that have this role,
|
||||
// e.g. primary or replicas or any.
|
||||
default_server_role: Option<Role>,
|
||||
|
||||
// Client parameters, e.g. user, client_encoding, etc.
|
||||
#[allow(dead_code)]
|
||||
parameters: HashMap<String, String>,
|
||||
@@ -67,7 +62,6 @@ impl Client {
|
||||
mut stream: TcpStream,
|
||||
client_server_map: ClientServerMap,
|
||||
transaction_mode: bool,
|
||||
default_server_role: Option<Role>,
|
||||
server_info: BytesMut,
|
||||
stats: Reporter,
|
||||
) -> Result<Client, Error> {
|
||||
@@ -126,7 +120,6 @@ impl Client {
|
||||
process_id: process_id,
|
||||
secret_key: secret_key,
|
||||
client_server_map: client_server_map,
|
||||
default_server_role: default_server_role,
|
||||
parameters: parameters,
|
||||
stats: stats,
|
||||
});
|
||||
@@ -148,7 +141,6 @@ impl Client {
|
||||
process_id: process_id,
|
||||
secret_key: secret_key,
|
||||
client_server_map: client_server_map,
|
||||
default_server_role: default_server_role,
|
||||
parameters: HashMap::new(),
|
||||
stats: stats,
|
||||
});
|
||||
@@ -162,7 +154,11 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Client loop. We handle all messages between the client and the database here.
|
||||
pub async fn handle(&mut self, mut pool: ConnectionPool) -> Result<(), Error> {
|
||||
pub async fn handle(
|
||||
&mut self,
|
||||
mut pool: ConnectionPool,
|
||||
mut query_router: QueryRouter,
|
||||
) -> Result<(), Error> {
|
||||
// The client wants to cancel a query it has issued previously.
|
||||
if self.cancel_mode {
|
||||
let (process_id, secret_key, address, port) = {
|
||||
@@ -191,8 +187,6 @@ impl Client {
|
||||
return Ok(Server::cancel(&address, &port, process_id, secret_key).await?);
|
||||
}
|
||||
|
||||
let mut query_router = QueryRouter::new(self.default_server_role, pool.shards());
|
||||
|
||||
// Our custom protocol loop.
|
||||
// We expect the client to either start a transaction with regular queries
|
||||
// or issue commands for our sharding and server selection protocols.
|
||||
@@ -222,6 +216,11 @@ impl Client {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Attempt to parse the query to determine where it should go
|
||||
if query_router.query_parser_enabled() && query_router.role() == None {
|
||||
query_router.infer_role(message.clone());
|
||||
}
|
||||
|
||||
// Grab a server from the pool: the client issued a regular query.
|
||||
let connection = match pool.get(query_router.shard(), query_router.role()).await {
|
||||
Ok(conn) => conn,
|
||||
|
||||
Reference in New Issue
Block a user