| 28 | } |
| 29 | |
| 30 | bool RescheduleJobRequest(TJobRequest* src, const TVector<ui16>& parentExecPlan, int localCompId, int ignoreCompId) { |
| 31 | Y_ASSERT(!parentExecPlan.empty()); |
| 32 | Y_ASSERT(localCompId != ignoreCompId); |
| 33 | int hostIdCount = src->HostId2Computer.ysize(); |
| 34 | |
| 35 | TVector<bool> isInParentExecPlan; |
| 36 | GetSelectedCompList(&isInParentExecPlan, parentExecPlan); |
| 37 | |
| 38 | TVector<bool> needHostId; |
| 39 | needHostId.resize(hostIdCount, false); |
| 40 | bool hasAnywhere = false; |
| 41 | for (int i = 0; i < src->Descr.ExecList.ysize(); ++i) { |
| 42 | const TJobParams& jp = src->Descr.ExecList[i]; |
| 43 | if (jp.HostId == TJobDescription::ANYWHERE_HOST_ID) |
| 44 | hasAnywhere = true; |
| 45 | else |
| 46 | needHostId[jp.HostId] = true; |
| 47 | } |
| 48 | |
| 49 | src->ExecPlan = parentExecPlan; |
| 50 | |
| 51 | // make hostId2Computer out of computers in parentExecPlan except localCompId |
| 52 | // excluding localCompId should help local-remote balance |
| 53 | TVector<TVector<int>> subsetHostId2Computer; |
| 54 | subsetHostId2Computer.resize(hostIdCount); |
| 55 | for (int hostId = 0; hostId < hostIdCount; ++hostId) { |
| 56 | TVector<int>& subsetHosts = subsetHostId2Computer[hostId]; |
| 57 | TVector<int>& srcHosts = src->HostId2Computer[hostId]; |
| 58 | if (srcHosts.empty()) |
| 59 | continue; |
| 60 | subsetHosts.resize(srcHosts.ysize()); |
| 61 | int dst = 0; |
| 62 | int ignoredCompPlace = -1; |
| 63 | for (int i = 0; i < srcHosts.ysize(); ++i) { |
| 64 | int compId = srcHosts[i]; |
| 65 | if (compId != localCompId) { |
| 66 | if (compId == ignoreCompId) |
| 67 | ignoredCompPlace = i; |
| 68 | else if (compId < isInParentExecPlan.ysize() && isInParentExecPlan[compId]) |
| 69 | subsetHosts[dst++] = compId; |
| 70 | } |
| 71 | } |
| 72 | if (ignoredCompPlace != -1) { |
| 73 | // this hostId has ignored comp |
| 74 | // remove it from the JobRequest's map |
| 75 | srcHosts.erase(srcHosts.begin() + ignoredCompPlace); |
| 76 | } |
| 77 | if (dst == 0) { |
| 78 | // have no replacement computer for this hostId in the parentExecPlan |
| 79 | // test if we need replacement and can do it |
| 80 | if ((hasAnywhere || needHostId[hostId]) && srcHosts.empty()) |
| 81 | return false; |
| 82 | if (needHostId[hostId]) { |
| 83 | // select replacement from outside of the group |
| 84 | int compId = srcHosts[RandomNumber(srcHosts.size())]; |
| 85 | subsetHosts[dst++] = compId; |
| 86 | AddCompToPlan(&src->ExecPlan, compId); |
| 87 | } |
no test coverage detected