| 225 | TabletNodeImpl::~TabletNodeImpl() {} |
| 226 | |
| 227 | bool TabletNodeImpl::Init() { |
| 228 | if (!InitCacheSystem()) { |
| 229 | LOG(ERROR) << "Init cache system failed, exit."; |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | InitDfsReadThreadLimiter(); |
| 234 | |
| 235 | if (FLAGS_tera_coord_type.empty()) { |
| 236 | LOG(ERROR) << "Note: We don't recommend that use '" |
| 237 | << "--tera_[zk|ins|mock_zk|mock_ins]_enabled' flag for your cluster " |
| 238 | "coord" |
| 239 | << " replace by '--tera_coord_type=[zk|ins|mock_zk|mock_ins|fake_zk]'" |
| 240 | << " flag is usually recommended."; |
| 241 | } |
| 242 | if (FLAGS_tera_coord_type == "zk" || (FLAGS_tera_coord_type.empty() && FLAGS_tera_zk_enabled)) { |
| 243 | zk_adapter_.reset(new TabletNodeZkAdapter(this, local_addr_)); |
| 244 | } else if (FLAGS_tera_coord_type == "ins" || |
| 245 | (FLAGS_tera_coord_type.empty() && FLAGS_tera_ins_enabled)) { |
| 246 | LOG(INFO) << "ins mode!"; |
| 247 | zk_adapter_.reset(new InsTabletNodeZkAdapter(this, local_addr_)); |
| 248 | } else if (FLAGS_tera_coord_type == "mock_zk" || |
| 249 | (FLAGS_tera_coord_type.empty() && FLAGS_tera_mock_zk_enabled)) { |
| 250 | LOG(INFO) << "mock zk mode!"; |
| 251 | zk_adapter_.reset(new MockTabletNodeZkAdapter(this, local_addr_)); |
| 252 | } else if (FLAGS_tera_coord_type == "mock_ins" || |
| 253 | (FLAGS_tera_coord_type.empty() && FLAGS_tera_mock_ins_enabled)) { |
| 254 | LOG(INFO) << "mock ins mode!"; |
| 255 | zk_adapter_.reset(new MockInsTabletNodeZkAdapter(this, local_addr_)); |
| 256 | } else if (FLAGS_tera_coord_type == "fake_zk" || FLAGS_tera_coord_type.empty()) { |
| 257 | LOG(INFO) << "fake zk mode!"; |
| 258 | zk_adapter_.reset(new FakeTabletNodeZkAdapter(this, local_addr_)); |
| 259 | } |
| 260 | |
| 261 | SetTabletNodeStatus(kIsIniting); |
| 262 | thread_pool_->AddTask(std::bind(&TabletNodeZkAdapterBase::Init, zk_adapter_.get())); |
| 263 | |
| 264 | // register cache metrics |
| 265 | cache_metrics_.reset(new CacheMetrics(ldb_block_cache_, ldb_table_cache_)); |
| 266 | RegisterTcmallocCollectors(); |
| 267 | // register snappy metrics |
| 268 | snappy_ratio_metric_.reset(new AutoCollectorRegister( |
| 269 | kSnappyCompressionRatioMetric, |
| 270 | std::unique_ptr<Collector>(new RatioCollector(&leveldb::snappy_before_size_counter, |
| 271 | &leveldb::snappy_after_size_counter, true)))); |
| 272 | |
| 273 | // update tablets status at background |
| 274 | tablet_healthcheck_thread_ = std::thread{&TabletNodeImpl::RefreshTabletsStatus, this}; |
| 275 | return true; |
| 276 | } |
| 277 | |
| 278 | bool TabletNodeImpl::InitCacheSystem() { |
| 279 | sysinfo_.SetPersistentCacheSize(0); |