~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/maria/unittest/ma_test_loghandler_first_lsn-t.c

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006-2008 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "../maria_def.h"
 
17
#include <stdio.h>
 
18
#include <errno.h>
 
19
#include <tap.h>
 
20
#include "../trnman.h"
 
21
 
 
22
extern my_bool maria_log_remove();
 
23
extern void translog_example_table_init();
 
24
 
 
25
#ifndef DBUG_OFF
 
26
static const char *default_dbug_option;
 
27
#endif
 
28
 
 
29
#define PCACHE_SIZE (1024*1024*10)
 
30
#define PCACHE_PAGE TRANSLOG_PAGE_SIZE
 
31
#define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
 
32
#define LOG_FLAGS 0
 
33
 
 
34
static char *first_translog_file= (char*)"maria_log.00000001";
 
35
 
 
36
int main(int argc __attribute__((unused)), char *argv[])
 
37
{
 
38
  uint pagen;
 
39
  uchar long_tr_id[6];
 
40
  PAGECACHE pagecache;
 
41
  LSN lsn, first_lsn, theor_lsn;
 
42
  LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
 
43
 
 
44
  MY_INIT(argv[0]);
 
45
 
 
46
  plan(2);
 
47
 
 
48
  bzero(&pagecache, sizeof(pagecache));
 
49
  maria_data_root= (char *)".";
 
50
  if (maria_log_remove())
 
51
    exit(1);
 
52
  /* be sure that we have no logs in the directory*/
 
53
  my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
 
54
  my_delete(first_translog_file, MYF(0));
 
55
 
 
56
  bzero(long_tr_id, 6);
 
57
#ifndef DBUG_OFF
 
58
#if defined(__WIN__)
 
59
  default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
 
60
#else
 
61
  default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
 
62
#endif
 
63
  if (argc > 1)
 
64
  {
 
65
    DBUG_SET(default_dbug_option);
 
66
    DBUG_SET_INITIAL(default_dbug_option);
 
67
  }
 
68
#endif
 
69
 
 
70
  if (ma_control_file_open(TRUE, TRUE))
 
71
  {
 
72
    fprintf(stderr, "Can't init control file (%d)\n", errno);
 
73
    exit(1);
 
74
  }
 
75
  if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
 
76
                             PCACHE_PAGE, 0)) == 0)
 
77
  {
 
78
    fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
 
79
    exit(1);
 
80
  }
 
81
  if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
 
82
                               LOG_FLAGS, 0, &translog_example_table_init,
 
83
                               0))
 
84
  {
 
85
    fprintf(stderr, "Can't init loghandler (%d)\n", errno);
 
86
    exit(1);
 
87
  }
 
88
  /* Suppressing of automatic record writing */
 
89
  dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
 
90
 
 
91
  theor_lsn= translog_first_theoretical_lsn();
 
92
  if (theor_lsn == 1)
 
93
  {
 
94
    fprintf(stderr, "Error reading the first log file.");
 
95
    translog_destroy();
 
96
    exit(1);
 
97
  }
 
98
  if (theor_lsn == LSN_IMPOSSIBLE)
 
99
  {
 
100
    fprintf(stderr, "There is no first log file.");
 
101
    translog_destroy();
 
102
    exit(1);
 
103
  }
 
104
  first_lsn= translog_first_lsn_in_log();
 
105
  if (first_lsn != LSN_IMPOSSIBLE)
 
106
  {
 
107
    fprintf(stderr, "Incorrect first lsn response (%lu,0x%lx).",
 
108
            LSN_IN_PARTS(first_lsn));
 
109
    translog_destroy();
 
110
    exit(1);
 
111
  }
 
112
  ok(1, "Empty log response");
 
113
 
 
114
 
 
115
  int4store(long_tr_id, 0);
 
116
  parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id;
 
117
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
 
118
  if (translog_write_record(&lsn,
 
119
                            LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
 
120
                            &dummy_transaction_object, NULL, 6,
 
121
                            TRANSLOG_INTERNAL_PARTS + 1,
 
122
                            parts, NULL, NULL))
 
123
  {
 
124
    fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
 
125
    translog_destroy();
 
126
    exit(1);
 
127
  }
 
128
 
 
129
  theor_lsn= translog_first_theoretical_lsn();
 
130
  if (theor_lsn == 1)
 
131
  {
 
132
    fprintf(stderr, "Error reading the first log file\n");
 
133
    translog_destroy();
 
134
    exit(1);
 
135
  }
 
136
  if (theor_lsn == LSN_IMPOSSIBLE)
 
137
  {
 
138
    fprintf(stderr, "There is no first log file\n");
 
139
    translog_destroy();
 
140
    exit(1);
 
141
  }
 
142
  first_lsn= translog_first_lsn_in_log();
 
143
  if (first_lsn != theor_lsn)
 
144
  {
 
145
    fprintf(stderr, "Incorrect first lsn: (%lu,0x%lx)  "
 
146
            " theoretical first: (%lu,0x%lx)\n",
 
147
            LSN_IN_PARTS(first_lsn), LSN_IN_PARTS(theor_lsn));
 
148
    translog_destroy();
 
149
    exit(1);
 
150
  }
 
151
 
 
152
  ok(1, "Full log response");
 
153
 
 
154
  translog_destroy();
 
155
  end_pagecache(&pagecache, 1);
 
156
  ma_control_file_end();
 
157
  if (maria_log_remove())
 
158
    exit(1);
 
159
  exit(0);
 
160
}
 
161
 
 
162
#include "../ma_check_standalone.h"