summaryrefslogtreecommitdiff
path: root/db2/log
diff options
context:
space:
mode:
Diffstat (limited to 'db2/log')
-rw-r--r--db2/log/log.c4
-rw-r--r--db2/log/log_archive.c10
-rw-r--r--db2/log/log_auto.c2
-rw-r--r--db2/log/log_get.c33
-rw-r--r--db2/log/log_put.c106
5 files changed, 77 insertions, 78 deletions
diff --git a/db2/log/log.c b/db2/log/log.c
index 17681f8e0f..a9bf7a95ab 100644
--- a/db2/log/log.c
+++ b/db2/log/log.c
@@ -7,7 +7,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)log.c 10.33 (Sleepycat) 11/2/97";
+static const char sccsid[] = "@(#)log.c 10.34 (Sleepycat) 11/28/97";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -91,7 +91,7 @@ log_open(path, flags, mode, dbenv, lpp)
retry_cnt = newregion = 0;
retry: if (LF_ISSET(DB_CREATE)) {
ret = __db_rcreate(dbenv, DB_APP_LOG, path,
- DB_DEFAULT_LOG_FILE, mode, len, &fd, &dblp->maddr);
+ DB_DEFAULT_LOG_FILE, mode, len, 0, &fd, &dblp->maddr);
if (ret == 0) {
/* Put the LOG structure first in the region. */
lp = dblp->maddr;
diff --git a/db2/log/log_archive.c b/db2/log/log_archive.c
index 140ea31fd1..0248e2815c 100644
--- a/db2/log/log_archive.c
+++ b/db2/log/log_archive.c
@@ -8,7 +8,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)log_archive.c 10.28 (Sleepycat) 10/28/97";
+static const char sccsid[] = "@(#)log_archive.c 10.29 (Sleepycat) 11/12/97";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -360,9 +360,9 @@ __absname(pref, name, newnamep)
* If the user has their own malloc routine, use it.
*/
static int
-__usermem(listp, func)
+__usermem(listp, cmpfunc)
char ***listp;
- void *(*func) __P((size_t));
+ void *(*cmpfunc) __P((size_t));
{
size_t len;
char **array, **arrayp, **orig, *strp;
@@ -378,10 +378,10 @@ __usermem(listp, func)
* XXX
* Don't simplify this expression, SunOS compilers don't like it.
*/
- if (func == NULL)
+ if (cmpfunc == NULL)
array = (char **)__db_malloc(len);
else
- array = (char **)func(len);
+ array = (char **)cmpfunc(len);
if (array == NULL)
return (ENOMEM);
strp = (char *)(array + (orig - *listp) + 1);
diff --git a/db2/log/log_auto.c b/db2/log/log_auto.c
index d5dbfe1f5f..61626b090e 100644
--- a/db2/log/log_auto.c
+++ b/db2/log/log_auto.c
@@ -102,7 +102,6 @@ int __log_register_log(logp, txnid, ret_lsnp, flags,
* PUBLIC: int __log_register_print
* PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
*/
-
int
__log_register_print(notused1, dbtp, lsnp, notused3, notused4)
DB_LOG *notused1;
@@ -250,7 +249,6 @@ int __log_unregister_log(logp, txnid, ret_lsnp, flags,
* PUBLIC: int __log_unregister_print
* PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
*/
-
int
__log_unregister_print(notused1, dbtp, lsnp, notused3, notused4)
DB_LOG *notused1;
diff --git a/db2/log/log_get.c b/db2/log/log_get.c
index ed35d57f82..2d1512c6b9 100644
--- a/db2/log/log_get.c
+++ b/db2/log/log_get.c
@@ -7,7 +7,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)log_get.c 10.21 (Sleepycat) 10/25/97";
+static const char sccsid[] = "@(#)log_get.c 10.22 (Sleepycat) 11/22/97";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -44,24 +44,21 @@ log_get(dblp, alsn, dbt, flags)
/* Validate arguments. */
#define OKFLAGS (DB_CHECKPOINT | \
DB_CURRENT | DB_FIRST | DB_LAST | DB_NEXT | DB_PREV | DB_SET)
- if (flags != 0) {
- if ((ret =
- __db_fchk(dblp->dbenv, "log_get", flags, OKFLAGS)) != 0)
- return (ret);
- switch (flags) {
- case DB_CHECKPOINT:
- case DB_CURRENT:
- case DB_FIRST:
- case DB_LAST:
- case DB_NEXT:
- case DB_PREV:
- case DB_SET:
- case 0:
- break;
- default:
- return (__db_ferr(dblp->dbenv, "log_get", 1));
- }
+ if ((ret = __db_fchk(dblp->dbenv, "log_get", flags, OKFLAGS)) != 0)
+ return (ret);
+ switch (flags) {
+ case DB_CHECKPOINT:
+ case DB_CURRENT:
+ case DB_FIRST:
+ case DB_LAST:
+ case DB_NEXT:
+ case DB_PREV:
+ case DB_SET:
+ break;
+ default:
+ return (__db_ferr(dblp->dbenv, "log_get", 1));
}
+
if (F_ISSET(dblp, DB_AM_THREAD)) {
if (LF_ISSET(DB_NEXT | DB_PREV | DB_CURRENT))
return (__db_ferr(dblp->dbenv, "log_get", 1));
diff --git a/db2/log/log_put.c b/db2/log/log_put.c
index 92d9563301..42fec88a7d 100644
--- a/db2/log/log_put.c
+++ b/db2/log/log_put.c
@@ -7,7 +7,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)log_put.c 10.20 (Sleepycat) 11/2/97";
+static const char sccsid[] = "@(#)log_put.c 10.22 (Sleepycat) 11/12/97";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -28,10 +28,10 @@ static const char sccsid[] = "@(#)log_put.c 10.20 (Sleepycat) 11/2/97";
#include "hash.h"
#include "common_ext.h"
-static int __log_fill __P((DB_LOG *, void *, u_int32_t));
+static int __log_fill __P((DB_LOG *, DB_LSN *, void *, u_int32_t));
static int __log_flush __P((DB_LOG *, const DB_LSN *));
static int __log_newfd __P((DB_LOG *));
-static int __log_putr __P((DB_LOG *, const DBT *, u_int32_t));
+static int __log_putr __P((DB_LOG *, DB_LSN *, const DBT *, u_int32_t));
static int __log_write __P((DB_LOG *, void *, u_int32_t));
/*
@@ -117,12 +117,13 @@ __log_put(dblp, lsn, dbt, flags)
/* Reset the file write offset. */
lp->w_off = 0;
-
- /* Reset the first-unwritten LSN for the buffer. */
- lp->uw_lsn = lp->lsn;
} else
lastoff = 0;
+ /* Initialize the LSN information returned to the user. */
+ lsn->file = lp->lsn.file;
+ lsn->offset = lp->lsn.offset;
+
/*
* Insert persistent information as the first record in every file.
* Note that the previous length is wrong for the very first record
@@ -131,17 +132,17 @@ __log_put(dblp, lsn, dbt, flags)
if (lp->lsn.offset == 0) {
t.data = &lp->persist;
t.size = sizeof(LOGP);
- if ((ret = __log_putr(dblp,
+ if ((ret = __log_putr(dblp, lsn,
&t, lastoff == 0 ? 0 : lastoff - lp->len)) != 0)
return (ret);
- }
- /* Initialize the LSN information returned to the user. */
- lsn->file = lp->lsn.file;
- lsn->offset = lp->lsn.offset;
+ /* Update the LSN information returned to the user. */
+ lsn->file = lp->lsn.file;
+ lsn->offset = lp->lsn.offset;
+ }
- /* Put out the user's record. */
- if ((ret = __log_putr(dblp, dbt, lp->lsn.offset - lp->len)) != 0)
+ /* Write the application's log record. */
+ if ((ret = __log_putr(dblp, lsn, dbt, lp->lsn.offset - lp->len)) != 0)
return (ret);
/*
@@ -184,19 +185,6 @@ __log_put(dblp, lsn, dbt, flags)
(void)time(&lp->chkpt);
lp->stat.st_wc_bytes = lp->stat.st_wc_mbytes = 0;
}
-
- /*
- * When an application calls the log_flush routine, we need to figure
- * out if the current buffer needs to be flushed. The problem is that
- * if a record spans buffers, it's possible for the record continued
- * in the current buffer to have begun in a previous buffer. Each time
- * we write a buffer, we update the first-unwritten LSN to point to the
- * first LSN after that written buffer. If we have a spanning record,
- * correct that value to be the LSN that started it all, here.
- */
- if (lsn->offset < lp->w_off && lsn->offset + lp->len > lp->w_off)
- lp->uw_lsn = *lsn;
-
return (0);
}
@@ -205,8 +193,9 @@ __log_put(dblp, lsn, dbt, flags)
* Actually put a record into the log.
*/
static int
-__log_putr(dblp, dbt, prev)
+__log_putr(dblp, lsn, dbt, prev)
DB_LOG *dblp;
+ DB_LSN *lsn;
const DBT *dbt;
u_int32_t prev;
{
@@ -225,15 +214,15 @@ __log_putr(dblp, dbt, prev)
hdr.len = sizeof(HDR) + dbt->size;
hdr.cksum = __ham_func4(dbt->data, dbt->size);
- if ((ret = __log_fill(dblp, &hdr, sizeof(HDR))) != 0)
+ if ((ret = __log_fill(dblp, lsn, &hdr, sizeof(HDR))) != 0)
return (ret);
+ lp->len = sizeof(HDR);
lp->lsn.offset += sizeof(HDR);
- if ((ret = __log_fill(dblp, dbt->data, dbt->size)) != 0)
+ if ((ret = __log_fill(dblp, lsn, dbt->data, dbt->size)) != 0)
return (ret);
+ lp->len += dbt->size;
lp->lsn.offset += dbt->size;
-
- lp->len = sizeof(HDR) + dbt->size;
return (0);
}
@@ -266,7 +255,7 @@ __log_flush(dblp, lsn)
{
DB_LSN t_lsn;
LOG *lp;
- int ret;
+ int current, ret;
ret = 0;
lp = dblp->lp;
@@ -292,23 +281,27 @@ __log_flush(dblp, lsn)
/*
* If the LSN is less than the last-sync'd LSN, we're done. Note,
* the last-sync LSN saved in s_lsn is the LSN of the first byte
- * that has not yet been written to disk, so the test is <, not <=.
+ * we absolutely know has been written to disk, so the test is <=.
*/
if (lsn->file < lp->s_lsn.file ||
- (lsn->file == lp->s_lsn.file && lsn->offset < lp->s_lsn.offset))
+ (lsn->file == lp->s_lsn.file && lsn->offset <= lp->s_lsn.offset))
return (0);
/*
* We may need to write the current buffer. We have to write the
* current buffer if the flush LSN is greater than or equal to the
- * first-unwritten LSN (uw_lsn). If we write the buffer, then we
- * update the first-unwritten LSN.
+ * buffer's starting LSN.
*/
+ current = 0;
if (lp->b_off != 0 &&
- lsn->file >= lp->uw_lsn.file && lsn->offset >= lp->uw_lsn.offset)
+ lsn->file >= lp->f_lsn.file && lsn->offset >= lp->f_lsn.offset) {
if ((ret = __log_write(dblp, lp->buf, lp->b_off)) != 0)
return (ret);
+ lp->b_off = 0;
+ current = 1;
+ }
+
/*
* It's possible that this thread may never have written to this log
* file. Acquire a file descriptor if we don't already have one.
@@ -323,10 +316,14 @@ __log_flush(dblp, lsn)
++lp->stat.st_scount;
/*
- * Set the last-synced LSN, the first LSN after the last record
- * that we know is on disk.
+ * Set the last-synced LSN, using the LSN of the current buffer. If
+ * the current buffer was flushed, we know the LSN of the first byte
+ * of the buffer is on disk, otherwise, we only know that the LSN of
+ * the record before the one beginning the current buffer is on disk.
*/
- lp->s_lsn = lp->uw_lsn;
+ lp->s_lsn = lp->f_lsn;
+ if (!current)
+ --lp->s_lsn.offset;
return (0);
}
@@ -336,8 +333,9 @@ __log_flush(dblp, lsn)
* Write information into the log.
*/
static int
-__log_fill(dblp, addr, len)
+__log_fill(dblp, lsn, addr, len)
DB_LOG *dblp;
+ DB_LSN *lsn;
void *addr;
u_int32_t len;
{
@@ -349,6 +347,15 @@ __log_fill(dblp, addr, len)
/* Copy out the data. */
for (lp = dblp->lp; len > 0;) {
/*
+ * If we're beginning a new buffer, note the user LSN to which
+ * the first byte of the buffer belongs. We have to know this
+ * when flushing the buffer so that we know if the in-memory
+ * buffer needs to be flushed.
+ */
+ if (lp->b_off == 0)
+ lp->f_lsn = *lsn;
+
+ /*
* If we're on a buffer boundary and the data is big enough,
* copy as many records as we can directly from the data.
*/
@@ -371,9 +378,12 @@ __log_fill(dblp, addr, len)
lp->b_off += nw;
/* If we fill the buffer, flush it. */
- if (lp->b_off == sizeof(lp->buf) &&
- (ret = __log_write(dblp, lp->buf, sizeof(lp->buf))) != 0)
- return (ret);
+ if (lp->b_off == sizeof(lp->buf)) {
+ if ((ret =
+ __log_write(dblp, lp->buf, sizeof(lp->buf))) != 0)
+ return (ret);
+ lp->b_off = 0;
+ }
}
return (0);
}
@@ -412,14 +422,8 @@ __log_write(dblp, addr, len)
if (nw != (int32_t)len)
return (EIO);
- /*
- * Reset the buffer offset, update the seek offset, and update the
- * first-unwritten LSN.
- */
- lp->b_off = 0;
+ /* Reset the buffer offset and update the seek offset. */
lp->w_off += len;
- lp->uw_lsn.file = lp->lsn.file;
- lp->uw_lsn.offset = lp->w_off;
/* Update written statistics. */
if ((lp->stat.st_w_bytes += len) >= MEGABYTE) {