pike.git / lib / modules / Sql.pmod / pgsql_util.pmod

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:538:    switch (mode) {    default:    break unfinalised;    case SYNCSEND:    PD("%d>Sync %d %d Queue\n",    socket->query_fd(), synctransact, ++queueoutidx);    add(PGSYNC);    mode = SENDOUT;    break;    case FLUSHLOGSEND: -  PD("%d>%O %d Queue simplequery %d bytes\n", socket->query_fd(), -  portal._portalname, ++queueoutidx, sizeof(this)); +  PD("%d>%d Queue simplequery %d bytes\n", +  socket->query_fd(), ++queueoutidx, sizeof(this));    mode = FLUSHSEND;    }    qportals->write(synctransact++);    } while (0);    if (sizeof(stash))    mode = getstash(mode);   #ifdef PG_DEBUG    mixed err;   #endif    for(;;) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:899:    if (!datarowtypes)    waitfordescribe();    {    Thread.MutexKey lock = closemux->lock();    if (_fetchlimit) {    array(Thread.MutexKey) reflock = ({ _fetchlimit = 0 });    for (;;) {    reflock[0] = lock;    lock = 0;    if (!_sendexecute(0, reflock)) { +  PD("Status_command_complete retry closemux %O\n", _portalname);    lock = closemux->lock();    continue;    }    }    }    lock = 0; // Force release before acquiring next    lock = _ddescribemux->lock();    if (!statuscmdcomplete)    PT(_ddescribe->wait(lock));    }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1148:    datarowdesc = drowdesc;    datarowtypes = drowtypes;    _ddescribe->broadcast();    }       final void _preparebind(array dtoid) {    array(string|int) paramValues = _params ? _params[2] : ({});    if (sizeof(dtoid) != sizeof(paramValues))    SUSERERROR("Invalid number of bindings, expected %d, got %d\n",    sizeof(dtoid), sizeof(paramValues)); +  PD("PrepareBind\n");    Thread.MutexKey lock = _ddescribemux->lock();    if (!_portalname) {    _portalname    = (_unnamedportalkey = pgsqlsess.unnamedportalmux->trylock(1))    ? "" : PORTALPREFIX   #ifdef PG_DEBUG    + (string)(c->socket->query_fd()) + "_"   #endif    + String.int2hex(pgsqlsess.pportalcount++);    lock = 0;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1350:    plugbuffer->add_int32(4)->add_int32((int)value);    break;    case INT2OID:    plugbuffer->add_int32(2)->add_int16((int)value);    break;    }    }    if (!datarowtypes) {    if (_tprepared && dontcacheprefix->match(_query))    m_delete(pgsqlsess->prepareds, _query), _tprepared = 0; +  PD("WaitForDescribe\n");    waitfordescribe();    } -  +  PD("About to bind %d\n", _state);    if (_state >= CLOSING)    lock = _unnamedstatementkey = 0;    else {    plugbuffer->add_int16(sizeof(datarowtypes));    if (sizeof(datarowtypes)) {    plugbuffer->add_ints(map(datarowtypes, readoidformat), 2);    lock = 0;    } else if (syncparse < 0 && !pgsqlsess->wasparallelisable    && !pgsqlsess->statementsinflight->drained(1)) {    lock = 0; // Unlock while we wait
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1398:    _tprepared.datarowtypes = datarowtypes;    }    }       final void _parseportal() {    for (;;) {    Thread.MutexKey lock = closemux->lock();    if ((syncparse || syncparse < 0 && pgsqlsess->wasparallelisable)    && !pgsqlsess->statementsinflight->drained()) {    lock = 0; // Unlock while we wait -  PD("Commit waiting for statements to finish\n"); +  PD("Commit waiting for statements to finish %d\n", +  pgsqlsess->statementsinflight->_count);    catch(PT(pgsqlsess->statementsinflight->wait_till_drained())); -  +  PD("Parseportal retry closemux %O\n", _portalname);    continue;    }    _state = PARSING;    stmtifkey = pgsqlsess->statementsinflight->acquire();    break;    }    statuscmdcomplete = 0;    pgsqlsess->wasparallelisable = paralleliseprefix->match(_query);    }   
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1495:    lock = closemux->lock();    if (_fetchlimit) {    _fetchlimit = pgsqlsess._fetchlimit;    if (bytesreceived)    _fetchlimit = min((portalbuffersize >> 1)    * index / bytesreceived || 1, _fetchlimit);    if (_fetchlimit)    if (inflight <= (_fetchlimit - 1) >> 1) {    array(Thread.MutexKey) reflock = ({ lock });    lock = 0; -  if (!_sendexecute(_fetchlimit, reflock)) +  if (!_sendexecute(_fetchlimit, reflock)) { +  PD("Replenishrows retry closemux %O\n", _portalname);    continue; -  +  }    } else    PD("<%O _fetchlimit %d, inflight %d, skip execute\n",    _portalname, _fetchlimit, inflight);    }    break;    }    }    }       final void _processdataready(array datarow, void|int msglen) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1532:    delayederror = LOSTERROR;    datarowtypes = ({});    _ddescribe->broadcast();    }    if (aborted && delayederror && pgsqlsess && !pgsqlsess.delayederror)    pgsqlsess.delayederror = delayederror; // Preserve error upstream    pgsqlsess = 0; // Sever connection to upstream    }       final void _releasesession(void|string statusccomplete) { +  int aborted = statusccomplete == "ABORT" ? 2 : 0;    c->runningportals[this] = 0;    if (statusccomplete && !statuscmdcomplete) {    Thread.MutexKey lock = _ddescribemux->lock();    statuscmdcomplete = statusccomplete;    _ddescribe->broadcast();    }    inflight = 0;    conxsess plugbuffer;    array(Thread.MutexKey) reflock = ({ 0 });    for (;;) { -  reflock[0] = closemux->lock(); -  if (!catch(plugbuffer = c->start(reflock))) { +  reflock[0] = closemux->lock(aborted); +  if (!catch(plugbuffer = c->start(reflock)))    if (plugbuffer)    plugbuffer->sendcmd(_closeportal(plugbuffer, reflock)); -  else +  else { +  PD("Releasesession retry closemux %O\n", _portalname);    continue;    }    break;    }    reflock[0] = 0;    if (_state < CLOSED) {    stmtifkey = 0;    _state = CLOSED;    }    datarows->write(1); // Signal EOF -  releaseconditions(statusccomplete == "ABORT"); +  releaseconditions(aborted);    }       protected void destroy() { -  catch { // inside destructors, exceptions don't work +  if (_state < CLOSED) +  catch { // inside destructors, exceptions don't work    _releasesession("ABORT");    };    }       final int _sendexecute(int fetchlimit,    void|array(Thread.MutexKey)|bufcon|conxsess plugbuffer) {    int flushmode;    array(Thread.MutexKey) reflock;    PD("Execute portal %O fetchlimit %d transtype %d\n", _portalname,    fetchlimit, transtype);
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1870:    if (cancelsecret > "") {    PD("CancelRequest\n");    conxion lcon = conxion(this, 0, 2);   #ifdef PG_DEBUG    mixed err =   #endif    catch(lcon->add_int32(16)->add_int32(PG_PROTOCOL(1234, 5678))    ->add_int32(backendpid)->add(cancelsecret)->sendcmd(FLUSHSEND));   #ifdef PG_DEBUG    if (err) -  PD("CancelRequest failed to connect %O\n", describe_backtrace(err)); +  PD("CancelRequest failed to connect %s\n", describe_backtrace(err));   #endif    destruct(lcon); // Destruct explicitly to avoid delayed close   #ifdef PG_DEBUGMORE    PD("Closetrace %O\n", backtrace());   #endif    } else    error("Connection not established, cannot cancel any query\n");    }       private string a2nls(array(string) msg) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:2503:    lastmessage += ({    pinpointerror(objectp(portal) && portal._query, msgresponse.P)    + pinpointerror(msgresponse.q, msgresponse.p)});    if (msgresponse.W)    lastmessage += ({msgresponse.W});    if (objectp(portal))    lastmessage += showbindings(portal);    switch (msgresponse.S) {    case "PANIC":werror(a2nls(lastmessage));    } -  case "25P02": // Preserve last error message +  case "25P02": // Preserve last error message    USERERROR(a2nls(lastmessage)); // Implicitly closed portal    }    break;    }    case 'N': {    PD("NoticeResponse\n");    mapping(string:string) msgresponse = getresponse(); -  +  switch (msgresponse.C) { +  default:    if (clearmessage) {    warningsdropcount += warningscollected;    clearmessage = warningscollected = 0;    lastmessage = ({});    }    warningscollected++;    lastmessage = ({sprintf("%s %s: %s",    msgresponse.S, msgresponse.C, msgresponse.M)});    int val;    if (val = msgisfatal(msgresponse)) { // Some warnings are fatal    preplastmessage(msgresponse);    PD(a2nls(lastmessage)); throw(val);    } -  +  case "25P01": // Suppress some warnings    break;    } -  +  break; +  }    case 'A': {    PD("NotificationResponse\n");    msglen -= 4 + 4;    int pid = cr->read_int32();    string condition, extrainfo;    {    array(string) ts = reads();    switch (sizeof(ts)) {   #if PG_DEBUG    case 0: