Use thread-specific storage for computing a snapshot.
authorPavan Deolasee <pavan.deolasee@gmail.com>
Thu, 15 Jun 2017 06:04:06 +0000 (11:34 +0530)
committerPavan Deolasee <pavan.deolasee@gmail.com>
Thu, 15 Jun 2017 06:11:22 +0000 (11:41 +0530)
commitfb56418d660437d1cbaa0aa7a4260ca826792ec9
treee3612a55edb7b8ff23be61fa233b266498385cfa
parent90d1109aa3397c6beb50b12cd8e5364861037424
Use thread-specific storage for computing a snapshot.

We mustn't use a global variable since concurrent GTM threads might try to
compute a snapshot at the same time and may overwrite the information before a
thread can send the complete snapshot to the client. Chi Gao
<chi.gao@microfun.com> reported that this can cause infinite wait on the client
side because the client expects N bytes of data, but only receives (N - x)
bytes and it keeps waiting for remaining x bytes which the GTM never sends.
While we don't have a report, it's obvious that it can also go wrong in the
other direction.

We fix this by using a thread-specific storage which ensures that the snapshot
cannot be changed while it's being sent to the client.

Report, analysis and fix by Chi Gao <chi.gao@microfun.com>. Some minor
editorialisation by me.

Backpatched to XL9_5_STABLE
src/gtm/main/gtm_snap.c
src/include/gtm/gtm.h