* Write out a new initialization file with the current contents * of the relcache (either shared rels or local rels, as indicated). */
| 6547 | * of the relcache (either shared rels or local rels, as indicated). |
| 6548 | */ |
| 6549 | static void |
| 6550 | write_relcache_init_file(bool shared) |
| 6551 | { |
| 6552 | FILE *fp; |
| 6553 | char tempfilename[MAXPGPATH]; |
| 6554 | char finalfilename[MAXPGPATH]; |
| 6555 | int magic; |
| 6556 | HASH_SEQ_STATUS status; |
| 6557 | RelIdCacheEnt *idhentry; |
| 6558 | int i; |
| 6559 | |
| 6560 | /* |
| 6561 | * If we have already received any relcache inval events, there's no |
| 6562 | * chance of succeeding so we may as well skip the whole thing. |
| 6563 | */ |
| 6564 | if (relcacheInvalsReceived != 0L) |
| 6565 | return; |
| 6566 | |
| 6567 | /* |
| 6568 | * We must write a temporary file and rename it into place. Otherwise, |
| 6569 | * another backend starting at about the same time might crash trying to |
| 6570 | * read the partially-complete file. |
| 6571 | */ |
| 6572 | if (shared) |
| 6573 | { |
| 6574 | snprintf(tempfilename, sizeof(tempfilename), "global/%s.%d", |
| 6575 | RELCACHE_INIT_FILENAME, MyProcPid); |
| 6576 | snprintf(finalfilename, sizeof(finalfilename), "global/%s", |
| 6577 | RELCACHE_INIT_FILENAME); |
| 6578 | } |
| 6579 | else |
| 6580 | { |
| 6581 | snprintf(tempfilename, sizeof(tempfilename), "%s/%s.%d", |
| 6582 | DatabasePath, RELCACHE_INIT_FILENAME, MyProcPid); |
| 6583 | snprintf(finalfilename, sizeof(finalfilename), "%s/%s", |
| 6584 | DatabasePath, RELCACHE_INIT_FILENAME); |
| 6585 | } |
| 6586 | |
| 6587 | unlink(tempfilename); /* in case it exists w/wrong permissions */ |
| 6588 | |
| 6589 | fp = AllocateFile(tempfilename, PG_BINARY_W); |
| 6590 | if (fp == NULL) |
| 6591 | { |
| 6592 | /* |
| 6593 | * We used to consider this a fatal error, but we might as well |
| 6594 | * continue with backend startup ... |
| 6595 | */ |
| 6596 | ereport(WARNING, |
| 6597 | (errcode_for_file_access(), |
| 6598 | errmsg("could not create relation-cache initialization file \"%s\": %m", |
| 6599 | tempfilename), |
| 6600 | errdetail("Continuing anyway, but there's something wrong."))); |
| 6601 | return; |
| 6602 | } |
| 6603 | |
| 6604 | /* |
| 6605 | * Write a magic number to serve as a file version identifier. We can |
| 6606 | * change the magic number whenever the relcache layout changes. |
no test coverage detected