test_group_deadlocks module from Amit
authorRobert Haas <rhaas@postgresql.org>
Thu, 21 Jan 2016 19:33:07 +0000 (14:33 -0500)
committerRobert Haas <rhaas@postgresql.org>
Mon, 1 Feb 2016 21:05:04 +0000 (16:05 -0500)
contrib/Makefile
contrib/test_group_deadlocks/Makefile [new file with mode: 0644]
contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql [new file with mode: 0644]
contrib/test_group_deadlocks/test_group_deadlocks.c [new file with mode: 0644]
contrib/test_group_deadlocks/test_group_deadlocks.control [new file with mode: 0644]

index bd251f6c668e1a4b14d3a4869bb0f30a487b5919..ff3c54d3c7de68971ceeb3f76696787eddca9951 100644 (file)
@@ -43,6 +43,7 @@ SUBDIRS = \
                tablefunc       \
                tcn             \
                test_decoding   \
+               test_group_deadlocks    \
                tsm_system_rows \
                tsm_system_time \
                tsearch2        \
diff --git a/contrib/test_group_deadlocks/Makefile b/contrib/test_group_deadlocks/Makefile
new file mode 100644 (file)
index 0000000..057448c
--- /dev/null
@@ -0,0 +1,19 @@
+# contrib/test_group_deadlocks/Makefile
+
+MODULE_big = test_group_deadlocks
+OBJS = test_group_deadlocks.o $(WIN32RES)
+
+EXTENSION = test_group_deadlocks
+DATA = test_group_deadlocks--1.0.sql
+PGFILEDESC = "test_group_deadlocks - participate in group locking"
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/test_group_deadlocks
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql b/contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql
new file mode 100644 (file)
index 0000000..377c363
--- /dev/null
@@ -0,0 +1,15 @@
+/* contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION test_group_deadlocks" to load this file. \quit
+
+-- Register the function.
+CREATE FUNCTION become_lock_group_leader()
+RETURNS pg_catalog.void
+AS 'MODULE_PATHNAME'
+LANGUAGE C;
+
+CREATE FUNCTION become_lock_group_member(pid pg_catalog.int4)
+RETURNS pg_catalog.bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C;
diff --git a/contrib/test_group_deadlocks/test_group_deadlocks.c b/contrib/test_group_deadlocks/test_group_deadlocks.c
new file mode 100644 (file)
index 0000000..f3d980a
--- /dev/null
@@ -0,0 +1,57 @@
+/*-------------------------------------------------------------------------
+ *
+ * test_group_deadlocks.c
+ *               group locking utilities
+ *
+ * Copyright (c) 2010-2014, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *               contrib/test_group_deadlocks/test_group_deadlocks.c
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "fmgr.h"
+#include "storage/proc.h"
+#include "storage/procarray.h"
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1(become_lock_group_leader);
+PG_FUNCTION_INFO_V1(become_lock_group_member);
+
+
+/*
+ * become_lock_group_leader
+ *
+ * This function makes current backend process as lock group
+ * leader.
+ */
+Datum
+become_lock_group_leader(PG_FUNCTION_ARGS)
+{
+       BecomeLockGroupLeader();
+
+       PG_RETURN_VOID();
+}
+
+/*
+ * become_lock_group_member
+ *
+ * This function makes current backend process as lock group
+ * member of the group owned by the process whose pid is passed
+ * as first argument.
+ */
+Datum
+become_lock_group_member(PG_FUNCTION_ARGS)
+{
+       bool            member;
+       PGPROC          *procleader;
+       int32           pid = PG_GETARG_INT32(0);
+
+       procleader = BackendPidGetProc(pid);
+       member = BecomeLockGroupMember(procleader, pid);
+
+       PG_RETURN_BOOL(member);
+}
diff --git a/contrib/test_group_deadlocks/test_group_deadlocks.control b/contrib/test_group_deadlocks/test_group_deadlocks.control
new file mode 100644 (file)
index 0000000..e2dcc71
--- /dev/null
@@ -0,0 +1,5 @@
+# test_group_locking extension
+comment = 'become part of group'
+default_version = '1.0'
+module_pathname = '$libdir/test_group_deadlocks'
+relocatable = true