* 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. */
| 393 | * fd.c calls this whenever a (potentially) file is enlarged. |
| 394 | */ |
| 395 | void |
| 396 | UpdateWorkFileSize(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 | /* |
no test coverage detected