Skip to content
Snippets Groups Projects
Commit 229c5afc authored by Dmitry Ivanov's avatar Dmitry Ivanov Committed by Dmitry Ivanov
Browse files

pgproto: eager init of portal & statement storages

parent 6c037819
No related branches found
No related tags found
1 merge request!1154pgproto: refactor statement and portal storage
Pipeline #46084 passed
......@@ -41,6 +41,9 @@ impl Config {
}
fn server_start(context: Context) {
// Help DBA diagnose storages by initializing them asap.
backend::storage::force_init_portals_and_statements();
while let Ok(raw) = context.server.accept() {
let stream = PgStream::new(raw);
if let Err(e) = handle_client(stream, context.tls_acceptor.clone()) {
......
use super::describe::{Describe, PortalDescribe, StatementDescribe};
use super::describe::{MetadataColumn, QueryType};
use super::result::{ExecuteResult, Rows};
use crate::pgproto::error::{PgError, PgErrorCode, PgResult};
use crate::pgproto::value::{FieldFormat, PgValue};
use crate::storage::PropertyName;
use crate::traft::node;
use ::tarantool::tuple::Tuple;
use super::{
describe::{Describe, MetadataColumn, PortalDescribe, QueryType, StatementDescribe},
result::{ExecuteResult, Rows},
};
use crate::{
pgproto::{
error::{PgError, PgErrorCode, PgResult},
value::{FieldFormat, PgValue},
},
storage::PropertyName,
tlog,
traft::node,
};
use rmpv::Value;
use sbroad::executor::ir::ExecutionPlan;
use sbroad::executor::Query;
use sbroad::ir::Plan;
use sbroad::{
executor::{ir::ExecutionPlan, Query},
ir::Plan,
};
use serde::{Deserialize, Serialize};
use std::cell::{Cell, RefCell};
use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, HashMap};
use std::iter::zip;
use std::ops::Bound::{Excluded, Included};
use std::os::raw::c_int;
use std::rc::{Rc, Weak};
use std::vec::IntoIter;
use tarantool::proc::{Return, ReturnMsgpack};
use tarantool::tuple::FunctionCtx;
use std::{
cell::{Cell, RefCell},
collections::{btree_map::Entry, BTreeMap, HashMap},
iter::zip,
ops::Bound,
os::raw::c_int,
rc::{Rc, Weak},
vec::IntoIter,
};
use tarantool::{
proc::{Return, ReturnMsgpack},
tuple::{FunctionCtx, Tuple},
};
use crate::sql::dispatch;
use crate::sql::router::RouterRuntime;
......@@ -134,8 +143,8 @@ impl<S> PgStorage<S> {
pub fn names_by_client_id(&self, id: ClientId) -> Vec<Rc<str>> {
let range = (
Included((id, Rc::clone(&self.empty_name))),
Excluded((id + 1, Rc::clone(&self.empty_name))),
Bound::Included((id, Rc::clone(&self.empty_name))),
Bound::Excluded((id + 1, Rc::clone(&self.empty_name))),
);
self.map
.range(range)
......@@ -160,7 +169,10 @@ type StatementStorage = PgStorage<StatementHolder>;
impl StatementStorage {
fn new() -> Self {
PgStorage::with_context(StorageContext::statements())
let context = StorageContext::statements();
let capacity = context.get_capacity().expect("storage capacity");
tlog!(Info, "creating statement storage with capacity {capacity}");
PgStorage::with_context(context)
}
pub fn get(&self, key: &(ClientId, Rc<str>)) -> Option<Statement> {
......@@ -168,17 +180,14 @@ impl StatementStorage {
}
}
impl Default for StatementStorage {
fn default() -> Self {
Self::new()
}
}
type PortalStorage = PgStorage<Portal>;
impl PortalStorage {
pub fn new() -> Self {
PgStorage::with_context(StorageContext::portals())
let context = StorageContext::portals();
let capacity = context.get_capacity().expect("storage capacity");
tlog!(Info, "creating portal storage with capacity {capacity}");
PgStorage::with_context(context)
}
pub fn remove_portals_by_statement(&mut self, statement: &Statement) {
......@@ -187,17 +196,18 @@ impl PortalStorage {
}
}
impl Default for PortalStorage {
fn default() -> Self {
Self::new()
}
}
// TODO: those shoudn't be global variables; move them to some context (backend?).
thread_local! {
pub static PG_STATEMENTS: Rc<RefCell<StatementStorage>> = Rc::new(RefCell::new(StatementStorage::new()));
pub static PG_PORTALS: Rc<RefCell<PortalStorage>> = Rc::new(RefCell::new(PortalStorage::new()));
}
/// Eagerly initialize storages for prepared statements and portals.
pub fn force_init_portals_and_statements() {
PG_STATEMENTS.with(|_| {});
PG_PORTALS.with(|_| {});
}
pub fn with_portals_mut<T, F>(key: (ClientId, Rc<str>), f: F) -> PgResult<T>
where
F: FnOnce(&mut Portal) -> PgResult<T>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment