1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9 /* User-specified role an environment should play in the replication group. */ 10 typedef enum { MASTER, CLIENT, UNKNOWN } ENV_ROLE; 11 12 /* User-specified information about a replication site. */ 13 typedef struct { 14 char *host; /* Host name. */ 15 u_int32_t port; /* Port on which to connect to this site. */ 16 int peer; /* Whether remote site is repmgr peer. */ 17 int creator; /* Whether local site is group creator. */ 18 } repsite_t; 19 20 /* Data used for common replication setup. */ 21 typedef struct { 22 const char *progname; 23 char *home; 24 int nsites; 25 int remotesites; 26 ENV_ROLE role; 27 repsite_t self; 28 repsite_t *site_list; 29 } SETUP_DATA; 30 31 /* Data shared by both repmgr and base versions of this program. */ 32 typedef struct { 33 int is_master; 34 int app_finished; 35 int in_client_sync; 36 } SHARED_DATA; 37 38 /* Arguments for support threads. */ 39 typedef struct { 40 DB_ENV *dbenv; 41 SHARED_DATA *shared; 42 } supthr_args; 43 44 /* Portability macros for basic threading & timing */ 45 #ifdef _WIN32 46 #define WIN32_LEAN_AND_MEAN 47 #include <windows.h> 48 #include <winsock2.h> 49 #define snprintf _snprintf 50 #define sleep(s) Sleep(1000 * (s)) 51 52 extern int getopt(int, char * const *, const char *); 53 54 typedef HANDLE thread_t; 55 #define thread_create(thrp, attr, func, arg) \ 56 (((*(thrp) = CreateThread(NULL, 0, \ 57 (LPTHREAD_START_ROUTINE)(func), (arg), 0, NULL)) == NULL) ? -1 : 0) 58 #define thread_join(thr, statusp) \ 59 ((WaitForSingleObject((thr), INFINITE) == WAIT_OBJECT_0) && \ 60 GetExitCodeThread((thr), (LPDWORD)(statusp)) ? 0 : -1) 61 62 #else /* !_WIN32 */ 63 #include <sys/time.h> 64 #include <pthread.h> 65 66 typedef pthread_t thread_t; 67 #define thread_create(thrp, attr, func, arg) \ 68 pthread_create((thrp), (attr), (func), (arg)) 69 #define thread_join(thr, statusp) pthread_join((thr), (statusp)) 70 71 #endif 72 73 void *checkpoint_thread __P((void *)); 74 int common_rep_setup __P((DB_ENV *, int, char *[], SETUP_DATA *)); 75 int create_env __P((const char *, DB_ENV **)); 76 int doloop __P((DB_ENV *, SHARED_DATA *)); 77 int env_init __P((DB_ENV *, const char *)); 78 int finish_support_threads __P((thread_t *, thread_t *)); 79 void *log_archive_thread __P((void *)); 80 int start_support_threads __P((DB_ENV *, supthr_args *, thread_t *, 81 thread_t *)); 82 void usage __P((const int, const char *)); 83