2004-06-24 21:10:31 +00:00
|
|
|
/*---
|
|
|
|
This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
2009-05-13 22:06:58 +00:00
|
|
|
* Transaction-level log manipulation routines (commit, update, etc...) that maintain consistency with the transaction tables.
|
2008-12-01 19:48:59 +00:00
|
|
|
*
|
2009-05-13 22:06:58 +00:00
|
|
|
* @ingroup LOGGING_INTERFACES
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LOGGER2_H__
|
|
|
|
#define __LOGGER2_H__
|
|
|
|
|
2009-03-16 08:11:49 +00:00
|
|
|
#include <stasis/common.h>
|
|
|
|
|
2009-05-13 18:04:53 +00:00
|
|
|
typedef struct stasis_log_t stasis_log_t;
|
2009-05-13 22:06:58 +00:00
|
|
|
|
2009-05-13 18:04:53 +00:00
|
|
|
typedef struct stasis_log_group_force_t stasis_log_group_force_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LOG_FORCE_COMMIT, LOG_FORCE_WAL
|
|
|
|
} stasis_log_force_mode_t;
|
|
|
|
|
|
|
|
#include <stasis/logger/groupForce.h>
|
2009-08-22 00:01:02 +00:00
|
|
|
#include <stasis/logger/logEntry.h>
|
2009-10-08 22:48:58 +00:00
|
|
|
#include <stasis/truncation.h>
|
2009-05-13 18:04:53 +00:00
|
|
|
#include <stasis/constants.h>
|
2009-10-14 18:57:50 +00:00
|
|
|
#include <stasis/transactionTable.h>
|
2009-03-16 08:11:49 +00:00
|
|
|
|
2004-07-04 00:46:49 +00:00
|
|
|
/**
|
|
|
|
A callback function that allows logHandle's iterator to stop
|
|
|
|
returning log entries depending on the context in which it was
|
|
|
|
called.
|
|
|
|
*/
|
2006-04-11 02:20:21 +00:00
|
|
|
typedef int (guard_fcn_t)(const LogEntry *, void *);
|
2004-07-04 00:46:49 +00:00
|
|
|
|
2009-05-13 22:06:58 +00:00
|
|
|
/**
|
|
|
|
* Interface provided by Stasis log implementations.
|
|
|
|
*
|
|
|
|
* This struct defines the interface provided by Stasis log
|
|
|
|
* implementations. New log implementations should provide a
|
|
|
|
* method that populates a stasis_log_t with appropriate function
|
|
|
|
* pointers and runtime state.
|
|
|
|
*
|
|
|
|
* @see safeWrites.c, inMemoryLog.c for example implementations.
|
|
|
|
*
|
|
|
|
* @ingroup LOGGING_IMPLEMENTATIONS
|
|
|
|
*/
|
2008-12-01 19:48:59 +00:00
|
|
|
struct stasis_log_t {
|
2009-10-08 22:48:58 +00:00
|
|
|
/**
|
|
|
|
Register a truncation policy with the log.
|
|
|
|
|
|
|
|
If this method is not called, and the log's length is
|
|
|
|
constrained by a hard limit, then truncation might not occur
|
|
|
|
promptly (or at all) when the log runs out of space.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void (*set_truncation)(struct stasis_log_t *log, stasis_truncation_t *trunc);
|
2008-12-01 19:48:59 +00:00
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Return the size of an implementation-specific log entry.
|
|
|
|
|
|
|
|
Log implementations may store extra information in "internal entries".
|
|
|
|
These entries will be ignored by higher-level code. In order to
|
|
|
|
facilitate memory management, Stasis' sizeofLogEntry() method supports
|
|
|
|
internal entries by calling this method.
|
|
|
|
|
|
|
|
@param log "this" log object
|
|
|
|
@param e A log entry with type INTERNALLOG
|
|
|
|
@return the length of e, in bytes.
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
|
|
|
lsn_t (*sizeof_internal_entry)(struct stasis_log_t* log, const LogEntry * e);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Append a log entry to the end of the log.
|
|
|
|
|
2009-05-13 22:06:58 +00:00
|
|
|
Append a log entry to the end of the log.
|
|
|
|
|
|
|
|
@param log "this" log object
|
|
|
|
@param e The entry to be written to log. After the call returns, e->LSN will be the new entry's offset.
|
2008-12-01 19:48:59 +00:00
|
|
|
@return 0 on success
|
|
|
|
*/
|
|
|
|
int (*write_entry)(struct stasis_log_t* log, LogEntry * e);
|
|
|
|
|
2010-01-11 20:41:59 +00:00
|
|
|
LogEntry* (*reserve_entry)(struct stasis_log_t* log, size_t sz);
|
2009-12-31 19:02:34 +00:00
|
|
|
|
2010-01-11 20:41:59 +00:00
|
|
|
int (*write_entry_done)(struct stasis_log_t* log, LogEntry* e);
|
2009-12-31 19:02:34 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
/**
|
|
|
|
Read a log entry, given its LSN.
|
2009-05-13 22:06:58 +00:00
|
|
|
|
|
|
|
Read a log entry, given its LSN.
|
|
|
|
|
|
|
|
@param log "this" log object
|
|
|
|
@param lsn The LSN of the log entry to be read. This must be the LSN of a valid log entry.
|
2009-10-15 20:11:43 +00:00
|
|
|
@return The LogEntry of interest. Should be freed with freeLogEntry(). A NULL return value means the log was truncated past the requested entry.
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
|
|
|
const LogEntry* (*read_entry)(struct stasis_log_t* log, lsn_t lsn);
|
|
|
|
|
2009-12-31 23:25:56 +00:00
|
|
|
/**
|
|
|
|
* Free any resources associated with reading a log entry. This should be called once for each call to read_entry.
|
|
|
|
*/
|
|
|
|
void (*read_entry_done)(struct stasis_log_t *log, const LogEntry *e);
|
2008-12-01 19:48:59 +00:00
|
|
|
/**
|
|
|
|
Given a log entry, return the LSN of the next entry.
|
2009-05-13 22:06:58 +00:00
|
|
|
|
|
|
|
This method returns the LSN of the log entry that will succeed the
|
|
|
|
given entry. Since the meaning of the LSN field is defined by the
|
|
|
|
underlying log implementation, this could return the offset into some
|
|
|
|
underlying file, or simply e->LSN + 1.
|
|
|
|
|
|
|
|
@param log "this" log object
|
|
|
|
@param e A LogEntry that has already been stored in this log.
|
|
|
|
@return the LSN of the next entry. Since LSN's must define an order
|
|
|
|
over the log, this must be greater than e->LSN.
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
|
|
|
lsn_t (*next_entry)(struct stasis_log_t* log, const LogEntry * e);
|
|
|
|
|
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Return the LSN of the earliest log entry that may not survive a crash.
|
|
|
|
|
|
|
|
Return the LSN of the earliest log entry that may not survive a crash.
|
|
|
|
If the entire log is stable, or the log does not support durability,
|
|
|
|
this function returns the LSN of the entry that will be allocated
|
|
|
|
the next time the log is appended to.
|
2008-12-01 22:45:32 +00:00
|
|
|
|
2009-05-13 22:06:58 +00:00
|
|
|
@param log "this" log object, which may or may not support durability.
|
2008-12-01 22:45:32 +00:00
|
|
|
@param mode The mode in which the log entries must have been forced.
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
2008-12-01 22:45:32 +00:00
|
|
|
lsn_t (*first_unstable_lsn)(struct stasis_log_t* log,
|
|
|
|
stasis_log_force_mode_t mode);
|
2009-03-15 02:43:09 +00:00
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Return the LSN that will be assigned to the next entry written to this log.
|
|
|
|
|
|
|
|
This function returns the LSN that will be assigned to the next entry
|
|
|
|
written to log. Because multiple threads may be accessing the same
|
|
|
|
stasis_log_t object, this method should not be used to determine which
|
|
|
|
LSN will actually be assigned; rather it is used to compute a valid
|
|
|
|
lower bound of the LSN of newly-loaded LSN-free pages.
|
|
|
|
|
|
|
|
@param log "this" log object
|
2009-03-15 02:43:09 +00:00
|
|
|
*/
|
|
|
|
lsn_t (*next_available_lsn)(struct stasis_log_t* log);
|
2008-12-01 19:48:59 +00:00
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Force any enqueued, unwritten entries to disk.
|
|
|
|
|
|
|
|
Once this method returns, any log entries written before the call began
|
|
|
|
should survive subsequent crashes. If the underlying log implementation
|
|
|
|
is not durable, then this method has no effect.
|
|
|
|
|
|
|
|
This method should not attempt to amortize the cost of multiple
|
|
|
|
concurrent calls; stasis_log_t::group_force provides takes care of this.
|
|
|
|
If group_force is non-null, callers should invoke methods on it rather
|
|
|
|
than call this method directly.
|
|
|
|
|
|
|
|
@param log "this" log object, which may or may not support durability.
|
|
|
|
@param mode The reason the log tail should be forced; in certain
|
|
|
|
environments, force writes that maintain the write-ahead invariant are
|
|
|
|
treated differently than those for transaction commit.
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
2008-12-01 22:45:32 +00:00
|
|
|
void (*force_tail)(struct stasis_log_t* log, stasis_log_force_mode_t mode);
|
2008-12-01 19:48:59 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Delete a prefix of the log.
|
|
|
|
|
|
|
|
This method allows the log to "forget" about old log entries. Its
|
|
|
|
behavior is implementation defined. A call to truncate amounts to a
|
|
|
|
promise that subsequent calls to stasis_log_t::read_entry will not
|
|
|
|
request entries before the truncation point.
|
|
|
|
|
|
|
|
@param log "this" log object.
|
|
|
|
@param lsn The truncation point; the first lsn that will be available after truncation.
|
|
|
|
@return 0 on success
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
|
|
|
int (*truncate)(struct stasis_log_t* log, lsn_t lsn);
|
|
|
|
|
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Return the LSN of the first entry of the log.
|
|
|
|
|
|
|
|
This function returns the LSN of the earliest entry in the log, which
|
|
|
|
must be less than or equal to the highest value ever passed into
|
|
|
|
stasis_log_t::truncate(). If the log is empty, this function returns
|
|
|
|
the same value as stasis_log_t::next_available_lsn().
|
|
|
|
|
|
|
|
@param log "this" log object
|
|
|
|
@return A valid LSN that may be passed into stasis_log_t::read_entry().
|
2008-12-01 19:48:59 +00:00
|
|
|
*/
|
|
|
|
lsn_t (*truncation_point)(struct stasis_log_t* log);
|
|
|
|
/**
|
2009-05-13 22:06:58 +00:00
|
|
|
Ensure that the tail of the log is durable, and free any associated resources.
|
|
|
|
|
|
|
|
Ensure that the tail of the log is durable, and free any associated resources.
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
@return 0 on success
|
|
|
|
*/
|
2009-04-11 17:17:42 +00:00
|
|
|
int (*close)(struct stasis_log_t* log);
|
2008-12-01 19:48:59 +00:00
|
|
|
|
2009-05-13 22:06:58 +00:00
|
|
|
/**
|
|
|
|
* Determine whether or not this log provides durability.
|
|
|
|
*
|
|
|
|
* @return true if this log implementation is durable, zero otherwise.
|
|
|
|
*/
|
2008-12-01 22:45:32 +00:00
|
|
|
int (*is_durable)(struct stasis_log_t* log);
|
2009-05-13 22:06:58 +00:00
|
|
|
/**
|
|
|
|
* @see groupForce.c
|
|
|
|
*/
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_group_force_t * group_force;
|
2009-05-13 22:06:58 +00:00
|
|
|
/**
|
|
|
|
* Implementation-specific state.
|
|
|
|
*/
|
2008-12-29 23:05:13 +00:00
|
|
|
void* impl;
|
2008-12-01 19:48:59 +00:00
|
|
|
};
|
|
|
|
|
2008-12-01 22:45:32 +00:00
|
|
|
/**
|
|
|
|
Synchronously make a prefix of the log durable.
|
|
|
|
|
|
|
|
This method uses group commit to reduce the number of calls to
|
|
|
|
force_tail().
|
2008-12-01 19:48:59 +00:00
|
|
|
|
2008-12-01 22:45:32 +00:00
|
|
|
Durability is guaranteed in an implementation-specific way.
|
|
|
|
|
|
|
|
@param log A log that already contains the entries to be forced to disk.
|
|
|
|
@param lsn Log entries up to and including the one that overlaps lsn will
|
2009-10-12 19:16:41 +00:00
|
|
|
be durable after this call returns. If INVALID_LSN is passed in,
|
|
|
|
the log will be immediately forced up to the current tail, bypassing
|
|
|
|
group commit.
|
2008-12-01 22:45:32 +00:00
|
|
|
@param mode The durability mode associated with this call.
|
|
|
|
|
|
|
|
@see stasis_log_force_mode_t
|
|
|
|
@see logger2.h for information about force_tail().
|
|
|
|
*/
|
2009-05-13 18:04:53 +00:00
|
|
|
void stasis_log_force(stasis_log_t* log, lsn_t lsn, stasis_log_force_mode_t mode);
|
2004-07-04 00:46:49 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
2006-09-27 20:32:27 +00:00
|
|
|
Inform the logging layer that a new transaction has begun, and
|
|
|
|
obtain a handle.
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
void stasis_log_begin_transaction(stasis_log_t* log, int xid, stasis_transaction_table_entry_t* l);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2008-09-24 03:08:32 +00:00
|
|
|
/**
|
2008-12-01 19:48:59 +00:00
|
|
|
Write a transaction PREPARE to the log tail. Blocks until the
|
|
|
|
prepare record is stable.
|
2008-09-24 03:08:32 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
@return the lsn of the prepare log entry
|
|
|
|
*/
|
2009-10-14 21:22:50 +00:00
|
|
|
lsn_t stasis_log_prepare_transaction(stasis_log_t* log, stasis_transaction_table_entry_t * l);
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
2008-12-01 19:48:59 +00:00
|
|
|
Write a transaction COMMIT to the log tail. Blocks until the commit
|
|
|
|
record is stable.
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
@return the lsn of the commit log entry.
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
2009-12-15 06:30:37 +00:00
|
|
|
lsn_t stasis_log_commit_transaction(stasis_log_t* log, stasis_transaction_table_t * tbl, stasis_transaction_table_entry_t * l, int force);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/**
|
2008-12-01 19:48:59 +00:00
|
|
|
Write a transaction ABORT to the log tail. Does not force the log.
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
@return the lsn of the abort log entry.
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
2009-12-15 06:30:37 +00:00
|
|
|
lsn_t stasis_log_abort_transaction(stasis_log_t* log, stasis_transaction_table_t * tbl, stasis_transaction_table_entry_t * l);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/**
|
2009-04-11 17:17:42 +00:00
|
|
|
Write a end transaction record. This entry tells recovery's undo
|
|
|
|
phase that it may safely ignore the transaction.
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
2009-12-15 06:30:37 +00:00
|
|
|
lsn_t stasis_log_end_aborted_transaction (stasis_log_t* log, stasis_transaction_table_t *tbl, stasis_transaction_table_entry_t * l);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2006-04-11 02:20:21 +00:00
|
|
|
/**
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_write_update writes an UPDATELOG log record to the log tail. It
|
2008-12-01 19:48:59 +00:00
|
|
|
also interprets its operation argument to the extent necessary for
|
|
|
|
allocating and laying out the log entry. Finally, it updates the
|
|
|
|
state of the parameter l.
|
2006-04-11 02:20:21 +00:00
|
|
|
*/
|
2009-05-13 18:04:53 +00:00
|
|
|
LogEntry * stasis_log_write_update(stasis_log_t* log,
|
2009-10-14 21:22:50 +00:00
|
|
|
stasis_transaction_table_entry_t * l, pageid_t page, unsigned int operation,
|
2008-12-01 19:48:59 +00:00
|
|
|
const byte * arg, size_t arg_size);
|
2006-04-11 02:20:21 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
|
|
|
Write a compensation log record. These records are used to allow
|
|
|
|
for efficient recovery, and possibly for log truncation. They
|
2005-03-08 07:53:53 +00:00
|
|
|
record the completion of undo operations, amongst other things.
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
@return the lsn of the CLR entry that was written to the log.
|
2008-12-01 19:48:59 +00:00
|
|
|
(Needed so that the lsn slot of the page in question can be
|
|
|
|
updated.)
|
2004-06-24 21:10:31 +00:00
|
|
|
*/
|
2009-05-13 18:04:53 +00:00
|
|
|
lsn_t stasis_log_write_clr(stasis_log_t* log, const LogEntry * e);
|
2007-04-03 09:18:45 +00:00
|
|
|
|
2009-05-14 21:28:09 +00:00
|
|
|
lsn_t stasis_log_write_dummy_clr(stasis_log_t* log, int xid, lsn_t prev_lsn);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2010-01-21 20:27:35 +00:00
|
|
|
void * stasis_log_begin_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, unsigned int op,
|
2009-05-14 21:28:09 +00:00
|
|
|
const byte * arg, size_t arg_size);
|
2009-10-14 21:22:50 +00:00
|
|
|
lsn_t stasis_log_end_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, LogEntry * e);
|
2004-06-24 21:10:31 +00:00
|
|
|
#endif
|