593 lines
18 KiB
C
Executable File
593 lines
18 KiB
C
Executable File
#ifndef h_udr_include
|
|
#define h_udr_include
|
|
/******************************************************************************
|
|
*
|
|
* UDR_include.h - standard data replication daemon data definitions
|
|
*
|
|
* Module %M% Version %I% Date %H%
|
|
*
|
|
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
|
|
* This is unpublished proprietary source code of Ardent Software Inc.
|
|
* The copyright notice above does not evidence any actual or intended
|
|
* publication of such source code.
|
|
*
|
|
*******************************************************************************
|
|
*
|
|
* Maintenence log - insert most recent change descriptions at top
|
|
*
|
|
* Date.... GTAR# WHO Description.........................................
|
|
* 06/07/99 24138 OGO Add define token to store maximum datastore cache size
|
|
* 04/28/99 23641 OGO Modified caching structure to support dictionaries,
|
|
* 21797 OGO Multi-level and distributed files
|
|
* 24139 OGO change NT debugging to be file based like UNIX,
|
|
* added UDR_DEBUG
|
|
* 24140 OGO added new define UDR_LOGOLDEST for this
|
|
* 10/14/98 23801 SAP Change copyrights.
|
|
* 12/12/97 22338 OGO Added error for synchronization process.
|
|
* 12/08/97 20606 OGO Added comments and remove STRtstatic macro.
|
|
* 10/15/97 20606 DJD Finished replication.
|
|
* 07/17/97 20606 DPB Added information for sync process.
|
|
* 07/11/97 20246 DJD Changed UDR_LOGADDSUB to UDR_LOGUPDSUB. Added
|
|
* UDRLOGCONTROL and UDRREPCONTROL.
|
|
* 07/09/97 20246 DJD Added new control commands and increased logcontrol size
|
|
* 07/02/97 20606 DPB Added update daemon.
|
|
* 06/26/97 20606 LAG Added UDR_BLOCKSIZE
|
|
* 06/23/97 20606 DPB fixed include of uvntlog.h.
|
|
* 06/20/97 20606 DPB Added defines and macros for uvdrsrvd.
|
|
* 06/19/97 20606 LAG Added UDRreptask structure and various definitions
|
|
* 06/12/97 20606 MGM Add some pads
|
|
* 06/11/97 20606 MGM Add logfile header and datastore cache structs
|
|
* 06/05/97 20606 LAG Changed sysaddress member of UDRlogrec structure
|
|
* 05/29/97 20606 LAG Initial creation and sccs.
|
|
*
|
|
******************************************************************************/
|
|
|
|
#define TRUE 1
|
|
#define FALSE 0
|
|
|
|
|
|
/* Generic definitions to seperate LOG and REP manager */
|
|
#define UDRLOG 1
|
|
#define UDRREP 2
|
|
|
|
/* definition of four valid states for a database file on a system using data replication */
|
|
#define UDRNONE 0
|
|
#define UDRPUB 1
|
|
#define UDRSUB 2
|
|
#define UDRFAILOVER 4
|
|
|
|
/* UDR shared memory and logfile buffer sizes */
|
|
#define UDR_BLOCKSIZE 4096
|
|
#define UDR_BUFFER 4096
|
|
#define UDR_LOGBUFFER 5120
|
|
#define UDR_ADDR_BYTES 32
|
|
#define UDR_LGHEADER_SIZE 512
|
|
|
|
/* UDR log daemon failures */
|
|
#define UDRLG_FAILURE -1
|
|
#define UDRLG_FAILOPEN -2
|
|
|
|
/* UDR subsystem states */
|
|
#define UDR_STOPPED 0
|
|
#define UDR_RUNNING 1
|
|
#define UDR_CRASHED 2
|
|
#define UDR_LOGFULL 3
|
|
|
|
/* UDR update operations */
|
|
#define UDR_TXBEGIN 1
|
|
#define UDR_TXCOMMIT 2
|
|
#define UDR_TXROLLBACK 3
|
|
#define UDR_WRITE 4
|
|
#define UDR_DELETE 5
|
|
|
|
/* UDR Sync operations */
|
|
#define SYNC_NOACTION 0
|
|
#define SYNC_COPY 1
|
|
#define SYNC_DELETE 2
|
|
|
|
/* UDR control states */
|
|
#define UDR_SHUTDOWN 1
|
|
#define UDR_SUBSCRIBE 2
|
|
#define UDR_REPADDSYS 3
|
|
#define UDR_REPDELSYS 4
|
|
#define UDR_REPUPDSYS 5
|
|
#define UDR_LOGRESUME 6
|
|
#define UDR_LOGADDPUB 7
|
|
#define UDR_LOGDELPUB 8
|
|
#define UDR_LOGUPDSUB 9
|
|
#define UDR_LOGDELREMSUB 10
|
|
|
|
/* UDR semaphores */
|
|
#define UDR_SHMSEM 0
|
|
#define UDR_LG0SEM 1
|
|
#define UDR_LG1SEM 2
|
|
|
|
/* UDR system files */
|
|
#define UDR_PUBFILE "UV_UDRPUB"
|
|
#define UDR_SUBFILE "UV_UDRSUB"
|
|
#define UDR_SYSFILE "UV_UDRSYS"
|
|
|
|
/* UDR logfile prefix */
|
|
#define UDR_LOGPREFIX "uvdrlg"
|
|
|
|
/* UDR config file tokens */
|
|
#define UDR_CONFIG "uvdr.config"
|
|
#define UDR_LOGDIR "logdir"
|
|
#define UDR_REPDIR "repdir"
|
|
#define UDR_LOGBOOT "logboot"
|
|
#define UDR_REPBOOT "repboot"
|
|
#define UDR_LOGCURRENT "logcurrent"
|
|
#define UDR_LOGOLDEST "logoldest"
|
|
#define UDR_LOGSIZE "logsize"
|
|
#define UDR_DEBUG "debug"
|
|
|
|
/* UDR trace files */
|
|
#define UDR_LOGD_TRACE "uvdrlogd.info"
|
|
#define UDR_REPD_TRACE "uvdrrepd.info"
|
|
#define UDR_SRVD_TRACE "uvdrsrvd.info"
|
|
#define UDR_UPDD_TRACE "uvdrupdd.info"
|
|
|
|
/* UDR daemons */
|
|
#ifdef MSWIN
|
|
#define UVDRLOGD "/bin/uvdrlogd.exe"
|
|
#define UVDRREPD "/bin/uvdrrepd.exe"
|
|
#define UVDRSRVD "/bin/uvdrsrvd.exe"
|
|
#define UVDRUPDD "/bin/uvdrupdd.exe"
|
|
#else
|
|
#define UVDRLOGD "/bin/uvdrlogd"
|
|
#define UVDRREPD "/bin/uvdrrepd"
|
|
#define UVDRSRVD "/bin/uvdrsrvd"
|
|
#define UVDRUPDD "/bin/uvdrupdd"
|
|
#endif
|
|
|
|
#define UVDRDAEMON_STARTUP_OPT " -startup"
|
|
#define UVDRDAEMON_SHUTDOWN_OPT " -shutdown"
|
|
|
|
/*****************************************************************************
|
|
* The UDRreptask structure describes the system information used by the
|
|
* replication manager to control system replication scheduling.
|
|
*****************************************************************************/
|
|
|
|
struct UDRreptask {
|
|
int next_slot;
|
|
int system;
|
|
int scheduled;
|
|
pid_t pid;
|
|
time_t start_time;
|
|
int active;
|
|
};
|
|
|
|
#define SYSTASK struct UDRreptask
|
|
|
|
/*****************************************************************************
|
|
* The UDRshmrec structure describes the header of the records that are
|
|
* written to the shared memory buffer by the routines such as DBwrite_item
|
|
* and DBdelete_item. This header is common between all of the record types.
|
|
*****************************************************************************/
|
|
|
|
struct UDRshmrec {
|
|
char readflg;
|
|
char pad1;
|
|
short rec_type;
|
|
int datastore_num;
|
|
int rec_size;
|
|
int TXid;
|
|
int seq_no;
|
|
time_t timestamp;
|
|
};
|
|
|
|
#define UDRSHMREC struct UDRshmrec
|
|
|
|
/*
|
|
* Shared memory records with record_type == UDR_WRITE
|
|
* have the following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRshmrec |
|
|
* +-----------------------+
|
|
* | int key_len |
|
|
* +-----------------------+
|
|
* | char keydata[key_len] |
|
|
* +-----------------------+
|
|
* | int rec_len |
|
|
* +-----------------------+
|
|
* | char recdata[rec_len] |
|
|
* +-----------------------+
|
|
*
|
|
* If the update message is larger than the shared memory record,
|
|
* the message is split into multiple blocks. The primary block
|
|
* has the format shown above while all subsequent blocks have
|
|
* the following format:
|
|
*
|
|
* The variable in the UDRshmrec structure "UDRSHMREC->seq_no" signifies
|
|
* which part of the data base record this shared memory record contains.
|
|
* A value of "0" means all data is contained in this shared memory record.
|
|
* A value of "1" means this is the first shared memory record of n shared
|
|
* memory records used to hold the data record in question.
|
|
* A value of "i" means this is the i'th shared memory record of n shared
|
|
* memory records used to hold the data record in question.
|
|
* A value of "-1" means this is the n'th shared memory record of n shared
|
|
* memory records used to hold the data record in question:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRshmrec |
|
|
* +-----------------------+
|
|
* | int rec_len |
|
|
* +-----------------------+
|
|
* | char recdata[rec_len] |
|
|
* +-----------------------+
|
|
*
|
|
* Shared memory records with rec_type == UDR_DELETE have the
|
|
* following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRshmrec |
|
|
* +-----------------------+
|
|
* | int key_len |
|
|
* +-----------------------+
|
|
* | char keydata[key_len] |
|
|
* +-----------------------+
|
|
*
|
|
* Shared memory records with rec_type == UDR_TXBEGIN have the
|
|
* following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRshmrec |
|
|
* +-----------------------+
|
|
* | int rec_len |
|
|
* +-----------------------+
|
|
* | char recdata[rec_len] |
|
|
* +-----------------------+
|
|
*
|
|
* Shared memory records with rec_type == UDR_TXCOMMIT || UDR_TXROLLBACK
|
|
* have the following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRshmrec |
|
|
* +-----------------------+
|
|
*/
|
|
|
|
/*****************************************************************************
|
|
* The UDRlogrec structure describes the header of the records that are
|
|
* written to the logfiles by the logfile manager. This header is common
|
|
* between all of the record types.
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
* Logfile records with rec_type == UDR_WRITE have the
|
|
* following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRlogrec |
|
|
* +-----------------------+
|
|
* | int key_len |
|
|
* +-----------------------+
|
|
* | char keydata[key_len] |
|
|
* +-----------------------+
|
|
* | int rec_len |
|
|
* +-----------------------+
|
|
* | char recdata[rec_len] |
|
|
* +-----------------------+
|
|
*
|
|
* Logfile records with rec_type == UDR_DELETE have the
|
|
* following format:
|
|
*
|
|
* +-----------------------+
|
|
* | UDRlogrec |
|
|
* +-----------------------+
|
|
* | int key_len |
|
|
* +-----------------------+
|
|
* | char keydata[key_len] |
|
|
* +-----------------------+
|
|
*/
|
|
|
|
struct UDRlogrec {
|
|
int sysaddress[8];
|
|
short mess_type;
|
|
short rec_type;
|
|
int datastore_num;
|
|
int rec_size;
|
|
int TXid;
|
|
int seq_no;
|
|
time_t timestamp;
|
|
};
|
|
|
|
#define UDRLOGREC struct UDRlogrec
|
|
|
|
/*****************************************************************************
|
|
* The UDR_data structure describes the shared memory control structure
|
|
* used by UDR.
|
|
*****************************************************************************/
|
|
|
|
struct UDR_data {
|
|
|
|
/*
|
|
* these are set to zero when UniVerse is booted.
|
|
*
|
|
* state:
|
|
* -----
|
|
* 0 = uninitialized
|
|
* 1 = initializing
|
|
* 2 = enabled
|
|
* 3 = disabled
|
|
* 4 = suspended
|
|
* 5 = full
|
|
* 6 = crashed
|
|
* 7 = shutdown
|
|
*/
|
|
|
|
int logstate; /* logfile Manager state */
|
|
int logcontrol[4]; /* logfile Manager control ints */
|
|
pid_t logd; /* logfile Manager's pid */
|
|
int repstate; /* replication Manager state */
|
|
int repcontrol[4]; /* replication Manager control ints */
|
|
pid_t repd; /* replication Manager's pid */
|
|
|
|
/* these are set at the first boot up of UniVerse */
|
|
|
|
char *buff_start; /* start of data buffer */
|
|
int buff_size; /* precomputed for ease of use */
|
|
char *write_ptr;
|
|
char *read_ptr;
|
|
};
|
|
|
|
#define UDRDATA struct UDR_data
|
|
|
|
struct UDRLG_header {
|
|
int sysaddress[8];
|
|
int version;
|
|
char name[14];
|
|
unsigned int seqno;
|
|
int eof;
|
|
int peof;
|
|
time_t timestamp;
|
|
unsigned int
|
|
empty:1,
|
|
inuse:1,
|
|
need_sync:1,
|
|
has_tx:1,
|
|
need_archive:1,
|
|
closed:1,
|
|
crashed:1;
|
|
};
|
|
|
|
#define UDRLGHD struct UDRLG_header
|
|
|
|
struct UDRLG_cacheds {
|
|
int sysaddress[8];
|
|
int datastore;
|
|
struct UDRLG_cacheds *next;
|
|
};
|
|
|
|
#define UDRLGDS struct UDRLG_cacheds
|
|
|
|
/* access macros */
|
|
|
|
#define UDRENABLED DBshmseg->tune_vals.udrmode
|
|
|
|
#define UDRCONTROL DBshmseg->UDRcontrol
|
|
#define UDRLOGSTATE DBshmseg->UDRcontrol.logstate
|
|
#define UDRLOGCONTROL DBshmseg->UDRcontrol.logcontrol
|
|
#define UDRLOGPID DBshmseg->UDRcontrol.logd
|
|
#define UDRREPSTATE DBshmseg->UDRcontrol.repstate
|
|
#define UDRREPCONTROL DBshmseg->UDRcontrol.repcontrol
|
|
#define UDRREPPID DBshmseg->UDRcontrol.repd
|
|
#define UDRBUFFSIZE DBshmseg->UDRcontrol.buff_size
|
|
|
|
/****************************************************************************
|
|
* This section contains all of the #defines and macros that are used by
|
|
* uvdrsrvd and uvdrupdd. (The UDR server daemon and the UDR update daemon).
|
|
***************************************************************************/
|
|
|
|
#define SYNCPUB 1
|
|
#define SYNCSUB 2
|
|
#define REPL 3
|
|
|
|
struct UDRlog_info {
|
|
char *filepath; /* the full path of the logfile */
|
|
long curpos; /* the current position in the logfile */
|
|
int fd, /* the logfile's file descriptor */
|
|
lognum; /* the log number of the current logfile */
|
|
};
|
|
|
|
#define UDRLGINFO struct UDRlog_info
|
|
|
|
struct updcache {
|
|
int datastore; /* The datastore num of the publisher */
|
|
int invalid; /* The specified datastore num is invalid */
|
|
DBFILE *fdesc; /* a file descriptor for the file */
|
|
char *filepath; /* the full path to the file */
|
|
STRING filename, /* the name of the subscribing file. */
|
|
account, /* the account the subscribing file is in */
|
|
filetype, /* the replication file type the file is. {F,Q,D,M,MD} */
|
|
mdname, /* the multi-level or distributed name */
|
|
mdtype; /* the multi-level or distributed replication type */
|
|
struct updcache *next, /* a pointer to the info for the next datastore */
|
|
*list; /* a pointer to other subs on the datastore */
|
|
};
|
|
|
|
#define UPDCACHE struct updcache
|
|
#define UPDCACHE_MAX 500
|
|
|
|
struct accntcache {
|
|
int invalid;
|
|
STRING AccountName;
|
|
char *AccountPath;
|
|
DBFILE *VOC;
|
|
struct accntcache *next;
|
|
};
|
|
|
|
#define ACNTCACHE struct accntcache
|
|
|
|
struct TXlist {
|
|
int rec_type,
|
|
datastore,
|
|
TXid;
|
|
STRING key,
|
|
rec;
|
|
struct TXlist *next,
|
|
*list,
|
|
*last;
|
|
};
|
|
|
|
#define TXLIST struct TXlist
|
|
|
|
/**********************************************************
|
|
* The following #define's are used by the Hot-Standby
|
|
* syncronization process in uvdrsrvd and uvdrupdd.
|
|
* the five digit 86000 range numbers correspond to messages in sys.mess.u
|
|
**********************************************************/
|
|
|
|
#define UDRSYNC_MAXBUCKETS 100 /* maximum number of buckets in the linked list */
|
|
#define UDRSYNC_BUCKETSIZE 100 /* maximum number of Key/CRC value pairs per bucket */
|
|
|
|
#define UDR_ERROR_NONE 0 /* no errors occured */
|
|
#define UDR_ERROR_PACKETTYPE 86231 /* Unexpected RPC packet type.*/
|
|
#define UDR_ERROR_HOTBAKSUB 86232 /* No Hot-Standby subscriptions found for '%s'. */
|
|
#define UDR_ERROR_FILELIST 86233 /* Failed to build a file list for '%s'. */
|
|
#define UDR_ERROR_PROCESSFILE 86234 /* Failed to access the requested Hot-Standby file. */
|
|
#define UDR_ERROR_SENDBUCKET 86235 /* Problem building or sending bucket of key/CRC pairs. */
|
|
#define UDR_ERROR_NOMOREBUCKETS 86236 /* No more buckets to send. */
|
|
#define UDR_ERROR_SENDUPDATE 86237 /* Failed to find requested data record. */
|
|
#define UDR_ERROR_RESETFILE 86238 /* Failed to reset file header of Hot-Standby file. */
|
|
#define UDR_ERROR_COMPETE 86239 /* Failed to finish cleaning up after last file syncronization. */
|
|
#define UDR_ERROR_RESETSYS 86240 /* Failed to reset field six of UV_UDRSYS. */
|
|
#define UDR_ERROR_NOTSYNCED 86241 /* All Hot-Standby files are NOT resyncronized yet. */
|
|
#define UDR_ERROR_SYSFAILBACK 86258 /* This system currently completely syncronized and failed back. */
|
|
#define UDR_FILEOPENFAILED 10 /* failed to open file */
|
|
#define UDR_RECEXISTS 11 /* the record already exists */
|
|
#define UDR_RECNOTEXISTS 12 /* the record does not exist */
|
|
#define UDR_WRITEFAILED 13 /* the write has failed */
|
|
#define UDR_READFAILED 14 /* the read has failed */
|
|
#define UDR_DELETEFAILED 15 /* the delete has failed */
|
|
#define UDR_MACHINENOTHOTBACKUP 16 /* the machine is not the hot standby machine */
|
|
|
|
/* structure used by the sync process to build a linked list of buckets */
|
|
struct bucket_list {
|
|
struct bucket_list *next;
|
|
STRING data;
|
|
};
|
|
|
|
#define BUCKETLIST struct bucket_list
|
|
|
|
/*******************************************
|
|
* These are the Defines for the Debugging
|
|
* Log Message Routines.
|
|
*******************************************/
|
|
|
|
/*
|
|
* Rather than include uvntlog.h in UDR_include.h we are redefining
|
|
* this here. That way we don't run into build problems with modules
|
|
* that include UDR_include.h before uvntlog.h has been created.
|
|
*/
|
|
|
|
/* to improve the standard feel across platforms I have removed all of the NT logging code
|
|
* so that now we get the debugging information in standard text log files like on the unix platforms.
|
|
* At some point in the future we should add support for logging only the critical messages to the NT log.
|
|
* this was done at the 9.5.1.1C release.
|
|
*/
|
|
/*
|
|
#define UV_INFO_MSG 0x600003E8L
|
|
|
|
#ifdef MSWIN
|
|
#define UDRLOG0(FLAG,OFILE,MSG) if (FLAG)\
|
|
{\
|
|
UVLogEvent(__FILE__, __LINE__, UV_INFO_MSG, 0, NULL, MSG);\
|
|
}
|
|
#else
|
|
*/
|
|
#define UDRLOG0(FLAG,OFILE,MSG) if (FLAG)\
|
|
{\
|
|
printdebug(OFILE);\
|
|
fprintf(OFILE,MSG);\
|
|
fprintf(OFILE, "\n");\
|
|
fflush(OFILE);\
|
|
}
|
|
/*
|
|
#endif
|
|
|
|
#ifdef MSWIN
|
|
#define UDRLOG1(FLAG,OFILE,MSG,ARG1) if (FLAG)\
|
|
{\
|
|
UVLogEvent(__FILE__, __LINE__, UV_INFO_MSG, 0, NULL, MSG, ARG1);\
|
|
}
|
|
#else
|
|
*/
|
|
#define UDRLOG1(FLAG,OFILE,MSG,ARG1) if (FLAG)\
|
|
{\
|
|
printdebug(OFILE);\
|
|
fprintf(OFILE,MSG,ARG1);\
|
|
fprintf(OFILE, "\n");\
|
|
fflush(OFILE);\
|
|
}
|
|
/*
|
|
#endif
|
|
|
|
#ifdef MSWIN
|
|
#define UDRLOG2(FLAG,OFILE,MSG,ARG1,ARG2) if (FLAG)\
|
|
{\
|
|
UVLogEvent(__FILE__, __LINE__, UV_INFO_MSG, 0, NULL, MSG, ARG1,ARG2);\
|
|
}
|
|
#else
|
|
*/
|
|
#define UDRLOG2(FLAG,OFILE,MSG,ARG1,ARG2) if (FLAG)\
|
|
{\
|
|
printdebug(OFILE);\
|
|
fprintf(OFILE,MSG,ARG1,ARG2);\
|
|
fprintf(OFILE, "\n");\
|
|
fflush(OFILE);\
|
|
}
|
|
/*
|
|
#endif
|
|
|
|
#ifdef MSWIN
|
|
#define UDRLOG3(FLAG,OFILE,MSG,ARG1,ARG2,ARG3) if (FLAG)\
|
|
{\
|
|
UVLogEvent(__FILE__, __LINE__,UV_INFO_MSG,0,NULL,MSG,ARG1,ARG2,ARG3);\
|
|
}
|
|
#else
|
|
*/
|
|
#define UDRLOG3(FLAG,OFILE,MSG,ARG1,ARG2,ARG3) if (FLAG)\
|
|
{\
|
|
printdebug(OFILE);\
|
|
fprintf(OFILE,MSG,ARG1,ARG2,ARG3);\
|
|
fprintf(OFILE, "\n");\
|
|
fflush(OFILE);\
|
|
}
|
|
/*
|
|
#endif
|
|
*/
|
|
|
|
/****************************************************************************
|
|
* UDRMAXMESSNO defines the maximum message number that can be passed to
|
|
* the server daemon. The values below that indicate which routine each
|
|
* message number calls.
|
|
****************************************************************************/
|
|
|
|
#define UDRMAXMESSNO 10
|
|
|
|
#define UDR_NOT_USED 0
|
|
#define UDR_SRV_DEBUG 1
|
|
#define UDR_SRV_GETPUBS 2
|
|
#define UDR_SRV_SETSUB 3
|
|
#define UDR_SRV_REMSUB 4
|
|
#define UDR_SRV_GETSUBS 5
|
|
#define UDR_SRV_INITREP 6
|
|
#define UDR_SRV_BEGINREP 7
|
|
#define UDR_SRV_SYNCPUB 8
|
|
#define UDR_SRV_ADDHOTBACKUP 9
|
|
#define UDR_SRV_REMHOTBACKUP 10
|
|
|
|
#define UDR_SRV_REPPACKET 300
|
|
#define UDR_SRV_ENDREP 301
|
|
#define UDR_SRV_STOPREP 302
|
|
|
|
#define UDR_SYNC 400
|
|
#define UDR_SYNC_PROCESSFILE 401
|
|
#define UDR_SYNC_SENDBUCKET 402
|
|
#define UDR_SYNC_SENDUPDATE 403
|
|
#define UDR_SYNC_RESETFILE 404
|
|
#define UDR_SYNC_COMPLETE 405
|
|
|
|
#endif /* udr_include.h */
|