MCPcopy Create free account
hub / github.com/apache/cloudberry / UpdateWorkFileSize

Function UpdateWorkFileSize

src/backend/utils/workfile_manager/workfile_mgr.c:395–463  ·  view source on GitHub ↗

* Update the totals of the workfile set for given file. * * If the given file is not associated with a workfile set yet, * a new workfile set is created. * * fd.c calls this whenever a (potentially) file is enlarged. */

Source from the content-addressed store, hash-verified

393 * fd.c calls this whenever a (potentially) file is enlarged.
394 */
395void
396UpdateWorkFileSize(File file, uint64 newsize)
397{
398 WorkFileLocalEntry *localEntry;
399 WorkFileSetSharedEntry *work_set;
400 WorkFileUsagePerQuery *perquery;
401 int64 diff;
402
403 ensureLocalEntriesSize(file);
404 localEntry = &localCtl.entries[file];
405
406 work_set = localEntry->work_set;
407 /*
408 * We got here only when the file's fdstate is FD_WORKFILE, and that
409 * means the file is registered to a work set.
410 */
411 Assert(work_set);
412 perquery = work_set->perquery;
413
414 diff = (int64) newsize - localEntry->size;
415 if (diff == 0)
416 return;
417
418 LWLockAcquire(WorkFileManagerLock, LW_EXCLUSIVE);
419
420 if (!work_set->active)
421 {
422 ereport(WARNING,
423 (errmsg("workfile_set %s for current file is freed which should not happen.", work_set->prefix),
424 errprintstack(true)));
425 LWLockRelease(WorkFileManagerLock);
426 return;
427 }
428
429 Assert(perquery->active);
430
431 /*
432 * If the file is being enlarged, enforce the limits.
433 */
434 if (diff > 0)
435 {
436 if (gp_workfile_limit_per_query > 0 &&
437 (perquery->total_bytes + diff + 1023) / 1024 > gp_workfile_limit_per_query)
438 {
439 ereport(ERROR,
440 (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
441 errmsg("workfile per query size limit exceeded")));
442 }
443 if (gp_workfile_limit_per_segment &&
444 (workfile_shared->total_bytes + diff) / 1024 > gp_workfile_limit_per_segment)
445 {
446 ereport(ERROR,
447 (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
448 errmsg("workfile per segment size limit exceeded")));
449 }
450 }
451
452 /*

Callers 1

FileWriteFunction · 0.85

Calls 6

ensureLocalEntriesSizeFunction · 0.85
LWLockAcquireFunction · 0.85
LWLockReleaseFunction · 0.85
errmsgFunction · 0.50
errprintstackFunction · 0.50
errcodeFunction · 0.50

Tested by

no test coverage detected