Skip to content
Snippets Groups Projects
Verified Commit ce184461 authored by Denis Smirnov's avatar Denis Smirnov
Browse files

feat: add statistics initialization to the API

Though we can lazily initialize statistics spaces, there is still a
problem with read-only replicas. If the workload does not write to
the storage (only reads with SELECTs), then callbre is used and no
queries will be dispatched to the storage master. As a result, no
statistics spaces will be initialized on the storage failover group.

To deal with it, we add a new API method to initialize statistics
on the instance startup.
parent cb565bff
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -9,3 +9,4 @@ pub mod calculate_bucket_id;
pub mod exec_query;
mod helper;
pub mod invalidate_cached_schema;
pub mod statistics;
use sbroad::debug;
use sbroad::otm::statistics::table::{QUERY, SPAN, STAT};
use std::os::raw::c_int;
/// Initialize query statistics tables.
///
/// Though the function always returns a success, it can fail to create
/// the table (for example on read-only replica). In this case, the
/// warning will be logged, but the function will return success.
#[allow(clippy::module_name_repetitions)]
#[no_mangle]
pub extern "C" fn init_statistics() -> c_int {
debug!(
Option::from("init_statistics"),
"Initializing statistics tables"
);
QUERY.with(|_| {});
SPAN.with(|_| {});
STAT.with(|_| {});
0
}
......@@ -217,6 +217,13 @@ local function init()
'libsbroad.dispatch_query',
{ if_not_exists = true, language = 'C' }
)
box.schema.func.create(
'libsbroad.init_statistics',
{ if_not_exists = true, language = 'C' }
)
box.func["libsbroad.init_statistics"]:call({})
end
local function calculate_bucket_id(values, space_name) -- luacheck: no unused args
......
......@@ -87,6 +87,13 @@ local function init()
'libsbroad.invalidate_segment_cache',
{ if_not_exists = true, language = 'C' }
)
box.schema.func.create(
'libsbroad.init_statistics',
{ if_not_exists = true, language = 'C' }
)
box.func["libsbroad.init_statistics"]:call({})
end
local function invalidate_cache()
......
......@@ -33,9 +33,9 @@ use tarantool::{index, space};
use crate::{debug, warn};
thread_local!(pub(super) static QUERY: RefCell<QuerySpace> = RefCell::new(QuerySpace::new()));
thread_local!(pub(super) static SPAN: RefCell<SpanMap> = RefCell::new(SpanMap::new()));
thread_local!(pub(super) static STAT: RefCell<StatSpace> = RefCell::new(StatSpace::new()));
thread_local!(pub static QUERY: RefCell<QuerySpace> = RefCell::new(QuerySpace::new()));
thread_local!(pub static SPAN: RefCell<SpanMap> = RefCell::new(SpanMap::new()));
thread_local!(pub static STAT: RefCell<StatSpace> = RefCell::new(StatSpace::new()));
pub trait RustMap {
type Key;
......
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