Every saga needs at least a second episode. |
What happens if data are not committed to a journaled file? To discover
the core of libjf
transactionality it's sufficient to remove
jf_file_commit
statement as in
hello_world2.c example:
Example 2-2. hello_world2.c
1 #include <jf_file.h> 2 int main() 3 { 4 int rc; 5 jf_file_t jf; 6 size_t write; 7 rc = jf_file_open(&jf, NULL, "jf_tut_foo", "w", NULL); 8 if (JF_RC_OK != rc) 9 return 1; 10 rc = jf_file_printf(&jf, &write, "%s", "Hello world!\n"); 11 if (JF_RC_OK != rc) 12 return 1; 13 rc = jf_file_close(&jf); 14 if (JF_RC_OK != rc) 15 return 1; 16 printf("Hello world II program is OK!\n"); 17 return 0; 18 }
libtool --mode=link gcc -Wall -I/opt/libjf/include -L/opt/libjf/lib -ljf \ -o hello_world2 hello_world2.cremove temporary files wrote by hello_world:
tiian@linux:~/tutorial> rm -f jf_tut_foo*and run hello_world2 program:
tiian@linux:~/tutorial> ./hello_world2 Hello world II program is OK!Take a look to files produced by hello_world2 execution:
tiian@linux:~/tutorial> ls -la jf_tut_foo* -rw-r--r-- 1 tiian users 0 2005-08-11 11:05 jf_tut_foo -rw-r--r-- 1 tiian users 8278 2005-08-11 11:05 jf_tut_foo.jfjf_tut_foo is now an empty file because data was not committed before calling
jf_file_close
(this
behavior is named "implicit rollback"); just for the sake of
curiosity, inspect the associated journal file:
tiian@linux:~/tutorial> jf_report -dt -j jf_tut_foo.jf <?xml version="1.0" encoding="UTF-8"?> <journal> <header magic_number='0x41524153' version='1' file_id_mask='0x8' file_id_mask_shift='3' size_mask='0xfffffff0' size_mask_shift='4' file_size='4194304' file_num='3' rotation_threshold='0.800' ctrl_recs='36' journal_recs='8278' /> <journaled_file_table max_files='2' number_of_files='2' file_table='0x804b170'> <file id='0' name='jf_tut_foo.jf' last_pos='8278' last_size='0' status='0' last_uc_pos='0' last_uc_size='8278' stream='0x804b008' /> <file id='1' name='jf_tut_foo' last_pos='0' last_size='0' status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' /> </journaled_file_table> <records> </records> </journal>no records have been written.