Add sys actions

next
Sayan Nandan 3 years ago
parent 0283d91f67
commit 832da79e9d
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -37,9 +37,9 @@ pub type TResult<T> = Result<T, Box<dyn Error>>;
/// The size of the read buffer in bytes
pub const BUF_CAP: usize = 8 * 1024; // 8 KB per-connection
/// The current version
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// The URL
pub static URL: &str = "https://github.com/skytable/skytable";
pub const URL: &str = "https://github.com/skytable/skytable";
#[macro_export]
/// Don't use unwrap_or but use this macro as the optimizer fails to optimize away usages

@ -27,3 +27,4 @@
//! Modules for administration of Skytable
pub mod mksnap;
pub mod sys;

@ -0,0 +1,71 @@
/*
* Created on Tue Mar 29 2022
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2022, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::corestore::booltable::BoolTable;
use crate::dbnet::connection::prelude::*;
use crate::protocol::{PROTOCOL_VERSION, PROTOCOL_VERSIONSTRING};
use ::libsky::VERSION;
const INFO: &[u8] = b"info";
const METRIC: &[u8] = b"metric";
const INFO_PROTOCOL: &[u8] = b"protocol";
const INFO_PROTOVER: &[u8] = b"protover";
const INFO_VERSION: &[u8] = b"version";
const METRIC_HEALTH: &[u8] = b"health";
const ERR_UNKNOWN_PROPERTY: &[u8] = b"!16\nunknown-property\n";
const ERR_UNKNOWN_METRIC: &[u8] = b"!14\nunknown-metric\n";
const HEALTH_TABLE: BoolTable<&str> = BoolTable::new("good", "critical");
action! {
fn sys(_handle: &Corestore, con: &mut T, iter: ActionIter<'_>) {
let mut iter = iter;
ensure_boolean_or_aerr(iter.len() == 2)?;
match unsafe { iter.next_lowercase_unchecked() }.as_ref() {
INFO => sys_info(con, &mut iter).await,
METRIC => sys_metric(con, &mut iter).await,
_ => util::err(groups::UNKNOWN_ACTION),
}
}
fn sys_info(con: &mut T, iter: &mut ActionIter<'_>) {
match unsafe { iter.next_lowercase_unchecked() }.as_ref() {
INFO_PROTOCOL => con.write_response(PROTOCOL_VERSIONSTRING).await?,
INFO_PROTOVER => con.write_response(PROTOCOL_VERSION).await?,
INFO_VERSION => con.write_response(VERSION).await?,
_ => return util::err(ERR_UNKNOWN_PROPERTY),
}
Ok(())
}
fn sys_metric(con: &mut T, iter: &mut ActionIter<'_>) {
match unsafe { iter.next_lowercase_unchecked() }.as_ref() {
METRIC_HEALTH => {
con.write_response(HEALTH_TABLE[registry::state_okay()]).await?
}
_ => return util::err(ERR_UNKNOWN_METRIC),
}
Ok(())
}
}

@ -62,7 +62,7 @@ mod storage;
#[cfg(test)]
mod tests;
const PATH: &str = ".sky_pid";
const PID_FILE_PATH: &str = ".sky_pid";
#[cfg(test)]
const ROOT_DIR: &str = env!("ROOT_DIR");
@ -157,7 +157,7 @@ fn check_args_and_get_cfg() -> (ConfigurationSet, Option<String>) {
/// to the same directory which can cause potentially undefined behavior.
///
fn run_pre_startup_tasks() -> FileLock {
let mut file = match FileLock::lock(PATH) {
let mut file = match FileLock::lock(PID_FILE_PATH) {
Ok(fle) => fle,
Err(e) => {
log::error!("Startup failure: Failed to lock pid file: {}", e);

@ -91,6 +91,9 @@ impl<'a> AnyArrayIter<'a> {
v.as_slice().to_ascii_lowercase().into_boxed_slice()
})
}
pub unsafe fn next_lowercase_unchecked(&mut self) -> Box<[u8]> {
self.next_lowercase().unwrap_or_else(|| impossible!())
}
pub unsafe fn next_uppercase_unchecked(&mut self) -> Box<[u8]> {
match self.next_uppercase() {
Some(s) => s,

@ -57,6 +57,11 @@ use core::hint::unreachable_unchecked;
use core::ops;
use core::slice;
/// The Skyhash protocol version
pub const PROTOCOL_VERSION: f32 = 1.2;
/// The Skyhash protocol version string (Skyhash-x.y)
pub const PROTOCOL_VERSIONSTRING: &[u8] = b"Skyhash-1.1";
const ASCII_UNDERSCORE: u8 = b'_';
const ASCII_AMPERSAND: u8 = b'&';
const ASCII_COLON: u8 = b':';

@ -174,6 +174,7 @@ async fn execute_stage<'a, T: 'a + ClientConnection<Strm>, Strm: Stream>(
LGET => actions::lists::lget::lget,
LMOD => actions::lists::lmod::lmod,
WHEREAMI => actions::whereami::whereami,
SYS => admin::sys::sys,
{
// actions that need other arguments
AUTH => auth::auth(con, auth, iter)

@ -38,6 +38,7 @@ use tokio::io::AsyncWriteExt;
pub mod writer;
pub const TSYMBOL_UNICODE_STRING: u8 = b'+';
pub const TSYMBOL_FLOAT: u8 = b'%';
type FutureIoResult<'s> = FutureResult<'s, Result<(), IoError>>;
@ -225,3 +226,18 @@ impl Writable for ObjectID {
})
}
}
impl Writable for f32 {
fn write<'s>(self, con: &'s mut impl IsConnection) -> FutureIoResult<'s> {
Box::pin(async move {
let payload = self.to_string();
let payload_len = Integer64::from(payload.len());
con.write_lowlevel(&[TSYMBOL_FLOAT]).await?;
con.write_lowlevel(&payload_len).await?;
con.write_lowlevel(&[b'\n']).await?;
con.write_lowlevel(payload.as_bytes()).await?;
con.write_lowlevel(&[b'\n']).await?;
Ok(())
})
}
}

Loading…
Cancel
Save