libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_journal.c File Reference

#include <jf/jf_config.h>
#include <jf/jf_journal_recovery.h>
#include <jf/jf_journal_cold_recovery.h>
#include <jf/jf_utils.h>
#include <jf/jf_errors.h>
#include <jf/jf_crash_simul.h>
#include <jf_file.h>

Go to the source code of this file.

Defines

#define JF_TRACE_MODULE   JF_TRACE_MOD_LIB_JOURNAL

Functions

int jf_journal_add_byte_data (jf_journal_t *journal, jf_word_t file_id, const byte_t *data, jf_word_t size)
int jf_journal_attach_file (jf_journal_t *journal, jf_journal_file_t *jf, jf_word_t *file_id)
int jf_journal_close (jf_journal_t *journal)
int jf_journal_close_detach_file (jf_journal_t *journal, jf_word_t file_id)
int jf_journal_commit_int (jf_journal_t *journal, jf_word_t file_id)
int jf_journal_create (jf_journal_t *journal, const char *path, jf_word_t max_files, FILE **stream, const struct jf_journal_opts_s *options)
int jf_journal_get_byte_data (jf_journal_t *journal, jf_word_t file_id, byte_t *data, size_t size, size_t *read)
int jf_journal_get_real_path (const char *path, char **real_path)
int jf_journal_init (jf_journal_t *journal, const struct jf_journal_opts_s *open_opts)
int jf_journal_is_all_sync (const jf_journal_t *journal)
int jf_journal_is_sync (const jf_journal_t *journal, jf_word_t file_id)
int jf_journal_load (jf_journal_t *journal, FILE *stream)
int jf_journal_new_unit_of_work (jf_journal_t *journal, jf_word_t file_id)
int jf_journal_open (jf_journal_t *journal, const char *path, jf_word_t max_files, const struct jf_journal_opts_s *options)
int jf_journal_open_attach_file (jf_journal_t *journal, const char *path, const char *mode, jf_word_t *file_id, int join, const struct jf_journal_file_opts_s *options)
int jf_journal_restore_files (const char *path)
int jf_journal_rollback_int (jf_journal_t *journal, jf_word_t file_id)
int jf_journal_rotate (jf_journal_t *journal)
int jf_journal_set_all_sync (jf_journal_t *journal)
int jf_journal_shift_files (const jf_journal_t *journal)
int jf_journal_sync (jf_journal_t *journal)
int jf_journal_trace (const jf_journal_t *journal, const char *method, FILE *out_stream)
int jf_journal_update_file_table (const jf_journal_t *journal, jf_word_t file_id, uint32_t flags)
int jf_journal_write_record (jf_journal_t *journal, jf_word_t file_id, jf_offset_t chunk_id)
int jf_journal_write_records (jf_journal_t *journal, jf_word_t file_id)
void jf_set_default_journal_opts (struct jf_journal_opts_s *options)

Variables

const char * JF_JOURNAL_EXTENSION = ".jf"
const char * JF_JOURNAL_TMP_EXTENSION = ".tjf"


Define Documentation

#define JF_TRACE_MODULE   JF_TRACE_MOD_LIB_JOURNAL
 

Definition at line 56 of file jf_journal.c.


Function Documentation

int jf_journal_add_byte_data jf_journal_t journal,
jf_word_t  file_id,
const byte_t data,
jf_word_t  size
 

Add data string to journaled file

Parameters:
journal IN/OUT journal object
file_id IN id of the file data are to be sent
data IN data must be appended
size IN number of byte must be appended
Returns:
a reason code
Definition at line 1250 of file jf_journal.c.

References byte_t, CATCH, FALSE, jf_journal_t::file_size, jf_journal_t::file_table, jf_cache_file_get_last_pos(), jf_cache_file_limit_exceeded(), jf_cache_file_resize(), jf_cache_file_set_content(), JF_FILE_OM_APPEND, JF_FILE_OM_MSDOS, jf_journal_file_get_cache_file(), jf_journal_file_get_last_uc_pos(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_open_mode(), jf_journal_file_get_stream(), jf_journal_file_set_all_in_cache(), jf_journal_file_set_last_uc_pos(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_get_jfile(), JF_JOURNAL_JOURNAL_FILE_ID, jf_journal_write_records(), jf_offset_t, JF_OFFSET_T_FORMAT, JF_RC_INTERNAL_ERROR, JF_RC_JOURNAL_OUT_OF_SPACE, JF_RC_OK, JF_TRACE, jf_translate_NL_CRLF(), jf_word_t, JF_WORD_T_FORMAT, THROW, and TRUE.

Referenced by jf_file_puts(), jf_file_write(), and jf_journal_add_c().

int jf_journal_attach_file jf_journal_t journal,
jf_journal_file_t jf,
jf_word_t file_id
 

Attach a file to a journal

Parameters:
journal IN/OUT journal object
jf IN journaled file must be attached to journal
file_id OUT journaled file id: used to retrieve properties from journal
Returns:
a reason code
Definition at line 811 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_file_get_cache_file(), jf_journal_file_get_open_mode(), jf_journal_file_get_stream(), jf_journal_file_set_cache_file(), jf_journal_file_set_open_mode(), jf_journal_file_set_stream(), jf_journal_file_tab_add(), jf_journal_file_tab_get_jfile(), JF_JOURNAL_FILE_TAB_PATH, jf_journal_file_tab_search(), JF_JOURNAL_FILE_TAB_SIZE, JF_JOURNAL_TRACE, jf_journal_update_file_table(), JF_RC_INTERNAL_ERROR, JF_RC_NULL_OBJECT, JF_RC_OBJ_NOT_FOUND, JF_RC_OK, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, and THROW.

Referenced by jf_journal_open_attach_file().

int jf_journal_close jf_journal_t journal  ) 
 

PUBLIC METHOD
Close a journal object

Parameters:
journal IN/OUT journal object
Returns:
a reason code
Definition at line 371 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, ftello, jf_journal_close_detach_file(), jf_journal_file_get_stream(), jf_journal_file_set_last_pos(), jf_journal_file_tab_destroy(), jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, JF_JOURNAL_GLOBAL_FILE_ID, JF_JOURNAL_JOURNAL_FILE_ID, jf_journal_rollback_int(), jf_journal_rotate(), jf_journal_sync(), jf_offset_t, JF_RC_FTELL_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, jf_word_t, and THROW.

Referenced by bench_X0_ljf_post(), jf_file_close(), jf_journal_util_join(), jf_journal_util_leave(), jf_journal_util_rename(), and main().

int jf_journal_close_detach_file jf_journal_t journal,
jf_word_t  file_id
 

Detach a journaled file from a journal, close associated stream as well

Parameters:
journal IN/OUT journal object
file_id IN identificator of the file in journal
Returns:
a reason code
Definition at line 1156 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_opts_s::flags, jf_journal_file_get_status(), jf_journal_file_get_stream(), jf_journal_file_set_status(), jf_journal_file_set_stream(), JF_JOURNAL_FILE_ST_OPEN, JF_JOURNAL_FILE_TAB_CTRL, jf_journal_file_tab_get_jfile(), JF_JOURNAL_JOURNAL_FILE_ID, jf_journal_update_file_table(), JF_RC_FCLOSE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, jf_stream_sync(), JF_TRACE, jf_word_t, jf_journal_t::open_opts, and THROW.

Referenced by jf_file_close(), jf_journal_close(), and jf_journal_cold_recovery().

int jf_journal_commit_int jf_journal_t journal,
jf_word_t  file_id
 

Commit updates of ONE or ALL the journaled files handle by a journal this method is for internal use only: take a look to jf_journal_commit and jf_file_commit for public methods

Parameters:
journal IN/OUT journal object
file_id IN id of the file must be committed, use JF_JOURNAL_GLOBAL_FILE_ID if the sync is a GLOBAL SYNC POINT (all the journaled filed handled by this journal are committed)
Returns:
a reason code
Definition at line 1602 of file jf_journal.c.

References CATCH, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_num, jf_journal_t::file_size, jf_journal_t::file_table, JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_COMMIT_1, JF_CRASH_SIMUL_F_COMMIT_2, JF_CRASH_SIMUL_F_COMMIT_3, JF_CRASH_SIMUL_F_COMMIT_4, JF_CRASH_SIMUL_F_COMMIT_5, JF_CRASH_SIMUL_F_COMMIT_6, jf_journal_file_get_last_uc_pos(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_status(), jf_journal_file_set_all_in_cache(), jf_journal_file_set_last_pos(), jf_journal_file_set_last_size(), jf_journal_file_set_last_uc_size(), jf_journal_file_set_status(), JF_JOURNAL_FILE_ST_SYNC, JF_JOURNAL_FILE_TAB_CTRL, jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, jf_journal_get_stream(), JF_JOURNAL_GLOBAL_FILE_ID, jf_journal_is_all_sync(), JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_OP_CODE_COMMIT, jf_journal_rotate(), jf_journal_set_all_sync(), jf_journal_sync(), jf_journal_update_file_table(), jf_journal_write_records(), jf_offset_t, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, jf_journal_t::open_opts, jf_journal_opts_s::rotation_threshold, THROW, and TRUE.

Referenced by jf_file_commit(), and jf_journal_commit().

int jf_journal_create jf_journal_t journal,
const char *  path,
jf_word_t  max_files,
FILE **  stream,
const struct jf_journal_opts_s options
 

Create a new journal file and set-up journal object

Parameters:
journal OUT journal object
path IN journal file path
max_files IN max number of files this journal will deal with
stream OUT the (opened) stream associated to the created journal
options IN special option may be used for creating and managing files
Returns:
a reason code
Definition at line 468 of file jf_journal.c.

References CATCH, jf_journal_t::ctrl_recs, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_num, jf_journal_opts_s::file_num, jf_journal_t::file_size, jf_journal_opts_s::file_size, jf_journal_t::file_table, ftello, jf_journal_file_create(), jf_journal_file_init(), jf_journal_file_set_last_pos(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_add(), jf_journal_file_tab_create(), JF_JOURNAL_FILE_TAB_CTRL, jf_journal_file_tab_destroy(), jf_journal_file_tab_dump(), jf_journal_file_tab_get_jfile(), jf_journal_file_tab_init(), JF_JOURNAL_FILE_TAB_PATH, JF_JOURNAL_FILE_TAB_SIZE, JF_JOURNAL_GLOBAL_FILE_ID, JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_MAGIC_NUMBER, JF_JOURNAL_MAX_FILES, JF_JOURNAL_OP_MASK, jf_journal_update_file_table(), JF_JOURNAL_VERSION, JF_RC_FFLUSH_ERROR, JF_RC_FOPEN_ERROR, JF_RC_FTELL_ERROR, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_word_t, jf_journal_opts_s::journal_file_opts, jf_journal_t::journal_recs, jf_journal_t::magic_number, jf_journal_t::size_mask, jf_journal_t::size_mask_shift, THROW, and jf_journal_t::version.

Referenced by jf_journal_open().

int jf_journal_get_byte_data jf_journal_t journal,
jf_word_t  file_id,
byte_t data,
size_t  size,
size_t *  read
 

Get data string from journaled file

Parameters:
journal IN/OUT journal object
file_id IN id of the file data are to be sent
data OUT room for data must be read
size IN max number of bytes can be read
read OUT real number of bytes stored in "data"
Returns:
a reason code
Definition at line 1384 of file jf_journal.c.

References byte_t, CATCH, FALSE, jf_journal_t::file_table, fseeko, jf_cache_file_chunk_get_content(), jf_cache_file_chunk_get_range(), jf_cache_file_search(), JF_FILE_OM_MSDOS, jf_journal_file_get_cache_file(), jf_journal_file_get_last_uc_pos(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_open_mode(), jf_journal_file_get_stream(), jf_journal_file_set_last_uc_pos(), jf_journal_file_tab_get_jfile(), jf_offset_t, JF_RC_EOF, JF_RC_FREAD_ERROR, JF_RC_FSEEK_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OBJ_NOT_FOUND, JF_RC_OK, JF_TRACE, jf_translate_CRLF_NL(), jf_word_t, THROW, and TRUE.

Referenced by jf_file_read(), and jf_journal_get_c().

int jf_journal_get_real_path const char *  path,
char **  real_path
 

Real journal path may be different than expected one if a crash happened
Note: output parameter must be freed if not NULL

Parameters:
path IN expected journal file path
real_path OUT real path name if different than expected path NULL if path is the real path
Returns:
a reason code
Definition at line 2321 of file jf_journal.c.

References CATCH, JF_JOURNAL_TMP_EXTENSION, JF_RC_FCLOSE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OBJ_NOT_FOUND, JF_RC_OK, JF_TRACE, and THROW.

Referenced by jf_journal_cold_recovery_analyze(), and jf_journal_restore_files().

int jf_journal_init jf_journal_t journal,
const struct jf_journal_opts_s open_opts
 

Initialize a new journal object

Parameters:
journal OUT journal file object
open_opts IN journal open options: it can NOT be a NULL pointer
Returns:
a reason code
Definition at line 60 of file jf_journal.c.

References CATCH, FALSE, jf_journal_opts_s::flags, JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_PROP_SYNC_ENV_VAR, JF_JOURNAL_PROP_SYNC_FAST, JF_JOURNAL_PROP_SYNC_SAFE, JF_JOURNAL_PROP_SYNC_SUGGESTED, JF_JOURNAL_PROP_VIRTMEM_ENV_VAR, JF_JOURNAL_PROP_VIRTMEM_HIGH, JF_JOURNAL_PROP_VIRTMEM_LOW, JF_JOURNAL_PROP_VIRTMEM_MEDIUM, JF_JOURNAL_PROP_VIRTMEM_SUGGESTED, JF_JOURNAL_SYNC_TYPE_ENV_VAR, JF_JOURNAL_VIRTMEM_ENV_VAR, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_NULL_OBJECT, JF_RC_OK, JF_TRACE, jf_journal_currec_s::last_id, jf_journal_t::open_opts, jf_journal_t::r, THROW, and TRUE.

Referenced by jf_journal_cold_recovery_analyze(), and jf_journal_open().

int jf_journal_is_all_sync const jf_journal_t journal  ) 
 

Check if the status of all, but journal, journaled files is "synchronized"

Parameters:
journal IN journal object
Returns:
a boolean value
Definition at line 2526 of file jf_journal.c.

References FALSE, jf_journal_t::file_table, jf_journal_file_get_status(), JF_JOURNAL_FILE_ST_SYNC, jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, jf_word_t, and TRUE.

Referenced by jf_journal_commit_int(), and jf_journal_rollback_int().

int jf_journal_is_sync const jf_journal_t journal,
jf_word_t  file_id
 

Check the status of one/all (but journal) journaled files: if one/all files is/are synchronized it returns TRUE, else FALSE

Parameters:
journal IN journal object
file_id IN journaled file to check (use JF_JOURNAL_GLOBAL_FILE_ID to check all journaled files: global sync)
Returns:
a boolean value
Definition at line 2439 of file jf_journal.c.

References FALSE, jf_journal_t::file_table, jf_journal_file_get_status(), JF_JOURNAL_FILE_ST_SYNC, jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, JF_JOURNAL_GLOBAL_FILE_ID, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, and TRUE.

Referenced by jf_journal_scan_undo().

int jf_journal_load jf_journal_t journal,
FILE *  stream
 

Load from disk the journal content

Parameters:
journal OUT journal object
stream IN journal file stream
Returns:
a reason code
Definition at line 667 of file jf_journal.c.

References CATCH, jf_journal_t::ctrl_recs, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_num, jf_journal_t::file_size, jf_journal_t::file_table, ftello, jf_journal_file_set_last_uc_size(), jf_journal_file_tab_create(), jf_journal_file_tab_destroy(), jf_journal_file_tab_get_jfile(), jf_journal_file_tab_restore(), JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_MAGIC_NUMBER, JF_JOURNAL_VERSION, jf_offset_t, JF_OFFSET_T_FORMAT, JF_RC_FREAD_ERROR, JF_RC_FTELL_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MAGIC_NUMBER_ERROR, JF_RC_NULL_OBJECT, JF_RC_OK, JF_RC_VERSION_ERROR, jf_stream_size(), JF_TRACE, jf_journal_t::journal_recs, jf_journal_t::magic_number, jf_journal_t::size_mask, jf_journal_t::size_mask_shift, THROW, and jf_journal_t::version.

Referenced by jf_journal_analyze(), jf_journal_cold_recovery_analyze(), and jf_journal_open().

int jf_journal_new_unit_of_work jf_journal_t journal,
jf_word_t  file_id
 

Open a new unit of work (recovery) for journaled file; this private method can be used before every journaled file update: it checks current status and dump control information if first write is in progress

Parameters:
journal IN/OUT journal object
file_id IN id of the journaled file will be written
Returns:
a reason code
Definition at line 2003 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_file_get_status(), jf_journal_file_set_status(), JF_JOURNAL_FILE_ST_OPEN, JF_JOURNAL_FILE_ST_SYNC, JF_JOURNAL_FILE_TAB_CTRL, jf_journal_file_tab_get_jfile(), jf_journal_update_file_table(), JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, and THROW.

Referenced by jf_journal_write_records().

int jf_journal_open jf_journal_t journal,
const char *  path,
jf_word_t  max_files,
const struct jf_journal_opts_s options
 

PUBLIC METHOD
Open a journal object retrieving data from journal file or creating a new one

Parameters:
journal OUT journal object
path IN journal file path
max_files IN max number of files this journal will deal with (meaningless if the journal already exists)
options IN stuff may be passed to tune specific values; it can be a NULL pointer: default options are used (see jf_set_default_journal_opts)
Returns:
a reason code
Definition at line 236 of file jf_journal.c.

References CATCH, FALSE, jf_journal_t::file_table, jf_journal_opts_s::flags, fseeko, jf_journal_cold_recovery(), jf_journal_create(), jf_journal_file_get_last_pos(), jf_journal_file_get_stream(), jf_journal_file_tab_get_jfile(), jf_journal_init(), JF_JOURNAL_JOURNAL_FILE_ID, jf_journal_load(), JF_JOURNAL_PROP_OPEN_O_CREAT, JF_JOURNAL_PROP_OPEN_O_EXCL, jf_journal_restore_files(), JF_JOURNAL_TRACE, JF_RC_FILE_ALREADY_EXISTS, JF_RC_FSEEK_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_PATH_NAME, JF_RC_OK, JF_RC_OUT_OF_RANGE, jf_set_default_journal_opts(), JF_TRACE, jf_word_t, and THROW.

Referenced by bench_X0_ljf_pre(), jf_file_open(), jf_journal_util_join(), jf_journal_util_leave(), jf_journal_util_rename(), and main().

int jf_journal_open_attach_file jf_journal_t journal,
const char *  path,
const char *  mode,
jf_word_t file_id,
int  join,
const struct jf_journal_file_opts_s options
 

Open a standard stream, create related journaled file object and attach to a journal

Parameters:
journal IN/OUT journal object
path IN journaled file name
mode IN journaled file open mode
file_id OUT identificator of the file in journal
join IN use TRUE if you want to join the journal, FALSE if file must be attached only if already journaled
options IN special option may be used for managing the journaled file will be attached; it's an optional parameter: pass a NULL pointer to use default values
Returns:
a reason code
Definition at line 908 of file jf_journal.c.

References CATCH, FALSE, jf_journal_t::file_table, jf_cache_file_resize(), jf_file_build_open_mode(), jf_file_check_mode(), JF_FILE_OPEN_MODE_SIZE, jf_journal_attach_file(), jf_journal_file_create(), jf_journal_file_get_cache_file(), jf_journal_file_get_last_pos(), jf_journal_file_get_last_size(), jf_journal_file_get_stream(), jf_journal_file_init(), jf_journal_file_set_all_in_cache(), jf_journal_file_set_last_pos(), jf_journal_file_set_last_size(), jf_journal_file_set_last_uc_pos(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_get_jfile(), jf_journal_file_tab_search(), jf_journal_get_jfile(), jf_offset_t, JF_RC_FILE_NOT_ABOVE_JOURNAL, JF_RC_FOPEN_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OBJ_NOT_FOUND, JF_RC_OK, JF_TRACE, jf_word_t, THROW, and TRUE.

Referenced by jf_file_open().

int jf_journal_restore_files const char *  path  ) 
 

Used to assure the journal file is at this place (it may have a different name due to a crash in jf_journal_rotate phase

Parameters:
path IN expected path name for journal
Returns:
a reason code
Definition at line 2391 of file jf_journal.c.

References CATCH, jf_journal_get_real_path(), JF_RC_INTERNAL_ERROR, JF_RC_OBJ_NOT_FOUND, JF_RC_OK, JF_RC_RENAME_ERROR, JF_TRACE, and THROW.

Referenced by jf_journal_open().

int jf_journal_rollback_int jf_journal_t journal,
jf_word_t  file_id
 

Rollback updates of ONE or ALL the journaled files handle by a journal; this method is for internal use only: take a look to jf_journal_rollback and jf_file_rollback for public methods

Parameters:
journal IN/OUT journal object
file_id IN id of the file must be backed-out, use JF_JOURNAL_GLOBAL_FILE_ID if the sync is a GLOBAL ROLLBACK (all the journaled filed handled by this journal are backed-out)
Returns:
a reason code
Definition at line 1786 of file jf_journal.c.

References CATCH, FALSE, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_num, jf_journal_t::file_size, jf_journal_t::file_table, jf_cache_file_clear(), jf_cache_file_get_last_pos(), jf_cache_file_set_last_pos(), JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_ROLLBACK_1, JF_CRASH_SIMUL_F_ROLLBACK_2, JF_CRASH_SIMUL_F_ROLLBACK_3, JF_CRASH_SIMUL_F_ROLLBACK_4, JF_JOURNAL_ANALYZE_RECOVERY, jf_journal_file_get_all_in_cache(), jf_journal_file_get_cache_file(), jf_journal_file_get_last_pos(), jf_journal_file_get_last_size(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_status(), jf_journal_file_get_stream(), jf_journal_file_set_all_in_cache(), jf_journal_file_set_last_uc_pos(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, jf_journal_get_stream(), JF_JOURNAL_GLOBAL_FILE_ID, jf_journal_is_all_sync(), JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_OP_CODE_ROLLBACK, jf_journal_rotate(), jf_journal_scan(), jf_offset_t, JF_OFFSET_T_FORMAT, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, jf_stream_truncate(), JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, jf_journal_t::open_opts, jf_journal_opts_s::rotation_threshold, THROW, and TRUE.

Referenced by jf_file_rollback(), jf_journal_close(), and jf_journal_rollback().

int jf_journal_rotate jf_journal_t journal  ) 
 

Rotate the stream associated to journal: current journal is stored and a fresh one is produced (if size was exceeded)

Parameters:
journal IN/OUT journal object
Returns:
a reason code
Definition at line 2063 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_opts_s::flags, JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_ROTATE_1, JF_CRASH_SIMUL_F_ROTATE_2, JF_CRASH_SIMUL_F_ROTATE_3, JF_CRASH_SIMUL_F_ROTATE_4, JF_CRASH_SIMUL_F_ROTATE_5, JF_CRASH_SIMUL_F_ROTATE_6, jf_journal_file_get_path(), jf_journal_file_get_stream(), jf_journal_file_set_last_pos(), jf_journal_file_set_last_uc_size(), jf_journal_file_set_stream(), JF_JOURNAL_FILE_TAB_CTRL, jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_JOURNAL_FILE_ID, jf_journal_shift_files(), JF_JOURNAL_TMP_EXTENSION, jf_journal_update_file_table(), JF_RC_FCLOSE_ERROR, JF_RC_FOPEN_ERROR, JF_RC_FREAD_ERROR, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OK, JF_RC_RENAME_ERROR, jf_stream_sync(), JF_TRACE, jf_word_t, jf_journal_t::journal_recs, jf_journal_t::open_opts, and THROW.

Referenced by jf_journal_close(), jf_journal_commit_int(), jf_journal_rollback_int(), jf_journal_util_leave(), and jf_journal_util_rename().

int jf_journal_set_all_sync jf_journal_t journal  ) 
 

Set the status of all, but journal, journaled files to "synchronized"

Parameters:
journal IN journal object
Returns:
a reason code
Definition at line 2476 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_file_get_status(), jf_journal_file_set_status(), JF_JOURNAL_FILE_ST_SYNC, jf_journal_file_tab_get_jfile(), jf_journal_file_tab_get_number_of_files(), JF_JOURNAL_FIRST_FILE_ID, JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, and THROW.

Referenced by jf_journal_commit_int(), and jf_journal_scan_undo().

int jf_journal_shift_files const jf_journal_t journal  ) 
 

Shift old journal files: jf.n-1 -> jf.n, jf.n-2 -> jf.n-1, ... jf.1 -> jf.2 This is a convenience internal method

Parameters:
journal IN journal object
Returns:
a reason code
Definition at line 2228 of file jf_journal.c.

References CATCH, jf_journal_t::file_num, jf_journal_t::file_table, JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_SHIFT_FILES_1, JF_JOURNAL_2_64_BASE_10_DIGITS, jf_journal_file_get_path(), jf_journal_file_tab_get_jfile(), JF_JOURNAL_JOURNAL_FILE_ID, JF_RC_FCLOSE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OK, JF_RC_RENAME_ERROR, JF_TRACE, jf_word_t, JF_WORD_T_FORMAT, and THROW.

Referenced by jf_journal_rotate().

int jf_journal_sync jf_journal_t journal  ) 
 

Synchronize journal disk file content

Parameters:
journal IN/OUT journal object
Returns:
a reason code
Definition at line 1564 of file jf_journal.c.

References CATCH, jf_journal_t::file_table, jf_journal_opts_s::flags, jf_journal_file_get_stream(), jf_journal_file_tab_get_jfile(), JF_JOURNAL_JOURNAL_FILE_ID, JF_RC_INTERNAL_ERROR, JF_RC_OK, jf_stream_sync(), JF_TRACE, jf_journal_t::open_opts, and THROW.

Referenced by jf_journal_close(), jf_journal_cold_recovery(), jf_journal_commit_int(), and jf_journal_write_records().

int jf_journal_trace const jf_journal_t journal,
const char *  method,
FILE *  out_stream
 

Trace journal file content to stream

Parameters:
journal IN journal object
method IN method name
out_stream IN output stream (i.e. stderr)
Definition at line 2917 of file jf_journal.c.

References jf_journal_t::ctrl_recs, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_num, jf_journal_t::file_size, jf_journal_t::file_table, jf_journal_file_tab_trace(), JF_OFFSET_T_FORMAT, jf_journal_t::journal_recs, jf_journal_t::magic_number, jf_journal_t::open_opts, jf_journal_opts_s::rotation_threshold, jf_journal_t::size_mask, jf_journal_t::size_mask_shift, and jf_journal_t::version.

Referenced by jf_journal_analyze().

int jf_journal_update_file_table const jf_journal_t journal,
jf_word_t  file_id,
uint32_t  flags
 

Update the content of the journal file physical copy: the table file has been changed at pos "pos"

Parameters:
journal IN journal object
file_id IN changed file id
flags IN which data of file table must be updated ( JF_JOURNAL_FILE_TAB_SIZE, JF_JOURNAL_FILE_TAB_PATH, JF_JOURNAL_FILE_TAB_CTRL )
Returns:
a reason code
Definition at line 1098 of file jf_journal.c.

References CATCH, jf_journal_t::ctrl_recs, jf_journal_t::file_table, fseeko, ftello, jf_journal_file_tab_dump(), jf_journal_get_stream(), jf_offset_t, JF_RC_FSEEK_ERROR, JF_RC_FTELL_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, jf_word_t, and THROW.

Referenced by jf_journal_attach_file(), jf_journal_close_detach_file(), jf_journal_cold_recovery(), jf_journal_commit_int(), jf_journal_create(), jf_journal_new_unit_of_work(), jf_journal_rotate(), jf_journal_util_leave(), and jf_journal_util_rename().

int jf_journal_write_record jf_journal_t journal,
jf_word_t  file_id,
jf_offset_t  chunk_id
 

Write a record to journal file: every used range in the cache file is dumped as a journal record. This is a private method generally invoked by jf_journal_write_records

Parameters:
journal IN/OUT journal object
file_id IN id of the journaled file the range is a piece of
chunk_id IN id of the chunk must be saved to journal
Returns:
a reason code
Definition at line 2676 of file jf_journal.c.

References byte_t, CATCH, jf_journal_t::file_id_mask, jf_journal_t::file_id_mask_shift, jf_journal_t::file_table, fseeko, jf_cache_file_chunk_get_content(), jf_cache_file_chunk_get_range(), jf_cache_file_is_empty(), JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_WRITE_RECORD_1, JF_CRASH_SIMUL_F_WRITE_RECORD_2, JF_CRASH_SIMUL_F_WRITE_RECORD_3, JF_CRASH_SIMUL_F_WRITE_RECORD_4, JF_CRASH_SIMUL_F_WRITE_RECORD_5, JF_CRASH_SIMUL_F_WRITE_RECORD_6, JF_CRASH_SIMUL_F_WRITE_RECORD_7, JF_CRASH_SIMUL_F_WRITE_RECORD_8, JF_CRASH_SIMUL_F_WRITE_RECORD_9, jf_journal_file_get_cache_file(), jf_journal_file_get_last_size(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_stream(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_get_jfile(), JF_JOURNAL_JOURNAL_FILE_ID, JF_JOURNAL_OP_CODE_APPEND, JF_JOURNAL_OP_CODE_UPDATE, JF_JOURNAL_OP_DO, jf_offset_t, JF_RC_FREAD_ERROR, JF_RC_FSEEK_ERROR, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, JF_TRACE_HEX_DATA, jf_word_t, jf_journal_t::size_mask, jf_journal_t::size_mask_shift, and THROW.

Referenced by jf_journal_write_records().

int jf_journal_write_records jf_journal_t journal,
jf_word_t  file_id
 

Write records related to a journaled file: redo data and undo data are saved to assure file recovery

Parameters:
journal IN/OUT journal object
file_id IN id of the journaled file must be "saved"
Returns:
a reason code
Definition at line 2545 of file jf_journal.c.

References byte_t, CATCH, jf_journal_t::file_table, fseeko, ftello, jf_cache_file_chunk_get_content(), jf_cache_file_chunk_get_range(), jf_cache_file_chunk_is_used(), jf_cache_file_clear(), jf_cache_file_get_size(), JF_CRASH_SIMUL, JF_CRASH_SIMUL_F_WRITE_RECORDS_1, JF_CRASH_SIMUL_F_WRITE_RECORDS_2, JF_CRASH_SIMUL_F_WRITE_RECORDS_3, JF_CRASH_SIMUL_F_WRITE_RECORDS_4, jf_journal_file_get_cache_file(), jf_journal_file_get_last_uc_size(), jf_journal_file_get_status(), jf_journal_file_get_stream(), jf_journal_file_set_last_uc_size(), jf_journal_file_tab_get_jfile(), jf_journal_new_unit_of_work(), jf_journal_sync(), jf_journal_write_record(), jf_offset_t, JF_RC_FSEEK_ERROR, JF_RC_FTELL_ERROR, JF_RC_FWRITE_ERROR, JF_RC_INTERNAL_ERROR, JF_RC_OK, JF_TRACE, JF_TRACE_HEX_DATA, jf_word_t, JF_WORD_T_FORMAT, and THROW.

Referenced by jf_journal_add_byte_data(), and jf_journal_commit_int().

void jf_set_default_journal_opts struct jf_journal_opts_s options  ) 
 

PUBLIC METHOD
Set default value for journal options

Parameters:
options IN/OUT pointer to struct must be set
Definition at line 202 of file jf_journal.c.

References FALSE, jf_journal_opts_s::file_num, jf_journal_opts_s::file_size, jf_journal_opts_s::flags, JF_JOURNAL_DEFAULT_FILE_NUM, JF_JOURNAL_DEFAULT_FILE_SIZE, JF_JOURNAL_DEFAULT_ROTATION_THRESHOLD, JF_JOURNAL_FILE_NUM_MIN, JF_JOURNAL_NUM_ENV_VAR, JF_JOURNAL_PROP_SYNC_DEFAULT, JF_JOURNAL_PROP_VIRTMEM_DEFAULT, JF_JOURNAL_ROT_THRESH_ENV_VAR, JF_JOURNAL_SIZE_ENV_VAR, jf_set_default_journal_file_opts(), jf_journal_opts_s::journal_file_opts, jf_journal_opts_s::recovery_analyze_flags, jf_journal_opts_s::recovery_damaged_journal, jf_journal_opts_s::recovery_enabled, and jf_journal_opts_s::rotation_threshold.

Referenced by bench_X0_ljf_pre(), jf_journal_cold_recovery_analyze(), jf_journal_open(), jf_journal_reset(), jf_journal_util_join(), jf_journal_util_leave(), jf_journal_util_rename(), jf_set_default_file_open_opts(), and main().


Variable Documentation

const char* JF_JOURNAL_EXTENSION = ".jf"
 

This is the default extension for private journal files Definition at line 46 of file jf_journal.c.

Referenced by jf_file_open().

const char* JF_JOURNAL_TMP_EXTENSION = ".tjf"
 

This is the default extension for temporary journal files created by jf_journal_rotate Definition at line 48 of file jf_journal.c.

Referenced by jf_journal_get_real_path(), and jf_journal_rotate().


Copyright 2005 © Tiian