MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / getAttachment

Method getAttachment

src/jrd/WorkerAttachment.cpp:276–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276StableAttachmentPart* WorkerAttachment::getAttachment(FbStatusVector* status, Database* dbb)
277{
278 // There should be no locked attachment.
279#ifdef _DEBUG
280 thread_db* tdbb = JRD_get_thread_data();
281 if (tdbb)
282 {
283 Attachment* att = tdbb->getAttachment();
284 if (att)
285 {
286 const StableAttachmentPart::Sync* sync = att->getStable()->getSync();
287 fb_assert(!sync || !sync->locked());
288 }
289 }
290#endif
291
292 Arg::Gds(isc_shutdown).copyTo(status);
293
294 WorkerAttachment* item = getByName(dbb->dbb_filename);
295 if (!item)
296 return NULL;
297
298 MutexLockGuard guard(item->m_mutex, FB_FUNCTION);
299
300 if (m_shutdown)
301 return NULL;
302
303 FB_SIZE_T maxWorkers = Config::getMaxParallelWorkers();
304 if (maxWorkers <= 0)
305 maxWorkers = MAX_ULONG;
306
307 StableAttachmentPart* sAtt = NULL;
308 while (!item->m_idleAtts.isEmpty())
309 {
310 if (m_shutdown)
311 return NULL;
312
313 sAtt = item->m_idleAtts.pop();
314 if (sAtt->getHandle())
315 {
316 status->init();
317 break;
318 }
319
320 // idle worker attachment was unexpectedly deleted, clean up and try next one
321 MutexUnlockGuard unlock(item->m_mutex, FB_FUNCTION);
322
323 FbLocalStatus local;
324 doDetach(&local, sAtt);
325 sAtt = NULL;
326 }
327
328 if (!sAtt)
329 {
330 if (item->m_activeAtts.getCount() >= maxWorkers)
331 {
332 (Arg::Gds(isc_random) << Arg::Str("No enough free worker attachments")).copyTo(status);
333 return NULL;

Callers

nothing calls this directly

Calls 15

JRD_get_thread_dataFunction · 0.85
GdsClass · 0.85
StrClass · 0.85
iscLogStatusFunction · 0.85
doAttachMethod · 0.80
isWorkerMethod · 0.80
getSyncMethod · 0.45
getStableMethod · 0.45
lockedMethod · 0.45
copyToMethod · 0.45
isEmptyMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected