Returns the size of the shared memory to allocate SessionStateArray */ * Grabs one entry in the sessionStateArray for current session. * If the current session already has an entry, it just returns the * pointer to the previously grabbed entry. */
| 51 | * pointer to the previously grabbed entry. |
| 52 | */ |
| 53 | static SessionState* |
| 54 | SessionState_Acquire(int sessionId) |
| 55 | { |
| 56 | LWLockAcquire(SessionStateLock, LW_EXCLUSIVE); |
| 57 | |
| 58 | SessionState *cur = AllSessionStateEntries->usedList; |
| 59 | |
| 60 | while (cur != NULL && cur->sessionId != sessionId) |
| 61 | { |
| 62 | Assert(INVALID_SESSION_ID != cur->sessionId); |
| 63 | cur = cur->next; |
| 64 | } |
| 65 | |
| 66 | if (NULL == cur && NULL == AllSessionStateEntries->freeList) |
| 67 | { |
| 68 | LWLockRelease(SessionStateLock); |
| 69 | ereport(FATAL, |
| 70 | (errcode(ERRCODE_TOO_MANY_CONNECTIONS), |
| 71 | errmsg("too many sessions"), |
| 72 | errdetail("Could not acquire resources for additional sessions."), |
| 73 | errhint("Disconnect some sessions and try again."))); |
| 74 | } |
| 75 | |
| 76 | SessionState *acquired = cur; |
| 77 | |
| 78 | /* |
| 79 | * Nothing was acquired for this session from any other processes. Therefore, |
| 80 | * acquire a new entry, and reset its properties. |
| 81 | */ |
| 82 | if (NULL == acquired) |
| 83 | { |
| 84 | acquired = AllSessionStateEntries->freeList; |
| 85 | |
| 86 | AllSessionStateEntries->freeList = acquired->next; |
| 87 | |
| 88 | acquired->next = AllSessionStateEntries->usedList; |
| 89 | AllSessionStateEntries->usedList = acquired; |
| 90 | AllSessionStateEntries->numSession++; |
| 91 | Assert(AllSessionStateEntries->numSession <= AllSessionStateEntries->maxSession); |
| 92 | |
| 93 | acquired->sessionId = sessionId; |
| 94 | acquired->runawayStatus = RunawayStatus_NotRunaway; |
| 95 | acquired->sessionVmemRunaway = 0; |
| 96 | acquired->commandCountRunaway = 0; |
| 97 | acquired->pinCount = 0; |
| 98 | acquired->sessionVmem = 0; |
| 99 | acquired->cleanupCountdown = CLEANUP_COUNTDOWN_BEFORE_RUNAWAY; |
| 100 | acquired->activeProcessCount = 0; |
| 101 | acquired->idle_start = 0; |
| 102 | acquired->latestCursorCommandId = 0; |
| 103 | acquired->resGroupSlot = NULL; |
| 104 | |
| 105 | #ifdef USE_ASSERT_CHECKING |
| 106 | acquired->isModifiedSessionId = false; |
| 107 | #endif |
| 108 | |
| 109 | /* |
| 110 | * Make sure that the lock is reset to released. Note: this doesn't |
no test coverage detected