* errstart --- begin an error-reporting cycle * * Create and initialize error stack entry. Subsequently, errmsg() and * perhaps other routines will be called to further populate the stack entry. * Finally, errfinish() will be called to actually process the error report. * * Returns true in normal case. Returns false to short-circuit the error * report (if it's a warning or lower and not t
| 393 | * report (if it's a warning or lower and not to be reported anywhere). |
| 394 | */ |
| 395 | bool |
| 396 | errstart(int elevel, const char *domain) |
| 397 | { |
| 398 | ErrorData *edata; |
| 399 | bool output_to_server = false; |
| 400 | bool output_to_client = false; |
| 401 | int i; |
| 402 | |
| 403 | /* |
| 404 | * Check some cases in which we want to promote an error into a more |
| 405 | * severe error. None of this logic applies for non-error messages. |
| 406 | */ |
| 407 | if (elevel >= ERROR) |
| 408 | { |
| 409 | /* |
| 410 | * If we are inside a critical section, all errors become PANIC |
| 411 | * errors. See miscadmin.h. |
| 412 | */ |
| 413 | if (CritSectionCount > 0) |
| 414 | elevel = PANIC; |
| 415 | |
| 416 | /* |
| 417 | * Check reasons for treating ERROR as FATAL: |
| 418 | * |
| 419 | * 1. we have no handler to pass the error to (implies we are in the |
| 420 | * postmaster or in backend startup). |
| 421 | * |
| 422 | * 2. ExitOnAnyError mode switch is set (initdb uses this). |
| 423 | * |
| 424 | * 3. the error occurred after proc_exit has begun to run. (It's |
| 425 | * proc_exit's responsibility to see that this doesn't turn into |
| 426 | * infinite recursion!) |
| 427 | */ |
| 428 | if (elevel == ERROR) |
| 429 | { |
| 430 | if (PG_exception_stack == NULL || |
| 431 | ExitOnAnyError || |
| 432 | proc_exit_inprogress) |
| 433 | elevel = FATAL; |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * If master process hits FATAL, post PREPARE but before COMMIT / ABORT on segment, |
| 438 | * just master process dies silently, leaves dangling prepared xact on segment. |
| 439 | * This also introduces inconsistency in the cluster, as xact is commited on master |
| 440 | * and some segments and still in-progress on few others. |
| 441 | * Hence converting FATAL to PANIC, here to reset master and perform full recovery |
| 442 | * instead, which would clean the dangling transaction update to COMMIT / ABORT. |
| 443 | */ |
| 444 | if ((elevel == FATAL) && (Gp_role == GP_ROLE_DISPATCH)) |
| 445 | { |
| 446 | switch (getCurrentDtxState()) |
| 447 | { |
| 448 | case DTX_STATE_PREPARING: |
| 449 | case DTX_STATE_PREPARED: |
| 450 | case DTX_STATE_INSERTING_COMMITTED: |
| 451 | case DTX_STATE_INSERTED_COMMITTED: |
| 452 | case DTX_STATE_NOTIFYING_COMMIT_PREPARED: |
no test coverage detected