File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -344,18 +344,17 @@ ModelLifeCycle::GetModel(
344
344
345
345
// The case where the request is asking for latest version
346
346
int64_t latest = -1 ;
347
- for (auto & version_model : mit->second ) {
348
- if (version_model.first > latest) {
349
- std::lock_guard<std::mutex> lock (version_model.second ->mtx_ );
350
- if (version_model.second ->state_ == ModelReadyState::READY) {
351
- latest = version_model.first ;
352
- // Tedious, but have to set handle for any "latest" version
353
- // at the moment to avoid edge case like the following:
354
- // "versions : 1 3 2", version 3 is latest but is requested
355
- // to be unloaded when the iterator is examining version 2,
356
- // then 'model' will ensure version 3 is still valid
357
- *model = version_model.second ->model_ ;
358
- }
347
+ static_assert (
348
+ std::is_same<
349
+ decltype (mit->second )::key_compare, std::less<int64_t >>::value,
350
+ " Below assume versions are sorted in specific order" );
351
+ for (auto version_model = mit->second .rbegin ();
352
+ version_model != mit->second .rend (); ++version_model) {
353
+ std::lock_guard<std::mutex> lock (version_model->second ->mtx_ );
354
+ if (version_model->second ->state_ == ModelReadyState::READY) {
355
+ latest = version_model->first ;
356
+ *model = version_model->second ->model_ ;
357
+ break ;
359
358
}
360
359
}
361
360
if (latest == -1 ) {
You can’t perform that action at this time.
0 commit comments