-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
152 lines (126 loc) · 4.46 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
#![allow(dead_code, unused)]
#![feature(impl_trait_in_assoc_type)]
use crate::app::{AppManager, APP_MANAGER_REF};
use crate::common::init_global_variable;
use crate::config::Config;
use crate::health_service::HealthService;
use crate::heartbeat::HeartbeatTask;
use crate::http::{HTTPServer, HttpMonitorService};
#[cfg(not(feature = "logforth"))]
use crate::log_service::LogService;
#[cfg(feature = "logforth")]
use crate::logforth_service::LogService;
use crate::mem_allocator::ALLOCATOR;
use crate::metric::MetricService;
use crate::readable_size::ReadableSize;
use crate::rpc::DefaultRpcService;
use crate::runtime::manager::RuntimeManager;
use crate::storage::StorageService;
use crate::tracing::FastraceWrapper;
use anyhow::Result;
use clap::{App, Arg};
use log::info;
use std::str::FromStr;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
pub mod app;
mod await_tree;
pub mod common;
pub mod composed_bytes;
pub mod config;
pub mod constant;
mod error;
pub mod event_bus;
pub mod grpc;
pub mod health_service;
pub mod heartbeat;
mod http;
pub mod kerberos;
pub mod id_layout;
pub mod lazy_initializer;
#[cfg(not(feature = "logforth"))]
mod log_service;
#[cfg(feature = "logforth")]
mod logforth_service;
pub mod bits;
pub mod block_id_manager;
pub mod histogram;
mod mem_allocator;
mod metric;
mod readable_size;
pub mod reject;
pub mod rpc;
pub mod runtime;
pub mod semaphore_with_index;
pub mod signal;
pub mod storage;
pub mod store;
pub mod tracing;
pub mod urpc;
pub mod util;
const MAX_MEMORY_ALLOCATION_SIZE_ENV_KEY: &str = "MAX_MEMORY_ALLOCATION_LIMIT_SIZE";
fn main() -> Result<()> {
setup_max_memory_allocation();
let args_match = App::new("Riffle")
.about("Rust based shuffle server for Apache Uniffle")
.arg(
Arg::with_name("config")
.short('c')
.long("config")
.value_name("FILE")
.default_value("./config.toml")
.help("Sets a custom config file")
.takes_value(true),
)
.get_matches();
let config_path = args_match.value_of("config").unwrap_or("./config.toml");
let config = Config::from(config_path);
#[cfg(not(feature = "logforth"))]
let _guard = LogService::init(&config.log);
#[cfg(feature = "logforth")]
let _guard = LogService::init(&config.log);
info!(
"Riffle is built on the git commit hash: {}",
env!("GIT_COMMIT_HASH")
);
init_global_variable(&config);
info!("The specified config show as follows: \n {:#?}", config);
let runtime_manager = RuntimeManager::from(config.runtime_config.clone());
let storage = StorageService::init(&runtime_manager, &config);
let app_manager_ref = AppManager::get_ref(runtime_manager.clone(), config.clone(), &storage);
storage.with_app_manager(&app_manager_ref);
let _ = APP_MANAGER_REF.set(app_manager_ref.clone());
let health_service =
HealthService::new(&app_manager_ref, &storage, &config.health_service_config);
MetricService::init(&config, runtime_manager.clone());
FastraceWrapper::init(config.clone());
HeartbeatTask::init(&config, &runtime_manager, &app_manager_ref, &health_service);
HttpMonitorService::init(&config, runtime_manager.clone());
DefaultRpcService {}.start(&config, runtime_manager, app_manager_ref)?;
Ok(())
}
fn setup_max_memory_allocation() {
#[cfg(all(unix, feature = "allocator-analysis"))]
{
let _ = std::env::var(MAX_MEMORY_ALLOCATION_SIZE_ENV_KEY).map(|v| {
let readable_size = ReadableSize::from_str(v.as_str()).unwrap();
ALLOCATOR.set_limit(readable_size.as_bytes() as usize)
});
}
}