| 370 | } |
| 371 | |
| 372 | Status TimezoneDatabase::LoadZoneAliasesFromHdfs(const string& hdfs_zone_alias_conf) { |
| 373 | DCHECK(!hdfs_zone_alias_conf.empty()); |
| 374 | |
| 375 | hdfsFS hdfs_conn; |
| 376 | RETURN_IF_ERROR( |
| 377 | HdfsFsCache::instance()->GetConnection(hdfs_zone_alias_conf, &hdfs_conn)); |
| 378 | |
| 379 | hdfsFile hdfs_file = hdfsOpenFile( |
| 380 | hdfs_conn, hdfs_zone_alias_conf.c_str(), O_RDONLY, 0, 0, 0); |
| 381 | if (hdfs_file == nullptr) { |
| 382 | return Status(GetHdfsErrorMsg("Failed to open HDFS file for reading: ", |
| 383 | hdfs_zone_alias_conf)); |
| 384 | } |
| 385 | |
| 386 | Status status = Status::OK(); |
| 387 | vector<char> buffer(HDFS_READ_SIZE); |
| 388 | int current_bytes_read = -1; |
| 389 | stringstream ss; |
| 390 | while (true) { |
| 391 | current_bytes_read = hdfsRead(hdfs_conn, hdfs_file, buffer.data(), buffer.size()); |
| 392 | if (current_bytes_read == 0) break; |
| 393 | if (current_bytes_read < 0) { |
| 394 | status = Status(TErrorCode::DISK_IO_ERROR, GetBackendString(), |
| 395 | GetHdfsErrorMsg("Error reading from HDFS file: ", hdfs_zone_alias_conf)); |
| 396 | break; |
| 397 | } |
| 398 | ss << string(buffer.data(), current_bytes_read); |
| 399 | } |
| 400 | |
| 401 | int hdfs_ret = hdfsCloseFile(hdfs_conn, hdfs_file); |
| 402 | if (hdfs_ret != 0) { |
| 403 | status.MergeStatus( |
| 404 | Status(ErrorMsg(TErrorCode::GENERAL, |
| 405 | GetHdfsErrorMsg("Failed to close HDFS file: ", hdfs_zone_alias_conf)))); |
| 406 | } |
| 407 | |
| 408 | if (status.ok()) { |
| 409 | status = LoadZoneAliases(ss, hdfs_zone_alias_conf.c_str()); |
| 410 | } |
| 411 | return status; |
| 412 | } |
| 413 | |
| 414 | Status TimezoneDatabase::LoadZoneAliases(istream &is, const char* path) { |
| 415 | string line, alias, value; |
nothing calls this directly
no test coverage detected