#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![cfg_attr(doc, feature(doc_cfg))]
#[cfg(all(feature = "cast_ints", feature = "cast_ints_unchecked"))]
compile_error!("features `cast_ints` and `cast_ints_unchecked` are mutually exclusive!");
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
pub use hiqlite_wal::LogSync;
pub use openraft::SnapshotPolicy;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display};
#[cfg(feature = "sqlite")]
use crate::store::state_machine::sqlite::state_machine::Response;
#[cfg(any(feature = "sqlite", feature = "cache"))]
pub use crate::{client::Client, error::Error};
#[cfg(any(feature = "sqlite", feature = "cache"))]
pub use config::{NodeConfig, RaftConfig};
#[cfg(feature = "sqlite")]
pub use query::cust_types::VecText;
#[cfg(feature = "sqlite")]
pub use crate::query::rows::Row;
#[cfg(feature = "sqlite")]
pub use crate::store::state_machine::sqlite::{
param::Param,
state_machine::Params,
transaction_variable::{StmtColumn, StmtIndex},
};
#[cfg(feature = "dlock")]
pub use client::dlock::Lock;
#[cfg(feature = "sqlite")]
pub use migration::AppliedMigration;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod app_state;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod client;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod config;
#[cfg(all(any(feature = "sqlite", feature = "cache"), feature = "toml"))]
mod config_toml;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod error;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod helpers;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod init;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod network;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod start;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod store;
#[cfg(feature = "backup")]
mod backup;
#[cfg(feature = "dashboard")]
mod dashboard;
#[cfg(feature = "sqlite")]
mod migration;
#[cfg(feature = "sqlite")]
mod query;
#[cfg(any(feature = "sqlite", feature = "cache"))]
mod split_brain_check;
#[cfg(feature = "macros")]
pub mod macros;
#[cfg(feature = "s3")]
pub mod s3;
#[cfg(feature = "server")]
pub mod server;
mod http_client;
#[cfg(any(feature = "sqlite", feature = "cache"))]
pub mod tls;
type NodeId = u64;
pub trait CacheVariants {
fn hiqlite_cache_index(&self) -> usize;
fn hiqlite_cache_variants() -> &'static [(usize, &'static str)];
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Node {
pub id: NodeId,
pub addr_raft: String,
pub addr_api: String,
}
impl Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Node {{ id: {}, rpc_addr: {}, api_addr: {} }}",
self.id, self.addr_raft, self.addr_api
)
}
}
#[cfg(feature = "sqlite")]
mod empty {
use crate::CacheVariants;
#[derive(Debug)]
pub enum Empty {}
impl CacheVariants for Empty {
fn hiqlite_cache_index(&self) -> usize {
unreachable!()
}
fn hiqlite_cache_variants() -> &'static [(usize, &'static str)] {
&[]
}
}
}
#[cfg(feature = "sqlite")]
pub async fn start_node(node_config: NodeConfig) -> Result<Client, Error> {
start::start_node_inner::<empty::Empty>(node_config).await
}
#[cfg(feature = "cache")]
pub async fn start_node_with_cache<C>(node_config: NodeConfig) -> Result<Client, Error>
where
C: Debug + CacheVariants,
{
start::start_node_inner::<C>(node_config).await
}