1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Adjust WAL code so that checkpoints truncate the xlog at the previous

checkpoint's redo pointer, not its undo pointer, per discussion in
pghackers a few days ago.  No point in hanging onto undo information
until we have the ability to do something with it --- and this solves
a rather large problem with log space for long-running transactions.
Also, change all calls of write() to detect the case where write
returned a count less than requested, but failed to set errno.
Presume that this situation indicates ENOSPC, and give the appropriate
error message, rather than a random message associated with the previous
value of errno.
This commit is contained in:
Tom Lane
2001-06-06 17:07:46 +00:00
parent ce370eec35
commit 1173344e74
6 changed files with 76 additions and 20 deletions

View File

@ -155,9 +155,8 @@ int dbf_write_head(dbhead *dbh) {
put_short(head.dbh_hlen, dbh->db_hlen);
put_short(head.dbh_rlen, dbh->db_rlen);
if (write(dbh->db_fd, &head, sizeof(dbf_header)) == -1 ) {
if (write(dbh->db_fd, &head, sizeof(dbf_header)) != sizeof(dbf_header))
return DBF_ERROR;
}
return 0;
}
@ -180,14 +179,12 @@ int dbf_put_fields(dbhead *dbh) {
field.dbf_flen = dbh->db_fields[t].db_flen;
field.dbf_dec = dbh->db_fields[t].db_dec;
if (write(dbh->db_fd, &field, sizeof(dbf_field)) == -1) {
if (write(dbh->db_fd, &field, sizeof(dbf_field)) != sizeof(dbf_field))
return DBF_ERROR;
}
}
if (write(dbh->db_fd, &end, 1) == -1) {
if (write(dbh->db_fd, &end, 1) != 1)
return DBF_ERROR;
}
return 0;
}
@ -457,15 +454,13 @@ int dbf_put_record(dbhead *dbh, field *rec, u_long where) {
idx += rec[t].db_flen;
}
if (write(dbh->db_fd, data, dbh->db_rlen) == -1) {
if (write(dbh->db_fd, data, dbh->db_rlen) != dbh->db_rlen)
return DBF_ERROR;
}
/* There's a 0x1A at the end of a dbf-file */
if (where == dbh->db_records) {
if (write(dbh->db_fd, &end, 1) == -1) {
if (write(dbh->db_fd, &end, 1) != 1)
return DBF_ERROR;
}
}
dbh->db_offset += dbh->db_rlen;

View File

@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.4 2001/05/30 14:18:18 momjian Exp $
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.5 2001/06/06 17:07:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -772,8 +772,12 @@ RewriteControlFile(void)
exit(1);
}
errno = 0;
if (write(fd, buffer, BLCKSZ) != BLCKSZ)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
errno = ENOSPC;
perror("RewriteControlFile failed to write pg_control file");
exit(1);
}
@ -884,8 +888,12 @@ WriteEmptyXLOG(void)
exit(1);
}
errno = 0;
if (write(fd, buffer, BLCKSZ) != BLCKSZ)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
errno = ENOSPC;
perror("WriteEmptyXLOG: failed to write xlog file");
exit(1);
}
@ -894,8 +902,11 @@ WriteEmptyXLOG(void)
memset(buffer, 0, BLCKSZ);
for (nbytes = BLCKSZ; nbytes < XLogSegSize; nbytes += BLCKSZ)
{
errno = 0;
if (write(fd, buffer, BLCKSZ) != BLCKSZ)
{
if (errno == 0)
errno = ENOSPC;
perror("WriteEmptyXLOG: failed to write xlog file");
exit(1);
}