1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6 
7 
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9 
10     PerconaFT is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License, version 2,
12     as published by the Free Software Foundation.
13 
14     PerconaFT is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
21 
22 ----------------------------------------
23 
24     PerconaFT is free software: you can redistribute it and/or modify
25     it under the terms of the GNU Affero General Public License, version 3,
26     as published by the Free Software Foundation.
27 
28     PerconaFT is distributed in the hope that it will be useful,
29     but WITHOUT ANY WARRANTY; without even the implied warranty of
30     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31     GNU Affero General Public License for more details.
32 
33     You should have received a copy of the GNU Affero General Public License
34     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36 
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38 
39 // verify that the log file trimmer does not delete the log file containing the
40 // begin checkpoint when the checkpoint log entries span multiple log files.
41 
42 #include "logger/logcursor.h"
43 #include "test.h"
44 
45 int
test_main(int argc,const char * argv[])46 test_main (int argc __attribute__((__unused__)),
47 	  const char *argv[] __attribute__((__unused__))) {
48     int r;
49     toku_os_recursive_delete(TOKU_TEST_FILENAME);
50     r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU);    assert(r==0);
51 
52     TOKULOGGER logger;
53     r = toku_logger_create(&logger); assert(r == 0);
54     r = toku_logger_set_lg_max(logger, 32); assert(r == 0);
55     r = toku_logger_open(TOKU_TEST_FILENAME, logger); assert(r == 0);
56     BYTESTRING hello = (BYTESTRING) { 5, (char *) "hello"};
57     LSN comment_lsn;
58     toku_log_comment(logger, &comment_lsn, true, 0, hello);
59     LSN begin_lsn;
60     toku_log_begin_checkpoint(logger, &begin_lsn, true, 0, 0);
61     LSN end_lsn;
62     toku_log_end_checkpoint(logger, &end_lsn, true, begin_lsn, 0, 0, 0);
63     toku_logger_maybe_trim_log(logger, begin_lsn);
64     r = toku_logger_close(&logger); assert(r == 0);
65 
66     // verify all log entries prior the begin checkpoint are trimmed
67     TOKULOGCURSOR lc = NULL;
68     r = toku_logcursor_create(&lc, TOKU_TEST_FILENAME); assert(r == 0);
69     struct log_entry *le = NULL;
70     r = toku_logcursor_first(lc, &le); assert(r == 0);
71     assert(le->cmd == LT_begin_checkpoint);
72     r = toku_logcursor_destroy(&lc); assert(r == 0);
73 
74     toku_os_recursive_delete(TOKU_TEST_FILENAME);
75     return 0;
76 }
77