MCPcopy Create free account
hub / github.com/apache/impala / AllocateRemoteSpace

Method AllocateRemoteSpace

be/src/runtime/tmp-file-mgr.cc:1430–1516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1428}
1429
1430Status TmpFileGroup::AllocateRemoteSpace(int64_t num_bytes, TmpFile** tmp_file,
1431 int64_t* file_offset, vector<int>* at_capacity_dirs) {
1432 // Only one remote dir supported currently.
1433 string dir = tmp_file_mgr_->tmp_dirs_remote_->path();
1434 // It is not supposed to have a remote directory other than HDFS, Ozone, or S3.
1435 DCHECK(IsHdfsPath(dir.c_str(), false) || IsOzonePath(dir.c_str(), false)
1436 || IsS3APath(dir.c_str(), false));
1437
1438 // Look for the space from a previous created file.
1439 if (!tmp_files_remote_.empty()) {
1440 TmpFile* tmp_file_cur = tmp_files_remote_.back().get();
1441 // If the file is blocklisted or is at capacity, we will create a new file instead.
1442 if (!tmp_file_cur->is_blacklisted()) {
1443 if (tmp_file_cur->AllocateSpace(num_bytes, file_offset)) {
1444 *tmp_file = tmp_file_cur;
1445 return Status::OK();
1446 }
1447 }
1448 }
1449
1450 // Return an error if the new bytes is over the bytes limit of the query or the remote
1451 // directory.
1452 int64_t new_bytes =
1453 current_bytes_allocated_.Load() + tmp_file_mgr_->GetRemoteTmpFileSize();
1454 if (bytes_limit_ != -1 && new_bytes > bytes_limit_) {
1455 return Status(TErrorCode::SCRATCH_LIMIT_EXCEEDED, bytes_limit_, GetBackendString());
1456 }
1457
1458 int64_t remote_dir_bytes_limit = tmp_file_mgr_->tmp_dirs_remote_->bytes_limit();
1459 if (remote_dir_bytes_limit != -1 && new_bytes > remote_dir_bytes_limit) {
1460 return Status(
1461 TErrorCode::SCRATCH_LIMIT_EXCEEDED, remote_dir_bytes_limit, GetBackendString());
1462 }
1463
1464 // The device id of remote directory is defined as the max local device id
1465 // plus the index of the remote dir. Since we only support one remote dir now,
1466 // the id is the max local device id plus one.
1467 DeviceId dev_id = tmp_file_mgr_->tmp_dirs_.size();
1468 string unique_name = lexical_cast<string>(random_generator()());
1469 stringstream file_name;
1470 dir = ConstructRemoteDirPath(dir,
1471 ExecEnv::GetInstance()->configured_backend_address().hostname,
1472 PrintId(ExecEnv::GetInstance()->backend_id(), "_"), PrintId(unique_id(), "_"));
1473
1474 string new_file_path = GenerateNewPath(dir, unique_name);
1475 const string& local_buffer_dir = tmp_file_mgr_->local_buff_dir_->path();
1476 string new_file_path_local = GenerateNewPath(local_buffer_dir, unique_name);
1477
1478 unique_ptr<TmpFileRemote> tmp_file_r = make_unique<TmpFileRemote>(
1479 this, dev_id, new_file_path, new_file_path_local, false, dir.c_str());
1480 if (tmp_file_r == nullptr) {
1481 return Status("Failed to allocate temporary file object.");
1482 }
1483 if (tmp_file_r->hdfs_conn_ == nullptr) {
1484 return Status(Substitute("Failed to connect to FS: $0.", dir));
1485 }
1486 shared_ptr<TmpFile> tmp_file_remote(move(tmp_file_r));
1487 int64_t file_size = tmp_file_mgr_->GetRemoteTmpFileSize();

Callers

nothing calls this directly

Calls 15

IsHdfsPathFunction · 0.85
IsOzonePathFunction · 0.85
IsS3APathFunction · 0.85
OKFunction · 0.85
GetBackendStringFunction · 0.85
ConstructRemoteDirPathFunction · 0.85
PrintIdFunction · 0.85
SubstituteFunction · 0.85
moveFunction · 0.85
pathMethod · 0.80
is_blacklistedMethod · 0.80
GetRemoteTmpFileSizeMethod · 0.80

Tested by

no test coverage detected