[pgpool-committers: 4183] pgpool: Fix query cache bug with streaming replication mode and extende

Tatsuo Ishii ishii at postgresql.org
Wed Aug 9 17:23:30 JST 2017


Fix query cache bug with streaming replication mode and extended query case.

- Commit cache upon receiving a command complete message, rather than
  upon receiving a "ready for query" message, except in an explicit
  transaction. Doing it upon the receiving ready for query message had
  serious problem with streaming replication mode and extended query
  case, because it is possible that multiple selects get executed
  before the ready for query message arrives. The older way cannot
  handle it because it only looked at the last command before the
  ready for query message.

- When query cache hits, do not forward cached messages to frontend in
  Execute(). Instead "inject" cached messages into the backend
  buffer. This is better than older way since it respects the pending
  messages and necessary treatment while receiving messages including
  parse complete and bind complete. Note that now the cached messages
  are returned only after a flush or a sync message sent. Before they
  are returned immediately while executing execute message. The newer
  behavior more resembles to the ordinary messages (no cached message).

  To avoid adding cache by the injected messages twice,
  "skip_cache_commit" flags is introduced in query context. The flag
  is set to true in Execute() if the injection
  happens. handle_query_cache() checks the flag and skips registering
  query results to the query cache if the flag is true. The flags is
  set to false if cache is not hit.

- Introduce new function pool_at_command_success() which were the code
  fragments in ReadyForQuery() to take care misc treatments including
  unsettling writing transaction flags in CommandComplete() as
  well. Also ReadyForQuery() now calls it.

- Fix memory leak. If a close request is not issued (this is typically
  the case when unnamed statements/portals used), temp cache buffer
  remains until the session end (at the session end, the memory for
  the buffer will be freed because they are in the session context
  memory. Thus only long running sessions hit the bug). Before we
  prepared new buffer when query cache committed. Now do not create
  new buffer there. Rather create a buffer when memqcache_register
  gets called if the temp buffer is not allocated yet.

Branch
------
V3_6_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=730a545ae6c46e64afafa6aef3f7630437cbf016

Modified Files
--------------
src/context/pool_query_context.c           |   1 +
src/context/pool_session_context.c         |  80 ++++++++-
src/include/context/pool_query_context.h   |   5 +
src/include/context/pool_session_context.h |   2 +
src/include/protocol/pool_proto_modules.h  |   2 +
src/protocol/CommandComplete.c             |  17 ++
src/protocol/child.c                       |   4 +
src/protocol/pool_proto_modules.c          | 274 ++++++++++++++++++-----------
src/query_cache/pool_memqcache.c           | 201 +++++++++++++++------
9 files changed, 427 insertions(+), 159 deletions(-)



More information about the pgpool-committers mailing list