Branch: Tag:

2018-05-07

2018-05-07 21:07:21 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Eliminate rare deadlock on heavy interleaved queries.

432:       final bufcon|conxsess start(void|int waitforreal) {    Thread.MutexKey lock; + #ifdef PG_DEBUGRACE +  if (nostash->current_locking_thread()) +  PD("Nostash locked by %s\n", +  describe_backtrace(nostash->current_locking_thread()->backtrace())); + #endif    if (lock = (waitforreal ? nostash->lock : nostash->trylock)(1)) {    int mode;   #ifdef PG_DEBUGRACE
1486:    void|bufcon|conxsess plugbuffer = CHAIN(cs);    int retval = KEEP;    PD("%O Try Closeportal %d\n", _portalname, _state); -  Thread.MutexKey lock = closemux->lock(); +  Thread.MutexKey lock = closemux->lock(2); // When called from _sendexecute(), it is already locked    _fetchlimit = 0; // disables further Executes    switch (_state) {    case PARSING:
1530:       private void replenishrows() {    if (_fetchlimit && sizeof(datarows) <= _fetchlimit >> 1) { +  Thread.MutexKey lock = closemux->lock(); +  if (_fetchlimit) {    _fetchlimit = pgsqlsess._fetchlimit;    if (bytesreceived)    _fetchlimit =    min((portalbuffersize >> 1) * index / bytesreceived || 1, _fetchlimit); -  Thread.MutexKey lock = closemux->lock(); -  if (_fetchlimit && inflight <= (_fetchlimit - 1) >> 1) +  if (_fetchlimit) +  if (inflight <= (_fetchlimit - 1) >> 1)    _sendexecute(_fetchlimit); -  else if (!_fetchlimit) +  else    PD("<%O _fetchlimit %d, inflight %d, skip execute\n",    _portalname, _fetchlimit, inflight);    }    } -  +  }       final void _processdataready(array datarow, void|int msglen) {    bytesreceived += msglen;