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

Function PGSharedMemoryIsInUse

src/backend/port/sysv_shmem.c:319–339  ·  view source on GitHub ↗

* PGSharedMemoryIsInUse * * Is a previously-existing shmem segment still existing and in use? * * The point of this exercise is to detect the case where a prior postmaster * crashed, but it left child backends that are still running. Therefore * we only care about shmem segments that are associated with the intended * DataDir. This is an important consideration since accidental matches of

Source from the content-addressed store, hash-verified

317 * shmem segment IDs are reasonably common.
318 */
319bool
320PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
321{
322 PGShmemHeader *memAddress;
323 IpcMemoryState state;
324
325 state = PGSharedMemoryAttach((IpcMemoryId) id2, NULL, &memAddress);
326 if (memAddress && shmdt(memAddress) < 0)
327 elog(LOG, "shmdt(%p) failed: %m", memAddress);
328 switch (state)
329 {
330 case SHMSTATE_ENOENT:
331 case SHMSTATE_FOREIGN:
332 case SHMSTATE_UNATTACHED:
333 return false;
334 case SHMSTATE_ANALYSIS_FAILURE:
335 case SHMSTATE_ATTACHED:
336 return true;
337 }
338 return true;
339}
340
341/*
342 * Test for a segment with id shmId; see comment at IpcMemoryState.

Callers 1

CreateLockFileFunction · 0.50

Calls 1

PGSharedMemoryAttachFunction · 0.85

Tested by

no test coverage detected