mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-03 11:52:54 +00:00
* feat(meta): add optional schema for Postgres metadata tables - Add `schema` option to specify a custom schema for metadata tables - Update `PgStore` and `PgElection` to support optional schema - Modify SQL templates to use schema when provided - Add tests for schema support in Postgres backend Signed-off-by: Logic <zqr10159@dromara.org> * refactor(meta): remove unused `create_schema_statement` and simplify `PgSqlTemplateFactory` - Remove `create_schema_statement` from `PgSqlTemplateSet` struct - Simplify `PgSqlTemplateFactory` by removing `new` method and merging it with `with_schema` - Update related tests to reflect these changes Signed-off-by: Logic <zqr10159@dromara.org> * refactor(meta-srv): remove unused imports - Remove unused import of BoxedError from common_error::ext- Remove unused import of TlsOption from servers::tls Signed-off-by: Logic <zqr10159@dromara.org> * build(meta): update Postgres version and add error handling imports - Update Postgres version to 17 in docker-compose.yml - Add BoxedError import for error handling in meta-srv Signed-off-by: Logic <zqr10159@dromara.org> * feat(postgres): add support for optional schema in PgElection and related components Signed-off-by: Logic <zqr10159@dromara.org> * feat(postgres): add support for optional schema in PgElection and related components Signed-off-by: Logic <zqr10159@dromara.org> * fix(develop): update Postgres schema commands to specify host Signed-off-by: Logic <zqr10159@dromara.org> * refactor(postgres): simplify plugin options handling and update SQL examples Signed-off-by: Logic <zqr10159@dromara.org> * refactor(postgres): simplify plugin options handling and update SQL examples Signed-off-by: Logic <zqr10159@dromara.org> * fix(postgres): update meta_election_lock_id description for optional schema support Signed-off-by: Logic <zqr10159@dromara.org> * fix(postgres): add health check and fallback wait for Postgres in CI setup * fix(postgres): update Docker setup for Postgres and add support for Postgres 15 * fix(postgres): remove redundant Postgres setup step in CI configuration * Update tests-integration/fixtures/postgres/init.sql Co-authored-by: Weny Xu <wenymedia@gmail.com> * Update .github/workflows/develop.yml * Update tests-integration/fixtures/docker-compose.yml * Update src/common/meta/src/kv_backend/rds/postgres.rs Co-authored-by: Weny Xu <wenymedia@gmail.com> * Update src/common/meta/src/kv_backend/rds/postgres.rs Co-authored-by: Weny Xu <wenymedia@gmail.com> * Update src/common/meta/src/kv_backend/rds/postgres.rs Co-authored-by: Weny Xu <wenymedia@gmail.com> * Update src/common/meta/src/kv_backend/rds/postgres.rs Co-authored-by: Weny Xu <wenymedia@gmail.com> * fix: Refactor PostgreSQL backend to support optional schema in PgStore and related SQL templates * feat: Update PostgreSQL configuration and add PG15 specific integration tests * feat: Update PostgreSQL configuration and add PG15 specific integration tests * refactor(postgres): update test schemas from 'greptime_schema' to 'test_schema' * Update .github/workflows/develop.yml * refactor: minor factor Signed-off-by: WenyXu <wenymedia@gmail.com> * chore: apply suggestions Signed-off-by: WenyXu <wenymedia@gmail.com> * fix: fix unit test Signed-off-by: WenyXu <wenymedia@gmail.com> --------- Signed-off-by: Logic <zqr10159@dromara.org> Signed-off-by: WenyXu <wenymedia@gmail.com> Co-authored-by: Weny Xu <wenymedia@gmail.com>
319 lines
13 KiB
Rust
319 lines
13 KiB
Rust
// Copyright 2023 Greptime Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use std::time::Duration;
|
|
|
|
use cmd::options::GreptimeOptions;
|
|
use cmd::standalone::StandaloneOptions;
|
|
use common_config::{Configurable, DEFAULT_DATA_HOME};
|
|
use common_options::datanode::{ClientOptions, DatanodeClientOptions};
|
|
use common_telemetry::logging::{LoggingOptions, DEFAULT_LOGGING_DIR, DEFAULT_OTLP_HTTP_ENDPOINT};
|
|
use common_wal::config::raft_engine::RaftEngineConfig;
|
|
use common_wal::config::DatanodeWalConfig;
|
|
use datanode::config::{DatanodeOptions, RegionEngineConfig, StorageConfig};
|
|
use file_engine::config::EngineConfig as FileEngineConfig;
|
|
use flow::FlownodeOptions;
|
|
use frontend::frontend::FrontendOptions;
|
|
use meta_client::MetaClientOptions;
|
|
use meta_srv::metasrv::MetasrvOptions;
|
|
use meta_srv::selector::SelectorType;
|
|
use metric_engine::config::EngineConfig as MetricEngineConfig;
|
|
use mito2::config::MitoConfig;
|
|
use query::options::QueryOptions;
|
|
use servers::export_metrics::ExportMetricsOption;
|
|
use servers::grpc::GrpcOptions;
|
|
use servers::http::HttpOptions;
|
|
use servers::tls::{TlsMode, TlsOption};
|
|
use store_api::path_utils::WAL_DIR;
|
|
|
|
#[allow(deprecated)]
|
|
#[test]
|
|
fn test_load_datanode_example_config() {
|
|
let example_config = common_test_util::find_workspace_path("config/datanode.example.toml");
|
|
let options =
|
|
GreptimeOptions::<DatanodeOptions>::load_layered_options(example_config.to_str(), "")
|
|
.unwrap();
|
|
|
|
let expected = GreptimeOptions::<DatanodeOptions> {
|
|
component: DatanodeOptions {
|
|
node_id: Some(42),
|
|
meta_client: Some(MetaClientOptions {
|
|
metasrv_addrs: vec!["127.0.0.1:3002".to_string()],
|
|
timeout: Duration::from_secs(3),
|
|
heartbeat_timeout: Duration::from_millis(500),
|
|
ddl_timeout: Duration::from_secs(10),
|
|
connect_timeout: Duration::from_secs(1),
|
|
tcp_nodelay: true,
|
|
metadata_cache_max_capacity: 100000,
|
|
metadata_cache_ttl: Duration::from_secs(600),
|
|
metadata_cache_tti: Duration::from_secs(300),
|
|
}),
|
|
wal: DatanodeWalConfig::RaftEngine(RaftEngineConfig {
|
|
dir: Some(format!("{}/{}", DEFAULT_DATA_HOME, WAL_DIR)),
|
|
sync_period: Some(Duration::from_secs(10)),
|
|
recovery_parallelism: 2,
|
|
..Default::default()
|
|
}),
|
|
storage: StorageConfig {
|
|
data_home: DEFAULT_DATA_HOME.to_string(),
|
|
..Default::default()
|
|
},
|
|
region_engine: vec![
|
|
RegionEngineConfig::Mito(MitoConfig {
|
|
auto_flush_interval: Duration::from_secs(3600),
|
|
write_cache_ttl: Some(Duration::from_secs(60 * 60 * 8)),
|
|
..Default::default()
|
|
}),
|
|
RegionEngineConfig::File(FileEngineConfig {}),
|
|
RegionEngineConfig::Metric(MetricEngineConfig {
|
|
experimental_sparse_primary_key_encoding: false,
|
|
flush_metadata_region_interval: Duration::from_secs(30),
|
|
}),
|
|
],
|
|
logging: LoggingOptions {
|
|
level: Some("info".to_string()),
|
|
dir: format!("{}/{}", DEFAULT_DATA_HOME, DEFAULT_LOGGING_DIR),
|
|
otlp_endpoint: Some(DEFAULT_OTLP_HTTP_ENDPOINT.to_string()),
|
|
tracing_sample_ratio: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
export_metrics: ExportMetricsOption {
|
|
self_import: None,
|
|
remote_write: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
grpc: GrpcOptions::default()
|
|
.with_bind_addr("127.0.0.1:3001")
|
|
.with_server_addr("127.0.0.1:3001"),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
|
|
similar_asserts::assert_eq!(options, expected);
|
|
}
|
|
|
|
#[test]
|
|
fn test_load_frontend_example_config() {
|
|
let example_config = common_test_util::find_workspace_path("config/frontend.example.toml");
|
|
let options =
|
|
GreptimeOptions::<FrontendOptions>::load_layered_options(example_config.to_str(), "")
|
|
.unwrap();
|
|
let expected = GreptimeOptions::<FrontendOptions> {
|
|
component: FrontendOptions {
|
|
default_timezone: Some("UTC".to_string()),
|
|
meta_client: Some(MetaClientOptions {
|
|
metasrv_addrs: vec!["127.0.0.1:3002".to_string()],
|
|
timeout: Duration::from_secs(3),
|
|
heartbeat_timeout: Duration::from_millis(500),
|
|
ddl_timeout: Duration::from_secs(10),
|
|
connect_timeout: Duration::from_secs(1),
|
|
tcp_nodelay: true,
|
|
metadata_cache_max_capacity: 100000,
|
|
metadata_cache_ttl: Duration::from_secs(600),
|
|
metadata_cache_tti: Duration::from_secs(300),
|
|
}),
|
|
logging: LoggingOptions {
|
|
level: Some("info".to_string()),
|
|
dir: format!("{}/{}", DEFAULT_DATA_HOME, DEFAULT_LOGGING_DIR),
|
|
otlp_endpoint: Some(DEFAULT_OTLP_HTTP_ENDPOINT.to_string()),
|
|
tracing_sample_ratio: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
datanode: DatanodeClientOptions {
|
|
client: ClientOptions {
|
|
connect_timeout: Duration::from_secs(10),
|
|
tcp_nodelay: true,
|
|
..Default::default()
|
|
},
|
|
},
|
|
export_metrics: ExportMetricsOption {
|
|
self_import: None,
|
|
remote_write: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
grpc: GrpcOptions::default()
|
|
.with_bind_addr("127.0.0.1:4001")
|
|
.with_server_addr("127.0.0.1:4001"),
|
|
internal_grpc: Some(GrpcOptions::internal_default()),
|
|
http: HttpOptions {
|
|
cors_allowed_origins: vec!["https://example.com".to_string()],
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
similar_asserts::assert_eq!(options, expected);
|
|
}
|
|
|
|
#[test]
|
|
fn test_load_metasrv_example_config() {
|
|
let example_config = common_test_util::find_workspace_path("config/metasrv.example.toml");
|
|
let options =
|
|
GreptimeOptions::<MetasrvOptions>::load_layered_options(example_config.to_str(), "")
|
|
.unwrap();
|
|
let expected = GreptimeOptions::<MetasrvOptions> {
|
|
component: MetasrvOptions {
|
|
selector: SelectorType::default(),
|
|
data_home: DEFAULT_DATA_HOME.to_string(),
|
|
grpc: GrpcOptions {
|
|
bind_addr: "127.0.0.1:3002".to_string(),
|
|
server_addr: "127.0.0.1:3002".to_string(),
|
|
..Default::default()
|
|
},
|
|
logging: LoggingOptions {
|
|
dir: format!("{}/{}", DEFAULT_DATA_HOME, DEFAULT_LOGGING_DIR),
|
|
level: Some("info".to_string()),
|
|
otlp_endpoint: Some(DEFAULT_OTLP_HTTP_ENDPOINT.to_string()),
|
|
tracing_sample_ratio: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
datanode: DatanodeClientOptions {
|
|
client: ClientOptions {
|
|
timeout: Duration::from_secs(10),
|
|
connect_timeout: Duration::from_secs(10),
|
|
tcp_nodelay: true,
|
|
},
|
|
},
|
|
export_metrics: ExportMetricsOption {
|
|
self_import: None,
|
|
remote_write: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
backend_tls: Some(TlsOption {
|
|
mode: TlsMode::Prefer,
|
|
cert_path: String::new(),
|
|
key_path: String::new(),
|
|
ca_cert_path: String::new(),
|
|
watch: false,
|
|
}),
|
|
meta_schema_name: Some("greptime_schema".to_string()),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
similar_asserts::assert_eq!(options, expected);
|
|
}
|
|
|
|
#[test]
|
|
fn test_load_flownode_example_config() {
|
|
let example_config = common_test_util::find_workspace_path("config/flownode.example.toml");
|
|
let options =
|
|
GreptimeOptions::<FlownodeOptions>::load_layered_options(example_config.to_str(), "")
|
|
.unwrap();
|
|
let expected = GreptimeOptions::<FlownodeOptions> {
|
|
component: FlownodeOptions {
|
|
node_id: Some(14),
|
|
flow: Default::default(),
|
|
grpc: GrpcOptions {
|
|
bind_addr: "127.0.0.1:6800".to_string(),
|
|
server_addr: "127.0.0.1:6800".to_string(),
|
|
runtime_size: 2,
|
|
..Default::default()
|
|
},
|
|
logging: LoggingOptions {
|
|
dir: format!("{}/{}", DEFAULT_DATA_HOME, DEFAULT_LOGGING_DIR),
|
|
level: Some("info".to_string()),
|
|
otlp_endpoint: Some(DEFAULT_OTLP_HTTP_ENDPOINT.to_string()),
|
|
otlp_export_protocol: Some(common_telemetry::logging::OtlpExportProtocol::Http),
|
|
tracing_sample_ratio: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
tracing: Default::default(),
|
|
heartbeat: Default::default(),
|
|
// flownode deliberately use a slower query parallelism
|
|
// to avoid overwhelming the frontend with too many queries
|
|
query: QueryOptions {
|
|
parallelism: 1,
|
|
allow_query_fallback: false,
|
|
},
|
|
meta_client: Some(MetaClientOptions {
|
|
metasrv_addrs: vec!["127.0.0.1:3002".to_string()],
|
|
timeout: Duration::from_secs(3),
|
|
heartbeat_timeout: Duration::from_millis(500),
|
|
ddl_timeout: Duration::from_secs(10),
|
|
connect_timeout: Duration::from_secs(1),
|
|
tcp_nodelay: true,
|
|
metadata_cache_max_capacity: 100000,
|
|
metadata_cache_ttl: Duration::from_secs(600),
|
|
metadata_cache_tti: Duration::from_secs(300),
|
|
}),
|
|
http: HttpOptions {
|
|
addr: "127.0.0.1:4000".to_string(),
|
|
..Default::default()
|
|
},
|
|
user_provider: None,
|
|
memory: Default::default(),
|
|
},
|
|
..Default::default()
|
|
};
|
|
similar_asserts::assert_eq!(options, expected);
|
|
}
|
|
|
|
#[test]
|
|
fn test_load_standalone_example_config() {
|
|
let example_config = common_test_util::find_workspace_path("config/standalone.example.toml");
|
|
let options =
|
|
GreptimeOptions::<StandaloneOptions>::load_layered_options(example_config.to_str(), "")
|
|
.unwrap();
|
|
let expected = GreptimeOptions::<StandaloneOptions> {
|
|
component: StandaloneOptions {
|
|
default_timezone: Some("UTC".to_string()),
|
|
wal: DatanodeWalConfig::RaftEngine(RaftEngineConfig {
|
|
dir: Some(format!("{}/{}", DEFAULT_DATA_HOME, WAL_DIR)),
|
|
sync_period: Some(Duration::from_secs(10)),
|
|
recovery_parallelism: 2,
|
|
..Default::default()
|
|
}),
|
|
region_engine: vec![
|
|
RegionEngineConfig::Mito(MitoConfig {
|
|
auto_flush_interval: Duration::from_secs(3600),
|
|
write_cache_ttl: Some(Duration::from_secs(60 * 60 * 8)),
|
|
..Default::default()
|
|
}),
|
|
RegionEngineConfig::File(FileEngineConfig {}),
|
|
RegionEngineConfig::Metric(MetricEngineConfig {
|
|
experimental_sparse_primary_key_encoding: false,
|
|
flush_metadata_region_interval: Duration::from_secs(30),
|
|
}),
|
|
],
|
|
storage: StorageConfig {
|
|
data_home: DEFAULT_DATA_HOME.to_string(),
|
|
..Default::default()
|
|
},
|
|
logging: LoggingOptions {
|
|
level: Some("info".to_string()),
|
|
dir: format!("{}/{}", DEFAULT_DATA_HOME, DEFAULT_LOGGING_DIR),
|
|
otlp_endpoint: Some(DEFAULT_OTLP_HTTP_ENDPOINT.to_string()),
|
|
tracing_sample_ratio: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
export_metrics: ExportMetricsOption {
|
|
self_import: Some(Default::default()),
|
|
remote_write: Some(Default::default()),
|
|
..Default::default()
|
|
},
|
|
http: HttpOptions {
|
|
cors_allowed_origins: vec!["https://example.com".to_string()],
|
|
..Default::default()
|
|
},
|
|
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
similar_asserts::assert_eq!(options, expected);
|
|
}
|