Thu Aug 23 11:04:37 PDT 2007
- Previous message: [Slony1-commit] slony1-engine/doc/adminguide filelist.sgml raceconditions.sgml slony.sgml
- Next message: [Slony1-commit] slony1-engine/src/slon remote_worker.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /home/cvsd/slony1/slony1-engine/src/slon
In directory main.slony.info:/tmp/cvs-serv29999
Modified Files:
Tag: REL_1_2_STABLE
remote_worker.c slon.h
Log Message:
Changing the file name of the archive logs to be based on the
internal archive tracking counter. That way a mechanism that applies
the archives to the offline replica can easily figure out which file
needs to be applied next by looking at sl_archive_tracking.
Jan
Index: remote_worker.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/remote_worker.c,v
retrieving revision 1.124.2.20
retrieving revision 1.124.2.21
diff -C2 -d -r1.124.2.20 -r1.124.2.21
*** remote_worker.c 20 Aug 2007 17:02:28 -0000 1.124.2.20
--- remote_worker.c 23 Aug 2007 18:04:35 -0000 1.124.2.21
***************
*** 256,260 ****
! static int archive_open(SlonNode *node, char *seqbuf);
static int archive_close(SlonNode *node);
static void archive_terminate(SlonNode *node);
--- 256,261 ----
! static int archive_open(SlonNode *node, char *seqbuf,
! PGconn *dbconn);
static int archive_close(SlonNode *node);
static void archive_terminate(SlonNode *node);
***************
*** 262,267 ****
static int archive_append_str(SlonNode *node, const char *s);
static int archive_append_data(SlonNode *node, const char *s, int len);
- static int archive_tracking(SlonNode *node, const char *namespace,
- PGconn *local_dbconn);
--- 263,266 ----
***************
*** 681,689 ****
if (archive_dir)
{
- ProviderInfo *pinfo;
- ProviderSet *pset;
char buf[256];
! if (archive_open(node, seqbuf) < 0)
slon_retry();
sprintf(buf, "-- %s", event->ev_type);
--- 680,686 ----
if (archive_dir)
{
char buf[256];
! if (archive_open(node, seqbuf, local_dbconn) < 0)
slon_retry();
sprintf(buf, "-- %s", event->ev_type);
***************
*** 691,698 ****
slon_retry();
- if (archive_tracking(node, rtcfg_namespace,
- local_dbconn) < 0)
- slon_retry();
-
/*
* Leave the archive open for event specific actions.
--- 688,691 ----
***************
*** 3863,3867 ****
if (archive_dir)
{
! rc = archive_open(node, seqbuf);
if (rc < 0)
{
--- 3856,3860 ----
if (archive_dir)
{
! rc = archive_open(node, seqbuf, local_dbconn);
if (rc < 0)
{
***************
*** 4222,4237 ****
/*
- * Add a call to the archive tracking function to the archive log.
- * This function ensures that all archive log files are applied in
- * the right order.
- */
- if (archive_dir)
- {
- rc = archive_tracking(node, rtcfg_namespace, local_dbconn);
- if (rc < 0)
- slon_retry();
- }
-
- /*
* We didn't add anything good in the provider clause. That shouldn't
* be!
--- 4215,4218 ----
***************
*** 5398,5404 ****
* - Second, you generate the header using generate_archive_header()
*
- * - Third, you need to set up the sync tracking function in the log
- * using logarchive_tracking()
- *
* ======== Here Ends The Header of the Log Shipping Archive ========
*
--- 5379,5382 ----
***************
*** 5424,5429 ****
*/
static int
! archive_open(SlonNode *node, char *seqbuf)
{
int i;
int rc;
--- 5402,5409 ----
*/
static int
! archive_open(SlonNode *node, char *seqbuf, PGconn *dbconn)
{
+ SlonDString query;
+ PGresult *res;
int i;
int rc;
***************
*** 5436,5440 ****
node->archive_name = malloc(SLON_MAX_PATH);
node->archive_temp = malloc(SLON_MAX_PATH);
! if (node->archive_name == NULL || node->archive_temp == NULL)
{
slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
--- 5416,5423 ----
node->archive_name = malloc(SLON_MAX_PATH);
node->archive_temp = malloc(SLON_MAX_PATH);
! node->archive_counter = malloc(64);
! node->archive_timestamp = malloc(256);
! if (node->archive_name == NULL || node->archive_temp == NULL ||
! node->archive_counter == NULL || node->archive_timestamp == NULL)
{
slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
***************
*** 5453,5461 ****
}
sprintf(node->archive_name, "%s/slony1_log_%d_", archive_dir,
node->no_id);
! for (i = strlen(seqbuf); i < 20; i++)
strcat(node->archive_name, "0");
! strcat(node->archive_name, seqbuf);
strcat(node->archive_name, ".sql");
strcpy(node->archive_temp, node->archive_name);
--- 5436,5484 ----
}
+ dstring_init(&query);
+ slon_mkquery(&query,
+ "update %s.sl_archive_counter "
+ " set ac_num = ac_num + 1, "
+ " ac_timestamp = CURRENT_TIMESTAMP; "
+ "select ac_num, ac_timestamp from %s.sl_archive_counter; ",
+ rtcfg_namespace, rtcfg_namespace);
+ res = PQexec(dbconn, dstring_data(&query));
+ if ((rc = PQresultStatus(res)) != PGRES_TUPLES_OK)
+ {
+ slon_log(SLON_ERROR,
+ "remoteWorkerThread_%d: \"%s\" %s %s\n",
+ node->no_id, dstring_data(&query),
+ PQresStatus(rc),
+ PQresultErrorMessage(res));
+ PQclear(res);
+ dstring_free(&query);
+ return -1;
+ }
+ if ((rc = PQntuples(res)) != 1)
+ {
+ slon_log(SLON_ERROR,
+ "remoteWorkerThread_%d: expected 1 row in sl_archive_counter - found %d",
+ node->no_id, rc);
+ PQclear(res);
+ dstring_free(&query);
+ return -1;
+ }
+ strcpy(node->archive_counter, PQgetvalue(res, 0, 0));
+ strcpy(node->archive_timestamp, PQgetvalue(res, 0, 1));
+
+ PQclear(res);
+ dstring_free(&query);
+ if (rc < 0)
+ {
+ slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+ "Cannot write to archive file %s - %s\n",
+ node->no_id, node->archive_temp, strerror(errno));
+ return -1;
+ }
sprintf(node->archive_name, "%s/slony1_log_%d_", archive_dir,
node->no_id);
! for (i = strlen(node->archive_counter); i < 20; i++)
strcat(node->archive_name, "0");
! strcat(node->archive_name, node->archive_counter);
strcat(node->archive_name, ".sql");
strcpy(node->archive_temp, node->archive_name);
***************
*** 5471,5478 ****
rc = fprintf(node->archive_fp,
! "-- Slony-I log shipping archive\n"
! "-- Node %d, Event %s\n"
! "start transaction;\n",
! node->no_id, seqbuf);
if (rc < 0)
{
--- 5494,5517 ----
rc = fprintf(node->archive_fp,
! "------------------------------------------------------------------\n"
! "-- Slony-I log shipping archive\n"
! "-- Node %d, Event %s\n"
! "------------------------------------------------------------------\n"
! "start transaction;\n",
! node->no_id, seqbuf);
! if (rc < 0)
! {
! slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
! "Cannot write to archive file %s - %s\n",
! node->no_id, node->archive_temp, strerror(errno));
! return -1;
! }
! rc = fprintf(node->archive_fp,
! "select %s.archiveTracking_offline('%s', '%s');\n"
! "-- end of log archiving header\n"
! "------------------------------------------------------------------\n"
! "-- start of Slony-I data\n"
! "------------------------------------------------------------------\n",
! rtcfg_namespace, node->archive_counter, node->archive_timestamp);
if (rc < 0)
{
***************
*** 5560,5637 ****
/* ----------
- * archive_tracking
- * ----------
- */
- static int
- archive_tracking(SlonNode *node, const char *namespace,
- PGconn *local_dbconn)
- {
- SlonDString query;
- PGresult *res;
- int rc;
-
- if (!archive_dir)
- return 0;
-
- dstring_init(&query);
- slon_mkquery(&query,
- "update %s.sl_archive_counter "
- " set ac_num = ac_num + 1, "
- " ac_timestamp = CURRENT_TIMESTAMP; "
- "select ac_num, ac_timestamp from %s.sl_archive_counter; ",
- namespace, namespace);
- res = PQexec(local_dbconn, dstring_data(&query));
- if ((rc = PQresultStatus(res)) != PGRES_TUPLES_OK)
- {
- slon_log(SLON_ERROR,
- "remoteWorkerThread_%d: \"%s\" %s %s\n",
- node->no_id, dstring_data(&query),
- PQresStatus(rc),
- PQresultErrorMessage(res));
- PQclear(res);
- dstring_free(&query);
- return -1;
- }
- if ((rc = PQntuples(res)) != 1)
- {
- slon_log(SLON_ERROR,
- "remoteWorkerThread_%d: expected 1 row in sl_archive_counter - found %d",
- node->no_id, rc);
- PQclear(res);
- dstring_free(&query);
- return -1;
- }
-
- if (node->archive_fp == NULL)
- {
- slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
- "Cannot write to archive file %s - not open\n",
- node->no_id, node->archive_temp);
- PQclear(res);
- dstring_free(&query);
- return -1;
- }
-
- rc = fprintf(node->archive_fp,
- "\nselect %s.archiveTracking_offline('%s', '%s');\n"
- "-- end of log archiving header\n"
- "------------------------------------------------------------------\n"
- "-- start of Slony-I data\n"
- "------------------------------------------------------------------\n",
- namespace, PQgetvalue(res, 0, 0), PQgetvalue(res, 0, 1));
- PQclear(res);
- dstring_free(&query);
- if (rc < 0)
- {
- slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
- "Cannot write to archive file %s - %s\n",
- node->no_id, node->archive_temp, strerror(errno));
- return -1;
- }
-
- return 0;
- }
-
- /* ----------
* archive_append_ds
* ----------
--- 5599,5602 ----
Index: slon.h
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/slon.h,v
retrieving revision 1.59.2.3
retrieving revision 1.59.2.4
diff -C2 -d -r1.59.2.3 -r1.59.2.4
*** slon.h 27 Oct 2006 20:09:56 -0000 1.59.2.3
--- slon.h 23 Aug 2007 18:04:35 -0000 1.59.2.4
***************
*** 108,111 ****
--- 108,113 ----
char *archive_name;
char *archive_temp;
+ char *archive_counter;
+ char *archive_timestamp;
FILE *archive_fp;
- Previous message: [Slony1-commit] slony1-engine/doc/adminguide filelist.sgml raceconditions.sgml slony.sgml
- Next message: [Slony1-commit] slony1-engine/src/slon remote_worker.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list