log.c revision 1
1N/A * See the file LICENSE for redistribution information. 1N/A * Copyright (c) 1996, 1997, 1998 1N/A * Sleepycat Software. All rights reserved. 1N/A#
endif /* not lint */ 1N/A /* Validate arguments. */ 1N/A /* Create and initialize the DB_LOG structure. */ 1N/A * The log region isn't fixed size because we store the registered 1N/A * file names there. Make it fairly large so that we don't have to 1N/A /* Map in the region. */ 1N/A * The LOG structure is first in the region, the rest of the region 1N/A /* Initialize a created region. */ 1N/A /* Initialize the LOG structure. */ 1N/A /* Initialize LOG LSNs. */ 1N/A /* Initialize thread information, mutex. */ 1N/A * If doing recovery, try and recover any previous log files before 1N/A * releasing the lock. 1N/A * PUBLIC: void __log_panic __P((DB_ENV *)); 1N/A * Find a log file. If none exist, we simply return, leaving 1N/A * everything initialized to a new log. 1N/A * We have the last useful log file and we've loaded any persistent 1N/A * information. Pretend that the log is larger than it can possibly 1N/A * be, and read the last file, looking for the last checkpoint and 1N/A /* Set the cursor. Shouldn't fail, leave error messages on. */ 1N/A * Read to the end of the file, saving checkpoints. This will fail 1N/A * at some point, so turn off error messages. 1N/A * We now know where the end of the log is. Set the first LSN that 1N/A * we want to return to an application and the LSN of the last known 1N/A /* Set up the current buffer information, too. */ 1N/A * It's possible that we didn't find a checkpoint because there wasn't 1N/A * one in the last log file. Start searching. 1N/A /* Set the cursor. Shouldn't fail, leave error messages on. */ 1N/A * Read to the end of the file, saving checkpoints. Shouldn't 1N/A * fail, leave error messages on. 1N/A * Reset the cursor lsn to the beginning of the log, so that an 1N/A * initial call to DB_NEXT does the right thing. 1N/A /* If we never find a checkpoint, that's okay, just 0 it out. */ 1N/A * The test suite explicitly looks for this string -- don't change 1N/A * it here unless you also change it there. 1N/A "Finding last valid log LSN: file: %lu offset %lu",
1N/A * Try to find a log file. If find_first is set, valp will contain 1N/A * the number of the first log file, else it will contain the number of 1N/A * the last log file. 1N/A * PUBLIC: int __log_find __P((DB_LOG *, int, int *)); 1N/A /* Find the directory name. */ 1N/A /* Get the list of file names. */ 1N/A * Search for a valid log file name, return a value of 0 on 1N/A * Assumes that atoi(3) returns a 32-bit number. 1N/A /* Discard the list. */ 1N/A * Validate a log file. 1N/A * PUBLIC: int __log_valid __P((DB_LOG *, u_int32_t, int)); 1N/A /* Try to open the log file. */ 1N/A /* Try to read the header. */ 1N/A /* Validate the header. */ 1N/A "Ignoring log file: %s: magic number %lx, not %lx",
1N/A "Ignoring log file: %s: unsupported log version %lu",
1N/A * If we're going to use this log file, set the region's persistent 1N/A * information based on the headers. 1N/A /* We may have opened files as part of XA; if so, close them. */ 1N/A /* Discard the per-thread pointer. */ 1N/A /* Close the region. */ 1N/A /* Close open files, release allocated memory. */ 1N/A * Return LOG statistics. 1N/A /* Copy out the global statistics. */