witness: initial code framework

This commit is contained in:
Ian Barwick
2017-11-13 10:21:31 +09:00
parent 688e609169
commit dff2bcc5de
7 changed files with 114 additions and 15 deletions

View File

@@ -37,7 +37,8 @@ include Makefile.global
$(info Building against PostgreSQL $(MAJORVERSION))
REPMGR_CLIENT_OBJS = repmgr-client.o \
repmgr-action-primary.o repmgr-action-standby.o repmgr-action-bdr.o repmgr-action-cluster.o repmgr-action-node.o \
repmgr-action-primary.o repmgr-action-standby.o repmgr-action-witness.o \
repmgr-action-bdr.o repmgr-action-cluster.o repmgr-action-node.o \
configfile.o log.o strutil.o controldata.o dirutil.o compat.o dbutils.o
REPMGRD_OBJS = repmgrd.o repmgrd-physical.o repmgrd-bdr.o configfile.o log.o dbutils.o strutil.o controldata.o
DATE=$(shell date "+%Y-%m-%d")
@@ -77,6 +78,7 @@ additional-clean:
rm -f repmgr-client.o
rm -f repmgr-action-primary.o
rm -f repmgr-action-standby.o
rm -f repmgr-action-witness.o
rm -f repmgr-action-bdr.o
rm -f repmgr-action-node.o
rm -f repmgr-action-cluster.o

View File

@@ -6,7 +6,7 @@ CREATE TABLE repmgr.nodes (
upstream_node_id INTEGER NULL REFERENCES nodes (node_id) DEFERRABLE,
active BOOLEAN NOT NULL DEFAULT TRUE,
node_name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN('primary','standby','bdr')),
type TEXT NOT NULL CHECK (type IN('primary','standby','witness','bdr')),
location TEXT NOT NULL DEFAULT 'default',
priority INT NOT NULL DEFAULT 100,
conninfo TEXT NOT NULL,

View File

@@ -32,7 +32,7 @@ CREATE TABLE repmgr.nodes (
upstream_node_id INTEGER NULL REFERENCES repmgr.nodes (node_id) DEFERRABLE,
active BOOLEAN NOT NULL DEFAULT TRUE,
node_name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN('primary','standby','bdr')),
type TEXT NOT NULL CHECK (type IN('primary','standby','witness','bdr')),
location TEXT NOT NULL DEFAULT 'default',
priority INT NOT NULL DEFAULT 100,
conninfo TEXT NOT NULL,

47
repmgr-action-witness.c Normal file
View File

@@ -0,0 +1,47 @@
/*
* repmgr-action-witness.c
*
* Implements witness actions for the repmgr command line utility
*
* Copyright (c) 2ndQuadrant, 2010-2017
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/stat.h>
#include "repmgr.h"
#include "dirutil.h"
#include "compat.h"
#include "controldata.h"
#include "repmgr-client-global.h"
#include "repmgr-action-witness.h"
void
do_witness_register(void)
{
return;
}
void
do_witness_unregister(void)
{
return;
}
void do_witness_help(void)
{
return;
}

27
repmgr-action-witness.h Normal file
View File

@@ -0,0 +1,27 @@
/*
* repmgr-action-witness.h
* Copyright (c) 2ndQuadrant, 2010-2017
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REPMGR_ACTION_WITNESS_H_
#define _REPMGR_ACTION_WITNESS_H_
extern void do_witness_register(void);
extern void do_witness_unregister(void);
extern void do_witness_help(void);
#endif /* _REPMGR_ACTION_WITNESS_H_ */

View File

@@ -57,6 +57,7 @@
#include "repmgr-client-global.h"
#include "repmgr-action-primary.h"
#include "repmgr-action-standby.h"
#include "repmgr-action-witness.h"
#include "repmgr-action-bdr.h"
#include "repmgr-action-node.h"
@@ -703,6 +704,7 @@ main(int argc, char **argv)
*
* { PRIMARY | MASTER } REGISTER |
* STANDBY { REGISTER | UNREGISTER | CLONE [node] | PROMOTE | FOLLOW [node] | SWITCHOVER } |
* WITNESS { CREATE | REGISTER | UNREGISTER }
* BDR { REGISTER | UNREGISTER } |
* NODE { STATUS | CHECK | REJOIN | SERVICE } |
* CLUSTER { CROSSCHECK | MATRIX | SHOW | EVENT | CLEANUP }
@@ -771,6 +773,18 @@ main(int argc, char **argv)
else if (strcasecmp(repmgr_action, "STATUS") == 0)
action = NODE_STATUS;
}
else if (strcasecmp(repmgr_command, "WITNESS") == 0)
{
if (help_option == true)
{
do_witness_help();
exit(SUCCESS);
}
else if (strcasecmp(repmgr_action, "REGISTER") == 0)
action = WITNESS_REGISTER;
else if (strcasecmp(repmgr_action, "UNREGISTER") == 0)
action = WITNESS_UNREGISTER;
}
else if (strcasecmp(repmgr_command, "BDR") == 0)
#else
if (strcasecmp(repmgr_command, "BDR") == 0)
@@ -1164,6 +1178,12 @@ main(int argc, char **argv)
do_standby_switchover();
break;
/* WITNESS */
case WITNESS_REGISTER:
do_witness_register();
break;
case WITNESS_UNREGISTER:
do_witness_unregister();
break;
#else
/* we won't ever reach here, but stop the compiler complaining */
@@ -1175,6 +1195,8 @@ main(int argc, char **argv)
case STANDBY_PROMOTE:
case STANDBY_FOLLOW:
case STANDBY_SWITCHOVER:
case WITNESS_REGISTER:
case WITNESS_UNREGISTER:
break;
#endif

View File

@@ -23,7 +23,6 @@
#include "log.h"
#define NO_ACTION 0 /* Dummy default action */
#define PRIMARY_REGISTER 1
#define PRIMARY_UNREGISTER 2
@@ -33,17 +32,19 @@
#define STANDBY_PROMOTE 6
#define STANDBY_FOLLOW 7
#define STANDBY_SWITCHOVER 8
#define BDR_REGISTER 9
#define BDR_UNREGISTER 10
#define NODE_STATUS 11
#define NODE_CHECK 12
#define NODE_SERVICE 13
#define NODE_REJOIN 14
#define CLUSTER_SHOW 15
#define CLUSTER_CLEANUP 16
#define CLUSTER_MATRIX 17
#define CLUSTER_CROSSCHECK 18
#define CLUSTER_EVENT 19
#define WITNESS_REGISTER 9
#define WITNESS_UNREGISTER 10
#define BDR_REGISTER 11
#define BDR_UNREGISTER 12
#define NODE_STATUS 13
#define NODE_CHECK 14
#define NODE_SERVICE 15
#define NODE_REJOIN 16
#define CLUSTER_SHOW 17
#define CLUSTER_CLEANUP 18
#define CLUSTER_MATRIX 19
#define CLUSTER_CROSSCHECK 20
#define CLUSTER_EVENT 21
/* command line options without short versions */
#define OPT_HELP 1001