From 5387d9515849c328cfeb3c513aae74215324e343 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Tue, 15 Jan 2019 23:48:49 +0100
Subject: [PATCH 5/7] Retrieve shared location for dict tweak

---
 src/backend/commands/tsearchcmds.c | 5 +++++
 src/backend/tsearch/ts_shared.c    | 4 ++++
 src/backend/utils/cache/ts_cache.c | 1 +
 3 files changed, 10 insertions(+)

diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 6d2868ccb5..71b6d5a3c9 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -536,6 +536,9 @@ RemoveTSDictionaryById(Oid dictId)
 	 * leak.  It may happen if some backend used the dictionary before dropping,
 	 * the backend will hold its DSM segment till disconnecting or calling
 	 * lookup_ts_dictionary_cache().
+	 *
+	 * XXX This comment is already elsewhere, so maybe move all of that to the
+	 * ts_dict_shmem_release function comment.
 	 */
 	dict.id = dictId;
 	dict.xmin = HeapTupleHeaderGetRawXmin(tup->t_data);
@@ -658,6 +661,8 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
 	 * anymor.  The segment still may leak.  It may happen if some backend used
 	 * the dictionary before dropping, the backend will hold its DSM segment
 	 * till disconnecting or calling lookup_ts_dictionary_cache().
+	 *
+	 * XXX Move comment to ts_dict_shmem_release?
 	 */
 	dict.id = dictId;
 	dict.xmin = HeapTupleHeaderGetRawXmin(tup->t_data);
diff --git a/src/backend/tsearch/ts_shared.c b/src/backend/tsearch/ts_shared.c
index 748ab5a782..9a2bedc43a 100644
--- a/src/backend/tsearch/ts_shared.c
+++ b/src/backend/tsearch/ts_shared.c
@@ -188,6 +188,9 @@ ts_dict_shmem_location(DictInitData *init_data,
  * dict: key to search the dictionary's DSM segment.
  * unpin_segment: true if we need to unpin the segment in case if the dictionary
  *				  was dropped or altered.
+ *
+ * XXX Maybe change this to accept individual fields instead of DickPointerData,
+ * so that we don't have to build the struct elsewhere, just to call this function.
  */
 void
 ts_dict_shmem_release(DictPointerData *dict, bool unpin_segment)
@@ -375,3 +378,4 @@ recheck_table:
 
 	MemoryContextSwitchTo(old_context);
 }
+
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index a002a01d05..4ad103b87e 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -134,6 +134,7 @@ do_ts_dict_shmem_release(void)
 	hash_seq_init(&status, TSDictionaryCacheHash);
 	while ((entry = (TSDictionaryCacheEntry *) hash_seq_search(&status)) != NULL)
 	{
+		/* XXX not really a pointer, so the name is misleading */
 		DictPointerData dict_ptr;
 
 		dict_ptr.id = entry->dictId;
-- 
2.17.2

