/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#endif
#include "db_int.h"
#include "shqueue.h"
#include "db_page.h"
#include "log.h"
#include "hash.h"
#include "clib_ext.h"
#include "common_ext.h"
/*
* log_put --
* Write a log record.
*/
int
{
int ret;
/* Validate arguments. */
return (ret);
}
/*
* __log_put --
* Write a log record; internal version.
*
* PUBLIC: int __log_put __P((DB_LOG *, DB_LSN *, const DBT *, u_int32_t));
*/
int
{
int ret;
/*
* If the application just wants to know where we are, fill in
* the information. Currently used by the transaction manager
* to avoid writing TXN_begin records.
*/
return (0);
}
/* If this information won't fit in the file, swap files. */
if (sizeof(HDR) +
"log_put: record larger than maximum file size");
return (EINVAL);
}
/* Flush the log. */
return (ret);
/*
* Save the last known offset from the previous file, we'll
* need it to initialize the persistent header information.
*/
/* Point the current LSN to the new file. */
/* Reset the file write offset. */
} else
lastoff = 0;
/* Initialize the LSN information returned to the user. */
/*
* Insert persistent information as the first record in every file.
* Note that the previous length is wrong for the very first record
* of the log, but that's okay, we check for it during retrieval.
*/
return (ret);
/* Update the LSN information returned to the user. */
}
/* Write the application's log record. */
return (ret);
/*
* On a checkpoint, we:
* Put out the checkpoint record (above).
* Save the LSN of the checkpoint in the shared region.
* Append the set of file name information into the log.
*/
if (flags == DB_CHECKPOINT) {
continue;
memset(&t, 0, sizeof(t));
!= 0)
return (ret);
}
}
/*
* On a checkpoint or when flush is requested, we:
* Flush the current buffer contents to disk.
* Sync the log to disk.
*/
return (ret);
/*
* On a checkpoint, we:
* Save the time the checkpoint was written.
* Reset the bytes written since the last checkpoint.
*/
if (flags == DB_CHECKPOINT) {
}
return (0);
}
/*
* __log_putr --
* Actually put a record into the log.
*/
static int
{
int ret;
/*
* Initialize the header. If we just switched files, lsn.offset will
* be 0, and what we really want is the offset of the previous record
* in the previous file. Fortunately, prev holds the value we want.
*/
return (ret);
return (ret);
return (0);
}
/*
* log_flush --
* Write all records less than or equal to the specified LSN.
*/
int
{
int ret;
return (ret);
}
/*
* __log_flush --
* Write all records less than or equal to the specified LSN; internal
* version.
*/
static int
{
ret = 0;
/*
* If no LSN specified, flush the entire log by setting the flush LSN
* to the last LSN written in the log. Otherwise, check that the LSN
* isn't a non-existent record for the log.
*/
} else
"log_flush: LSN past current end-of-log");
return (EINVAL);
}
/*
* 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
* we absolutely know has been written to disk, so the test is <=.
*/
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
* buffer's starting LSN.
*/
current = 0;
return (ret);
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.
*/
return (ret);
/* Sync all writes to disk. */
return (ret);
}
/*
* 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.
*
* XXX
* Check to make sure that the saved lsn isn't 0 before we go making
* this change. If DB_CHECKPOINT was called before we actually wrote
* something, you can end up here without ever having written anything
* to a log file, and decrementing either s_lsn.file or s_lsn.offset
* will cause much sadness later on.
*/
} else
return (0);
}
/*
* __log_fill --
* Write information into the log.
*/
static int
void *addr;
{
int ret;
/* Copy out the data. */
/*
* 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 we're on a buffer boundary and the data is big enough,
* copy as many records as we can directly from the data.
*/
return (ret);
continue;
}
/* Figure out how many bytes we can copy this time. */
/* If we fill the buffer, flush it. */
if ((ret =
return (ret);
}
}
return (0);
}
/*
* __log_write --
* Write the log buffer to disk.
*/
static int
void *addr;
{
int ret;
/*
* If we haven't opened the log file yet or the current one
* has changed, acquire a new log file.
*/
return (ret);
/*
* Seek to the offset in the file (someone may have written it
* since we last did).
*/
return (ret);
}
return (EIO);
/* Reset the buffer offset and update the seek offset. */
/* Update written statistics. */
}
}
return (0);
}
/*
* log_file --
* Map a DB_LSN to a file name.
*/
int
char *namep;
{
int ret;
char *name;
if (ret != 0)
return (ret);
/* Check to make sure there's enough room and copy the name. */
*namep = '\0';
return (ENOMEM);
}
return (0);
}
/*
* __log_newfd --
* Acquire a file descriptor for the current log file.
*/
static int
{
int ret;
char *name;
/* Close any previous file descriptor. */
}
/* Get the path of the new file and open it. */
return (ret);
}
/*
* __log_name --
* Return the log name for a particular file, and optionally open it.
*
* PUBLIC: int __log_name __P((DB_LOG *, u_int32_t, char **, int *, u_int32_t));
*/
int
char **namep;
int *fdp;
{
int ret;
char *oname;
/*
* !!!
* The semantics of this routine are bizarre.
*
* The reason for all of this is that we need a place where we can
* intercept requests for log files, and, if appropriate, check for
* both the old-style and new-style log file names. The trick is
* that all callers of this routine that are opening the log file
* read-only want to use an old-style file name if they can't find
* a match using a new-style name. The only down-side is that some
* callers may check for the old-style when they really don't need
* to, but that shouldn't mess up anything, and we only check for
* the old-style name when we've already failed to find a new-style
* one.
*
* Create a new-style file name, and if we're not going to open the
* file, return regardless.
*/
return (ret);
/* Open the new-style file -- if we succeed, we're done. */
return (0);
/*
* The open failed... if the DB_RDONLY flag isn't set, we're done,
* the caller isn't interested in old-style files.
*/
return (ret);
/* Create an old-style file name. */
goto err;
/*
* Open the old-style file -- if we succeed, we're done. Free the
* space allocated for the new-style name and return the old-style
* name to the caller.
*/
return (0);
}
/*
* Couldn't find either style of name -- return the new-style name
* for the caller's error message. If it's an old-style name that's
* actually missing we're going to confuse the user with the error
* message, but that implies that not only were we looking for an
* old-style name, but we expected it to exist and we weren't just
* looking for any log file. That's not a likely error.
*/
return (ret);
}