Skip to content
Snippets Groups Projects
Commit 4b46bbfa authored by Stephen R. van den Berg's avatar Stephen R. van den Berg
Browse files

pgsql: Disentangle concurrent stash flushes explicitly.

- Solves the last remaining one-deadlock-per-month problem.
- Speeds up the critical path with regard to stash-flushing.
parent c419939f
Branches
Tags
No related merge requests found
...@@ -320,6 +320,7 @@ class bufcon { ...@@ -320,6 +320,7 @@ class bufcon {
realbuffer->socket->query_fd(), mode, realbuffer->stashflushmode); realbuffer->socket->query_fd(), mode, realbuffer->stashflushmode);
if (mode > realbuffer->stashflushmode) if (mode > realbuffer->stashflushmode)
realbuffer->stashflushmode = mode; realbuffer->stashflushmode = mode;
lock = 0;
dirty = 0; dirty = 0;
this->clear(); this->clear();
if (lock = realbuffer->nostash->trylock(1)) { if (lock = realbuffer->nostash->trylock(1)) {
...@@ -475,10 +476,7 @@ class conxion { ...@@ -475,10 +476,7 @@ class conxion {
#endif #endif
started = lock; started = lock;
lock = 0; // Force release before acquiring next lock = 0; // Force release before acquiring next
lock = shortmux->lock(); if (sizeof(stash) && getstash(KEEP) > KEEP)
mode = getstash(KEEP);
lock = 0;
if (mode > KEEP)
sendcmd(mode); // Force out stash to the server sendcmd(mode); // Force out stash to the server
#ifdef PG_DEBUGRACE #ifdef PG_DEBUGRACE
return sess; return sess;
...@@ -501,7 +499,7 @@ class conxion { ...@@ -501,7 +499,7 @@ class conxion {
} }
private int getstash(int mode) { private int getstash(int mode) {
if (sizeof(stash)) { Thread.MutexKey lock = shortmux->lock();
add(stash); stash->clear(); add(stash); stash->clear();
foreach (stashqueue->try_read_array(); ; int|sql_result portal) foreach (stashqueue->try_read_array(); ; int|sql_result portal)
if (intp(portal)) if (intp(portal))
...@@ -513,7 +511,6 @@ class conxion { ...@@ -513,7 +511,6 @@ class conxion {
if (stashflushmode > mode) if (stashflushmode > mode)
mode = stashflushmode; mode = stashflushmode;
stashflushmode = KEEP; stashflushmode = KEEP;
}
return mode; return mode;
} }
...@@ -538,8 +535,9 @@ unfinalised: ...@@ -538,8 +535,9 @@ unfinalised:
} }
qportals->write(synctransact++); qportals->write(synctransact++);
} while (0); } while (0);
Thread.MutexKey lock = shortmux->lock(); if (sizeof(stash))
mode = getstash(mode); mode = getstash(mode);
for(;;) {
#ifdef PG_DEBUG #ifdef PG_DEBUG
mixed err = mixed err =
#endif #endif
...@@ -563,9 +561,20 @@ outer: ...@@ -563,9 +561,20 @@ outer:
} }
} while (0); } while (0);
started = 0; started = 0;
if (sizeof(stash) && (started = nostash->trylock(1))) {
#ifdef PG_DEBUGRACE
conxsess sess = conxsess(this);
sess->sendcmd(SENDOUT);
#else
mode = getstash(SENDOUT);
continue;
#endif
}
return; return;
}; };
lock = 0; break;
}
started = 0;
PD("Sendcmd failed %s\n", describe_backtrace(err)); PD("Sendcmd failed %s\n", describe_backtrace(err));
destruct(this); destruct(this);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment