Skip to main content

servers/
lib.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![feature(try_blocks)]
16#![feature(exclusive_wrapper)]
17
18use datafusion_expr::LogicalPlan;
19use sql::statements::statement::Statement;
20// Re-export for use in add_service! macro
21#[doc(hidden)]
22pub use tower;
23
24pub mod addrs;
25pub mod configurator;
26pub(crate) mod elasticsearch;
27pub mod error;
28pub mod grpc;
29
30mod hint_headers;
31pub mod http;
32pub mod influxdb;
33pub mod interceptor;
34pub mod metrics;
35pub mod metrics_handler;
36pub mod mysql;
37pub mod opentsdb;
38pub mod otel_arrow;
39pub mod otlp;
40pub mod pending_rows_batcher;
41mod pipeline;
42pub mod postgres;
43pub mod prom_remote_write;
44pub(crate) mod prom_row_builder;
45pub mod prom_store;
46pub mod prometheus;
47pub mod prometheus_handler;
48pub mod query_handler;
49pub mod repeated_field;
50pub mod request_memory_limiter;
51pub mod request_memory_metrics;
52mod row_writer;
53pub mod semantic;
54pub mod server;
55pub mod tls;
56
57/// Cached sql plan or statement for database interfaces
58#[derive(Clone, Debug)]
59pub enum SqlPlan {
60    /// Empty Query
61    Empty,
62    /// Hardcoded SQL shortcuts
63    Shortcut(String),
64    /// Datafusion parsed execution plan with the original statement
65    Plan(LogicalPlan, Statement),
66    /// Parsed statement when execution is not managed by datafusion
67    /// eg. CREATE TABLE
68    /// The String is the original query string to avoid AST round-trip issues
69    Statement(Statement, String),
70}
71
72/// Install the default crypto provider for rustls process-wide. see:
73///
74///  https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#using-the-per-process-default-cryptoprovider
75///
76/// for more information.
77pub fn install_default_crypto_provider() -> Result<(), String> {
78    rustls::crypto::CryptoProvider::install_default(rustls::crypto::aws_lc_rs::default_provider())
79        .map_err(|ret| {
80            format!(
81                "CryptoProvider already installed as: {:?}, but providing {:?}",
82                rustls::crypto::CryptoProvider::get_default(),
83                ret
84            )
85        })
86}