int checkPart (int partid,int partidx,int partsrno,int slotIndex) { int jid,m,tt; /* we have found slots for all jobs for this part */ if (partidx >= parts[partid].totjobs) return 1; jid = parts[partid].jobs[partidx]; for (tt=slotIndex;tt<tsec;tt++) { for (m=0;m<total_machines;m++) { if (!machineCanDo (m,jid)) continue; if (checkSlotsFor (m,jid,tt)) { markSlots(m,partid,partsrno,jid,tt,jobs[jid].rtime); if (checkPart (partid,partidx+1,partsrno,tt+jobs[jid].rtime)) return 1; else { markSlots(m,-1,-1,-1,tt,jobs[jid].rtime); return 0; } } } } return 0; }
void fillEmptySlots () { int partscreated = 1,p; int *partsrnos = (int *) malloc (total_parts*sizeof(int)); for(p=0;p<total_parts;p++) partsrnos[p]=1000; while (partscreated) { partscreated=0; for (p = 0; p < total_parts; p++) { if(checkPart (p, 0, partsrnos[p]+1, 0)) { partsrnos[p]++; partscreated++; parts[p].count_added++; } } } free(partsrnos); }
void ReplicatedMergeTreePartCheckThread::run() { if (need_stop) return; try { time_t current_time = time(nullptr); /// Take part from the queue for verification. PartsToCheckQueue::iterator selected = parts_queue.end(); /// end from std::list is not get invalidated time_t min_check_time = std::numeric_limits<time_t>::max(); { std::lock_guard<std::mutex> lock(parts_mutex); if (parts_queue.empty()) { if (!parts_set.empty()) { LOG_ERROR(log, "Non-empty parts_set with empty parts_queue. This is a bug."); parts_set.clear(); } } else { for (auto it = parts_queue.begin(); it != parts_queue.end(); ++it) { if (it->second <= current_time) { selected = it; break; } if (it->second < min_check_time) min_check_time = it->second; } } } if (selected == parts_queue.end()) return; checkPart(selected->first); if (need_stop) return; /// Remove the part from check queue. { std::lock_guard<std::mutex> lock(parts_mutex); if (parts_queue.empty()) { LOG_ERROR(log, "Someone erased cheking part from parts_queue. This is a bug."); } else { parts_set.erase(selected->first); parts_queue.erase(selected); } } task->schedule(); } catch (const zkutil::KeeperException & e) { tryLogCurrentException(log, __PRETTY_FUNCTION__); if (e.code == ZooKeeperImpl::ZooKeeper::ZSESSIONEXPIRED) return; task->scheduleAfter(PART_CHECK_ERROR_SLEEP_MS); } catch (...) { tryLogCurrentException(log, __PRETTY_FUNCTION__); task->scheduleAfter(PART_CHECK_ERROR_SLEEP_MS); } }