MCPcopy Create free account
hub / github.com/Tencent/phxqueue / DistubePendingQueues

Method DistubePendingQueues

phxqueue/consumer/hblock.cpp:195–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195void HeartBeatLock::DistubePendingQueues(const map<int, vector<Queue_t>> &sub_id2pending_queues) {
196 //if (impl_->ossid) OssAttrInc(impl_->ossid, 20, 1);
197
198 comm::utils::RWLock l(impl_->rwlock, comm::utils::RWLock::LockMode::WRITE);
199
200 for (auto &&kv : sub_id2pending_queues) {
201 auto &&sub_id = kv.first;
202 auto &&pending_queues = kv.second;
203
204 vector<bool> done;
205 done.resize(pending_queues.size(), false);
206
207 size_t idx;
208
209 // if there is a proc handling a queue in pending_queues, keep doing that. prevent from lock switching.
210 for (int vpid{0}; vpid < impl_->nproc; ++vpid) {
211 Queue_t *queue{&impl_->buf->queues[vpid]};
212
213 if (LOCK_ITEM_MAGIC == queue->magic && sub_id == queue->sub_id) {
214 for (idx = 0; idx < pending_queues.size(); ++idx) {
215 auto &&pending_queue = pending_queues[idx];
216 if (queue->sub_id == pending_queue.sub_id &&
217 queue->store_id == pending_queue.store_id &&
218 queue->queue_id == pending_queue.queue_id) {
219
220 if (!done[idx]) {
221 done[idx] = true;
222 QLInfo("QUEUEINFO: vpid %d keep sub %u store %u queue %u", vpid, queue->sub_id, queue->store_id, queue->queue_id);
223 } else {
224 memset(queue, 0, sizeof(Queue_t));
225 }
226
227 break;
228 }
229 }
230 if (pending_queues.size() == idx) {
231 memset(queue, 0, sizeof(Queue_t));
232 }
233 }
234 }
235
236 // the left nproc handle the left queues in pending_queues
237 for (int vpid{0}; vpid < impl_->nproc; ++vpid) {
238 Queue_t *queue{&impl_->buf->queues[vpid]};
239
240 if (LOCK_ITEM_MAGIC != queue->magic) {
241 idx = 0;
242 for (; idx < pending_queues.size(); ++idx) {
243 if (!done[idx]) break;
244 }
245 if (idx == pending_queues.size()) {
246 queue->magic = 0;
247 } else {
248 auto &&pending_queue = pending_queues[idx];
249
250 queue->magic = LOCK_ITEM_MAGIC;
251 queue->sub_id = pending_queue.sub_id;
252 queue->store_id = pending_queue.store_id;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected