Skip to content

Commit 8cf2408

Browse files
committed
Change env_path to canonical_env_path
1 parent 2e21869 commit 8cf2408

2 files changed

Lines changed: 37 additions & 32 deletions

File tree

src/pb_env.cc

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ EnvironmentManager::EnvironmentManager()
240240
}
241241

242242
std::string
243-
EnvironmentManager::ExtractIfNotExtracted(const std::string& env_source)
243+
EnvironmentManager::ExtractIfNotExtracted(const std::string& env_path)
244244
{
245245
std::string canonical_env_path = [&] {
246246
char canonical_env_path[PATH_MAX + 1];
247-
char* err = realpath(env_source.c_str(), canonical_env_path);
247+
char* err = realpath(env_path.c_str(), canonical_env_path);
248248
if (err == nullptr) {
249249
throw PythonBackendException(
250-
"Failed to get the canonical path for " + env_source + ".");
250+
"Failed to get the canonical path for " + env_path + ".");
251251
}
252252
return std::string(canonical_env_path);
253253
}();
@@ -271,34 +271,34 @@ EnvironmentManager::ExtractIfNotExtracted(const std::string& env_source)
271271
std::lock_guard<std::mutex> lk(mutex_);
272272

273273
time_t last_modified_time;
274-
LastModifiedTime(env_source, &last_modified_time);
274+
LastModifiedTime(canonical_env_path, &last_modified_time);
275275

276-
auto env_itr = env_map_.find(env_source);
276+
auto env_itr = env_map_.find(canonical_env_path);
277277
// Extract only if the env has not been extracted yet.
278278
if (env_itr == env_map_.end()) {
279279
LOG_MESSAGE(
280280
TRITONSERVER_LOG_VERBOSE,
281-
("Extracting Python execution env " + env_source).c_str());
281+
("Extracting Python execution env " + canonical_env_path).c_str());
282282

283283
std::string dst_env_path =
284284
std::string(base_path_) + "/" + std::to_string(env_path_counter_);
285285
++env_path_counter_;
286286

287-
// Add the environment to the list of environments
287+
// Add the environment to the list of environments.
288288
env_itr = env_map_
289289
.try_emplace(
290-
env_source, env_source, dst_env_path, last_modified_time)
290+
canonical_env_path, canonical_env_path, dst_env_path,
291+
last_modified_time)
291292
.first;
292293
} else {
293294
Environment& env = env_itr->second;
294295

295296
// Check if the environment has been modified and would
296-
// need to be extracted again (or the current environment has no owners
297-
// anymore).
297+
// need to be extracted again.
298298
if (env.LastModifiedTime() != last_modified_time) {
299299
LOG_MESSAGE(
300300
TRITONSERVER_LOG_VERBOSE,
301-
("Re-extracting Python execution env " + env_source).c_str());
301+
("Re-extracting Python execution env " + canonical_env_path).c_str());
302302
// Environment file has been updated. Need to clear
303303
// the previously extracted environment and extract
304304
// the environment to the same destination directory.
@@ -308,37 +308,39 @@ EnvironmentManager::ExtractIfNotExtracted(const std::string& env_source)
308308

309309
Environment& env = env_itr->second;
310310

311-
// Reference counter must be incremented on each ExtractIfNotExtracted call
311+
// Reference counter must be incremented on each ExtractIfNotExtracted call.
312312
env.IncrementRefCount();
313313

314314
LOG_MESSAGE(
315315
TRITONSERVER_LOG_VERBOSE,
316-
("Successfully extracted Python execution env " + env_source).c_str());
316+
("Successfully extracted Python execution env " + canonical_env_path)
317+
.c_str());
317318

318-
return env.Path();
319+
return env.Destination();
319320
}
320321

321322
void
322-
EnvironmentManager::DropEnvironment(const std::string& env_source)
323+
EnvironmentManager::DropEnvironment(const std::string& canonical_env_path)
323324
{
324325
LOG_MESSAGE(
325326
TRITONSERVER_LOG_VERBOSE,
326-
("Trying to drop Python execution env " + env_source).c_str());
327+
("Trying to drop Python execution env " + canonical_env_path).c_str());
327328

328329
std::lock_guard<std::mutex> lk(mutex_);
329330

330-
auto env_itr = env_map_.find(env_source);
331+
auto env_itr = env_map_.find(canonical_env_path);
331332
if (env_itr != env_map_.end()) {
332333
if (env_itr->second.DecrementRefCount() == 0) {
333334
env_map_.erase(env_itr);
334335
LOG_MESSAGE(
335336
TRITONSERVER_LOG_VERBOSE,
336-
("Successfully dropped Python execution env " + env_source).c_str());
337+
("Successfully dropped Python execution env " + canonical_env_path)
338+
.c_str());
337339
}
338340
} else {
339341
LOG_MESSAGE(
340342
TRITONSERVER_LOG_VERBOSE,
341-
("The environment with the key '" + env_source +
343+
("The environment with the key '" + canonical_env_path +
342344
"' is not presented the env_map")
343345
.c_str());
344346
}
@@ -356,22 +358,24 @@ EnvironmentManager::~EnvironmentManager()
356358
}
357359

358360
EnvironmentManager::Environment::Environment(
359-
const std::string& source, const std::string& path,
361+
const std::string& source, const std::string& destination,
360362
const time_t& last_modified_time)
361-
: source_(source), path_(path), last_modified_time_(last_modified_time)
363+
: source_(source), destination_(destination),
364+
last_modified_time_(last_modified_time)
362365
{
363366
Extract();
364367
}
365368

366369
void
367370
EnvironmentManager::Environment::Extract()
368371
{
369-
int status = mkdir(path_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
372+
int status =
373+
mkdir(destination_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
370374
if (status != 0) {
371375
throw PythonBackendException(
372-
"Failed to create environment directory for '" + path_ + "'.");
376+
"Failed to create environment directory for '" + destination_ + "'.");
373377
}
374-
ExtractTarFile(source_, path_);
378+
ExtractTarFile(source_, destination_);
375379
}
376380

377381
void
@@ -385,7 +389,7 @@ EnvironmentManager::Environment::Update(const time_t& last_modified_time)
385389
void
386390
EnvironmentManager::Environment::Delete()
387391
{
388-
RecursiveDirectoryDelete(path_.c_str());
392+
RecursiveDirectoryDelete(destination_.c_str());
389393
}
390394

391395
EnvironmentManager::Environment::~Environment()

src/pb_env.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EnvironmentManager {
5050
class Environment {
5151
public:
5252
Environment(
53-
const std::string& source, const std::string& path,
53+
const std::string& source, const std::string& destination,
5454
const time_t& last_modified_time);
5555
~Environment();
5656

@@ -59,15 +59,15 @@ class EnvironmentManager {
5959
size_t DecrementRefCount() { return --ref_count_; }
6060

6161
const std::string& Source() const { return source_; }
62-
const std::string& Path() const { return path_; }
62+
const std::string& Destination() const { return destination_; }
6363
const time_t& LastModifiedTime() const { return last_modified_time_; }
6464

6565
private:
6666
void Extract();
6767
void Delete();
6868

6969
std::string source_;
70-
std::string path_;
70+
std::string destination_;
7171
time_t last_modified_time_;
7272

7373
size_t ref_count_ = 0;
@@ -77,13 +77,14 @@ class EnvironmentManager {
7777

7878
// Extracts the tar.gz file in the 'env_path' if it has not been
7979
// already extracted
80-
std::string ExtractIfNotExtracted(const std::string& env_source);
80+
std::string ExtractIfNotExtracted(const std::string& env_path);
8181

8282
~EnvironmentManager();
8383

84-
// Decreases the refcount for the environment identified by env_source.
85-
// If the refcount reaches zero, the environment is removed from the map.
86-
void DropEnvironment(const std::string& env_source);
84+
// Decrement the refcount for the environment identified by
85+
// canonical_env_path. If the refcount reaches zero, the environment is
86+
// removed from the map.
87+
void DropEnvironment(const std::string& canonical_env_path);
8788

8889
private:
8990
size_t env_path_counter_ = 0;

0 commit comments

Comments
 (0)