ma_test_loghandler_pagecache-t.c 4.49 KB
Newer Older
1 2 3
#include "../maria_def.h"
#include <stdio.h>
#include <errno.h>
4
#include <tap.h>
5
#include "../trnman.h"
6

unknown's avatar
unknown committed
7 8
extern my_bool maria_log_remove();

9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef DBUG_OFF
static const char *default_dbug_option;
#endif

#define PCACHE_SIZE (1024*1024*10)
#define PCACHE_PAGE TRANSLOG_PAGE_SIZE
#define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
#define LOG_FLAGS 0

static char *first_translog_file= (char*)"maria_log.00000001";
static char *file1_name= (char*)"page_cache_test_file_1";
static PAGECACHE_FILE file1;

unknown's avatar
unknown committed
22
int main(int argc __attribute__((unused)), char *argv[])
23 24
{
  uint pagen;
unknown's avatar
unknown committed
25
  uchar long_tr_id[6];
26 27 28
  PAGECACHE pagecache;
  LSN lsn;
  MY_STAT st, *stat;
29
  LEX_STRING parts[TRANSLOG_INTERNAL_PARTS + 1];
30 31 32

  MY_INIT(argv[0]);

unknown's avatar
unknown committed
33 34
  plan(1);

35 36
  bzero(&pagecache, sizeof(pagecache));
  maria_data_root= ".";
unknown's avatar
unknown committed
37 38
  if (maria_log_remove())
    exit(1);
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  /* be sure that we have no logs in the directory*/
  if (my_stat(CONTROL_FILE_BASE_NAME, &st,  MYF(0)))
    my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
  if (my_stat(first_translog_file, &st,  MYF(0)))
    my_delete(first_translog_file, MYF(0));

  bzero(long_tr_id, 6);
#ifndef DBUG_OFF
#if defined(__WIN__)
  default_dbug_option= "d:t:i:O,\\ma_test_loghandler_pagecache.trace";
#else
  default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler_pagecache.trace";
#endif
  if (argc > 1)
  {
    DBUG_SET(default_dbug_option);
    DBUG_SET_INITIAL(default_dbug_option);
  }
#endif

unknown's avatar
unknown committed
59
  if (ma_control_file_create_or_open(TRUE))
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  {
    fprintf(stderr, "Can't init control file (%d)\n", errno);
    exit(1);
  }
  if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
                             PCACHE_PAGE)) == 0)
  {
    fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
    exit(1);
  }
  if (translog_init(".", LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS))
  {
    fprintf(stderr, "Can't init loghandler (%d)\n", errno);
    translog_destroy();
    exit(1);
  }
76
  example_loghandler_init();
77 78
  /* Suppressing of automatic record writing */
  dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
79 80 81 82 83 84 85 86 87 88 89 90 91 92

  if ((stat= my_stat(first_translog_file, &st,  MYF(0))) == 0)
  {
    fprintf(stderr, "There is no %s (%d)\n", first_translog_file, errno);
    exit(1);
  }
  if (st.st_size != TRANSLOG_PAGE_SIZE)
  {
    fprintf(stderr,
            "incorrect initial size of %s: %ld instead of %ld\n",
            first_translog_file, (long)st.st_size, (long)TRANSLOG_PAGE_SIZE);
    exit(1);
  }
  int4store(long_tr_id, 0);
93 94
  parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id;
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
95
  dummy_transaction_object.first_undo_lsn= TRANSACTION_LOGGED_LONG_ID;
96
  if (translog_write_record(&lsn,
97
                            LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
98 99
                            &dummy_transaction_object, NULL, 6,
                            TRANSLOG_INTERNAL_PARTS + 1,
unknown's avatar
unknown committed
100
                            parts, NULL, NULL))
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
  {
    fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
    translog_destroy();
    exit(1);
  }

  if ((file1.file= my_open(file1_name,
                           O_CREAT | O_TRUNC | O_RDWR, MYF(0))) == -1)
  {
    fprintf(stderr, "Got error during file1 creation from open() (errno: %d)\n",
	    errno);
    exit(1);
  }
  if (chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
  {
    fprintf(stderr, "Got error during file1 chmod() (errno: %d)\n",
	    errno);
    exit(1);
  }

  {
    uchar page[PCACHE_PAGE];

    bzero(page, PCACHE_PAGE);
#define PAGE_LSN_OFFSET 0
unknown's avatar
unknown committed
126
    lsn_store(page + PAGE_LSN_OFFSET, lsn);
127 128 129 130 131
    pagecache_write(&pagecache, &file1, 0, 3, (char*)page,
                    PAGECACHE_LSN_PAGE,
                    PAGECACHE_LOCK_LEFT_UNLOCKED,
                    PAGECACHE_PIN_LEFT_UNPINNED,
                    PAGECACHE_WRITE_DELAY,
132
                    0, LSN_IMPOSSIBLE);
133 134 135 136 137 138 139 140 141 142 143 144 145
    flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE);
  }
  if ((stat= my_stat(first_translog_file, &st,  MYF(0))) == 0)
  {
    fprintf(stderr, "can't stat %s (%d)\n", first_translog_file, errno);
    exit(1);
  }
  if (st.st_size != TRANSLOG_PAGE_SIZE * 2)
  {
    fprintf(stderr,
            "incorrect initial size of %s: %ld instead of %ld\n",
            first_translog_file,
            (long)st.st_size, (long)(TRANSLOG_PAGE_SIZE * 2));
unknown's avatar
unknown committed
146
    ok(0, "log triggered");
147 148
    exit(1);
  }
unknown's avatar
unknown committed
149
  ok(1, "log triggered");
150 151 152 153 154 155 156 157 158 159

  translog_destroy();
  end_pagecache(&pagecache, 1);
  ma_control_file_end();
  my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
  my_delete(first_translog_file, MYF(0));
  my_delete(file1_name, MYF(0));

  exit(0);
}