aboutsummaryrefslogtreecommitdiff
path: root/src/include/replication/basebackup_target.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-03-15 13:22:04 -0400
committerRobert Haas <rhaas@postgresql.org>2022-03-15 13:22:04 -0400
commite4ba69f3f4a1b997aa493cc02e563a91c0f35b87 (patch)
tree42896f0b83306b28fbc131ff45d6ab49ef33c821 /src/include/replication/basebackup_target.h
parent75eae090876f4d47bf6a1e1016627b75da612307 (diff)
downloadpostgresql-e4ba69f3f4a1b997aa493cc02e563a91c0f35b87.tar.gz
postgresql-e4ba69f3f4a1b997aa493cc02e563a91c0f35b87.zip
Allow extensions to add new backup targets.
Commit 3500ccc39b0dadd1068a03938e4b8ff562587ccc allowed for base backup targets, meaning that we could do something with the backup other than send it to the client, but all of those targets had to be baked in to the core code. This commit makes it possible for extensions to define additional backup targets. Patch by me, reviewed by Abhijit Menon-Sen. Discussion: http://postgr.es/m/CA+TgmoaqvdT-u3nt+_kkZ7bgDAyqDB0i-+XOMmr5JN2Rd37hxw@mail.gmail.com
Diffstat (limited to 'src/include/replication/basebackup_target.h')
-rw-r--r--src/include/replication/basebackup_target.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/include/replication/basebackup_target.h b/src/include/replication/basebackup_target.h
new file mode 100644
index 00000000000..e23ac29a89d
--- /dev/null
+++ b/src/include/replication/basebackup_target.h
@@ -0,0 +1,66 @@
+/*-------------------------------------------------------------------------
+ *
+ * basebackup_target.h
+ * Extensibility framework for adding base backup targets.
+ *
+ * Portions Copyright (c) 2010-2022, PostgreSQL Global Development Group
+ *
+ * src/include/replication/basebackup_target.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef BASEBACKUP_TARGET_H
+#define BASEBACKUP_TARGET_H
+
+#include "replication/basebackup_sink.h"
+
+struct BaseBackupTargetHandle;
+typedef struct BaseBackupTargetHandle BaseBackupTargetHandle;
+
+/*
+ * Extensions can call this function to create new backup targets.
+ *
+ * 'name' is the name of the new target.
+ *
+ * 'check_detail' is a function that accepts a target name and target detail
+ * and either throws an error (if the target detail is not valid or some other
+ * problem, such as a permissions issue, is detected) or returns a pointer to
+ * the data that will be needed to create a bbsink implementing that target.
+ * The second argumnt will be NULL if the TARGET_DETAIL option to the
+ * BASE_BACKUP command was not specified.
+ *
+ * 'get_sink' is a function that creates the bbsink. The first argument
+ * is the successor sink; the sink created by this function should always
+ * forward to this sink. The second argument is the pointer returned by a
+ * previous call to the 'check_detail' function.
+ *
+ * In practice, a user will type something like "pg_basebackup --target foo:bar
+ * -Xfetch". That will cause the server to look for a backup target named
+ * "foo". If one is found, the check_detail callback will be invoked for the
+ * string "bar", and whatever that callback returns will be passed as the
+ * second argument to the get_sink callback.
+ */
+extern void BaseBackupAddTarget(char *name,
+ void *(*check_detail) (char *, char *),
+ bbsink * (*get_sink) (bbsink *, void *));
+
+/*
+ * These functions are used by the core code to access base backup targets
+ * added via BaseBackupAddTarget(). The core code will pass the TARGET and
+ * TARGET_DETAIL strings obtained from the user to BaseBackupGetTargetHandle,
+ * which will either throw an error (if the TARGET is not recognized or the
+ * check_detail hook for that TARGET doesn't like the TARGET_DETAIL) or
+ * return a BaseBackupTargetHandle object that can later be passed to
+ * BaseBackupGetSink.
+ *
+ * BaseBackupGetSink constructs a bbsink implementing the desired target
+ * using the BaseBackupTargetHandle and the successor bbsink. It does this
+ * by arranging to call the get_sink() callback provided by the extension
+ * that implements the base backup target.
+ */
+extern BaseBackupTargetHandle *BaseBackupGetTargetHandle(char *target,
+ char *target_detail);
+extern bbsink *BaseBackupGetSink(BaseBackupTargetHandle *handle,
+ bbsink *next_sink);
+
+#endif