📄 mcolog.h
字号:
/***************************************************************** * * * mcolog.h * * * * This file is a part of the eXtremeDB source code * * Copyright (c) 2001-2006 McObject LLC * * All Rights Reserved * * * *****************************************************************//* * * ABSTRACT: eXtremeDB transaction log public definitions and static API * * * VERSION: 1.0 * * HISTORY: * 1 26-Dec-2003 SS Created it was * 2 04-Sep-2004 SS flag MCO_LOGF_ALREADY_RECOVERED * and error code MCO_E_LOG_ALREADY_RECOVERED were added * 3 08-Sep-2004 SS flag MCO_LOGF_SAVED was added * 4 26-Oct-2004 SS struct mco_LOG_ext was changed: nonbuffered IOcontrol was added * * -- */#ifndef _LOG_LOG_H_ #define _LOG_LOG_H_#ifdef __cplusplusextern "C" { #endif#include "mco.h"/*if you need low-level nonbuffered IO support, this definition MUST be uncommented */#define MCO_CFG_NONBUFFERED_IO_SUPPORT/* definition of the LOG path length */#define MCO_LOG_PATHLENGTH 128/* error's definitions */enum LogErrors { MCO_E_LOG_INVAL = MCO_E_LOG, /* invalid value */ MCO_E_LOG_NOIMAGE, /* bacup image is absent*/ MCO_E_LOG_IMG_NOT_FOUND, /* image file is not found */ MCO_E_LOG_IO_ERROR, /* input/output error */ MCO_E_LOG_LOG_NOT_FOUND, /* LOG file is not found */ MCO_E_LOG_EOLOG, /* end of LOG sequence */ MCO_E_LOG_INVFORMAT, MCO_E_LOG_INVDATA, MCO_E_LOG_FILENOTFOUND, /* file is not found */ MCO_E_LOG_BROKEN_RECORD, /* broken record during recovering */ MCO_E_LOG_ALREADY_MODIFIED, /* there are new transactions saved to log at the moment */ MCO_E_LOG_ALREADY_RECOVERED /* the database is already recovered */};enum LogStartFlags { MCO_LOG_CLOSE = 0x1, /* close/reopen LOG file after each transaction for the debug purposes */ MCO_LOG_NONBUFFERED_IO = 0x2 /* close/reopen LOG file after each transaction for the debug purposes */};/* * compression procedure pointer. * Descripton: * Compresses data in the buffer "buff". Compressed data is placed * to the same buffer * Return: returns length of the compressed data */typedef int (*mco_compress)( void * buff, uint4 lehgth);/* * Decompression procedure pointer. * Descripton: * Decompresses data in the buffer "buff". Decompressed data is placed * to the same buffer * Return: returns length of the decompressed data */typedef int (*mco_decompress)( void * buff, uint4 lehgth);struct _mco_log_compress_;/* * log support internal data structures: *//* * compression descriptor */typedef struct _mco_log_compress_ { mco_compress compress; /* pointer to compression procedure */ mco_compress decompress; /* pointer to decompression procedure */} mco_log_compress_t, *mco_log_compress_h;struct flush_timer_;/* prototype for the external flush timer procedure */typedef mco_bool(*flush_timer_proc)(struct flush_timer_* handle);typedef struct flush_timer_{ timer_unit flush_time; /* The external flush timer procedure flushtimer_proc() MUST signal that the specified amount of time is expired, then the current contents of LOG file buffer will be flushed */ timer_unit time_elapsed; /* when initializing, MUST be zeroized */ flush_timer_proc TimerProc; /* user defined external timer plocedure. MUST signal of elapsing the specified amount of time */}flush_timer_t, *flush_timer_h;/* previous declarations of internal structures *//* The common part of the transaction log descriptor */struct mco_LOG_;typedef struct mco_LOG_ *mco_LOG_h;/* Transaction log per/thread context base descriptor */struct mco_LOG_context_;typedef struct mco_LOG_context_ *mco_log_h;/* LOG common flags */enum LogFlags { MCO_LOGF_INITIALIZED = 0x8000, /* transaction log is initialized */ MCO_LOGF_MODIFIED = 0x4000, /* some transactions were saved to log */ MCO_LOGF_ALREADY_RECOVERED = 0x2000, /* the database is already recovered */ MCO_LOGF_SAVED = 0x1000 /* the database is once saved */};/* LOG context flags */enum LogCtxFlags { MCO_LOGCF_INITIALIZED = 0x8000, /* transaction log is initialized */ MCO_LOGCF_SUPPRESS = 0x4000, /* suppress transaction log during save & recover */ MCO_LOGCF_COMPRESSION = 0x2000, /* enables LOG compression/decompression */ MCO_LOGCF_ASYNCHDEL = 0x1000, /* asynchron LOG deletion enabled */ MCO_LOGCF_ONCE_STARTED = 0x800, /* this flag is used to indicate restart of transaction logging */ MCO_LOGCF_BUSY = 0x400, /* transaction log descriptor is busy */ LOGCF_USERMASK = 0x7ff};/* * The "standard" extension of the common part of the transaction log descriptor. * In user-defined implementation of transaction logging you MAY define your own extension * of the common part of the transaction log descriptor. */typedef struct mco_LOG_ext_{ int4 newdiridx; /* index of the new directory */ int4 lastdiridx; /* last directory index */ int4 deldiridx; /* current directory under deletion */ int4 maxlogsize; /* size limit of LOG file */ int4 maxfiles; /* maximum number of LOG files in the same LOG directory */ int4 currlog; /* current LOG file index */ int4 currdir; /* current directory index */ char basepath[MCO_LOG_PATHLENGTH]; /* log base filepath */ char log_path[MCO_LOG_PATHLENGTH]; /* the path of the current LOG file */#ifdef MCO_CFG_NONBUFFERED_IO_SUPPORT uint1 * io_buffer; /* [MCO_CFG_LOG_IO_BUFFER_SIZE] internal low-level IO buffer */ uint1 * buff_ptr; /* pointer to the current IO buffer offset */ uint4 current_bufsz; /* by default is MCO_CFG_LOG_IO_BUFFER_SIZE, autimaticaly set to current sector size by platform-dependent initialization program */ uint4 file_position; /* current file position for nonbuffered IO */#endif // MCO_CFG_NONBUFFERED_IO_SUPPORT uint2 flags; /* log extension flags */}mco_LOG_ext_t, *mco_LOG_ext_h;/* * The extension of transaction log per/connection descriptor. It is used in the "standard" * implementations of transaction logging. In user-defined implementation of transaction * logging you MAY define your own descriptor. * The first field of the structure MUST always be a pointer to the transaction log * per/thread context base descriptor. */typedef struct mco_log_context_ext_{ mco_log_h base; /* Base descriptor pointer. MUST always be placed first!!! */ void* hndl; /* file handle */ unsigned long filesize; /* current size of LOG file */ int4 logidx; /* current LOG file index */ int4 diridx; /* current directory index */ uint4 offs; /* current offset of the LOG file */ uint2 flush_depth; /* transaction depth value, after which file buffer is flushed */ uint2 flushd_count; /* transaction depth counter */ flush_timer_h flush_timer; /* flush timer structure */}mco_log_ctx_ext_t, *mco_log_ctx_ext_h;/* The structure of "standard" block of arguments for mco_log_start(). In user-defined implementation of transaction logging you MAY use your own block of arguments*/typedef struct log_args_ { char * Filepath; uint4 maxlogsize; uint4 maxfiles; uint2 flags; uint2 flush_depth; flush_timer_h flush_timer;}log_args_t, *log_args_h;/*************************************************************************** External LOG interface ***************************************************************************//***************************************************************************/MCO_RET mco_log_start(mco_db_h dbh, log_args_h args );/* * IN mco_db_h db - database connection handle * log_args_h args - pointer to the structure that contains * implementation-dependent argument list (see mcolog.h) * * Description: * Initializes & starts transaction log. * * Returns MSO_S_OK if successful or error code (see mcolog.h). *//***************************************************************************/MCO_RET mco_log_stop( mco_db_h dbh );/* * IN mco_db_h db - database connection handle * * Description: * stops & deinitializes transaction log. * * Returns MSO_S_OK if successful or error code (see mcolog.h). *//***************************************************************************/MCO_RET mco_log_set_compression( mco_db_h dbh, mco_compress compress_func, mco_decompress decompress_func );/* * IN mco_db_h db - database handle * mco_compress compress_func - pointer to a compression function * mco_decompress decompress_func - pointer to a decompression function * * Description: * Sets compression mode: enables compression/decompression of LOG data * * Returns MSO_S_OK if successful or error code (see mcolog.h). *//***************************************************************************/MCO_RET mco_log_recover( mco_db_h db );/* * IN mco_db_h db - database connection handle * * Description: * Recovers the database after crash. * * Returns MSO_S_OK if successful or error code (see mcolog.h). *//***************************************************************************/MCO_RET mco_log_save( mco_db_h db, short delete_old_log );/* * IN mco_db_h db - database connection handle * mco_bool delete_old_log - deletion flag. if TRUE, old LOGs are deleted after saving * * Description: * Saves the database. * * Returns MSO_S_OK if successful or error code (see mcolog.h). *//***************************************************************************/MCO_RET mco_log_delete_old( mco_db_h db );/* * IN mco_db_h db - database connection handle. * * Description: * Removes old database image & log files. * *//***************************************************************************/MCO_RET mco_log_deferred_deletion( mco_db_h db );/* * IN mco_db_h db - database connection handle. * * Description: * Removes old database image & log files in deferred mode. * * Works in a loop. Returns error code (see mcolog.h) if error. */#ifdef __cplusplus}#endif#endif //_LOG_LOG_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -