Ejemplo n.º 1
0
int main(int argc __attribute__((unused)), char **argv)
{
  MY_INIT(argv[0]);

  if (argv[1] && *argv[1])
    DBUG_SET_INITIAL(argv[1]);

  pthread_mutex_init(&mutex, 0);
  pthread_cond_init(&cond, 0);
  pthread_attr_init(&thr_attr);
  pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);

#define CYCLES 3000
#define THREADS 30

  diag("N CPUs: %d, atomic ops: %s", my_getncpus(), MY_ATOMIC_MODE);

  do_tests();

  /*
    workaround until we know why it crashes randomly on some machine
    (BUG#22320).
  */
#ifdef NOT_USED
  sleep(2);
#endif
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&cond);
  pthread_attr_destroy(&thr_attr);
  my_end(0);
  return exit_status();
}
Ejemplo n.º 2
0
static sig_handler endprog(int sig_number __attribute__((unused)))
{
  {
    hp_panic(HA_PANIC_CLOSE);
    my_end(1);
    exit(1);
  }
}
Ejemplo n.º 3
0
void do_exec(char *args[])
{
  if (!args[0])
    do_usage();

  my_end(0);
  execvp(args[0], args);
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
  MY_INIT(argv[0]);
  {
    uint row_count;
    struct errors *error_head;
    struct languages *lang_head;
    DBUG_ENTER("main");

    charsets_dir= DEFAULT_CHARSET_DIR;
    my_umask_dir= 0777;
    if (get_options(&argc, &argv))
      DBUG_RETURN(1);
    if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head)))
    {
      fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
      DBUG_RETURN(1);
    }
#if MYSQL_VERSION_ID >= 50100 && MYSQL_VERSION_ID < 50500
/* Number of error messages in 5.1 - do not change this number! */
#define MYSQL_OLD_GA_ERROR_MESSAGE_COUNT 641
#elif MYSQL_VERSION_ID >= 50500 && MYSQL_VERSION_ID < 50600
/* Number of error messages in 5.5 - do not change this number! */
#define MYSQL_OLD_GA_ERROR_MESSAGE_COUNT 728
#endif
#if MYSQL_OLD_GA_ERROR_MESSAGE_COUNT
    if (row_count != MYSQL_OLD_GA_ERROR_MESSAGE_COUNT)
    {
      fprintf(stderr, "Can only add new error messages to latest GA. ");
      fprintf(stderr, "Use ER_UNKNOWN_ERROR instead.\n");
      fprintf(stderr, "Expected %u messages, found %u.\n",
              MYSQL_OLD_GA_ERROR_MESSAGE_COUNT, row_count);
      DBUG_RETURN(1);
    }
#endif
    if (lang_head == NULL || error_head == NULL)
    {
      fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
      DBUG_RETURN(1);
    }

    if (create_header_files(error_head))
    {
      fprintf(stderr, "Failed to create header files\n");
      DBUG_RETURN(1);
    }
    if (create_sys_files(lang_head, error_head, row_count))
    {
      fprintf(stderr, "Failed to create sys files\n");
      DBUG_RETURN(1);
    }
    clean_up(lang_head, error_head);
    DBUG_LEAVE;			/* Can't use dbug after my_end() */
    my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
    return 0;
  }
}
Ejemplo n.º 5
0
void
ndb_end(int flags)
{
  if (ndb_init_called == 1)
  {
    my_end(flags);
    ndb_end_internal();
    ndb_init_called = 0;
  }
}
Ejemplo n.º 6
0
int main (int argc, char **argv)
{
  MYSQL conn;
  int OK;

  const char* query4= "INSERT INTO federated.t1 SET Value=54";
  const char* query5= "INSERT INTO federated.t1 SET Value=55";

  MY_INIT(argv[0]);

  if (argc != 2 || !strcmp(argv[1], "--help"))
  {
    fprintf(stderr, "This program is a part of the MySQL test suite. "
            "It is not intended to be executed directly by a user.\n");
    return -1;
  }

  mysql_init(&conn);
  if (!mysql_real_connect(
                          &conn,
                          "127.0.0.1",
                          "root",
                          "",
                          "test",
                          atoi(argv[1]),
                          NULL,
                          CLIENT_FOUND_ROWS))
  {
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
            mysql_error(&conn));
    return 1;
  } else {
    printf("%s\n", mysql_error(&conn));
  }

  OK = mysql_real_query (&conn, query4, strlen(query4));

  assert(0 == OK);

  printf("%ld inserted\n",
         (long) mysql_insert_id(&conn));

  OK = mysql_real_query (&conn, query5, strlen(query5));

  assert(0 == OK);

  printf("%ld inserted\n",
         (long) mysql_insert_id(&conn));

  mysql_close(&conn);
  my_end(0);

  return 0;
};
Ejemplo n.º 7
0
int main(int argc,char *argv[])
{
  int error= 0;
  char tp_path[FN_REFLEN];
  char server_path[FN_REFLEN];
  char operation[16];

  MY_INIT(argv[0]);
  plugin_data.name= 0; // initialize name
  
  /*
    The following operations comprise the method for enabling or disabling
    a plugin. We begin by processing the command options then check the
    directories specified for --datadir, --basedir, --plugin-dir, and
    --plugin-ini (if specified). If the directories are Ok, we then look
    for the mysqld executable and the plugin soname. Finally, we build a
    bootstrap command file for use in bootstraping the server.
    
    If any step fails, the method issues an error message and the tool exits.
    
      1) Parse, execute, and verify command options.
      2) Check access to directories.
      3) Look for mysqld executable.
      4) Look for the plugin.
      5) Build a bootstrap file with commands to enable or disable plugin.
      
  */
  if ((error= process_options(argc, argv, operation)) ||
      (error= check_access()) ||
      (error= find_tool("mysqld" FN_EXEEXT, server_path)) ||
      (error= find_plugin(tp_path)) ||
      (error= build_bootstrap_file(operation, bootstrap)))
    goto exit;
  
  /* Dump the bootstrap file if --verbose specified. */
  if (opt_verbose && ((error= dump_bootstrap_file(bootstrap))))
    goto exit;
  
  /* Start the server in bootstrap mode and execute bootstrap commands */
  error= bootstrap_server(server_path, bootstrap);

exit:
  /* Remove file */
  my_delete(bootstrap, MYF(0));
  if (opt_verbose && error == 0)
  {
    printf("# Operation succeeded.\n");
  }

  my_end(my_end_arg);
  exit(error ? 1 : 0);
  return 0;        /* No compiler warnings */
}
Ejemplo n.º 8
0
static sig_handler endprog(int sig_number __attribute__((unused)))
{
#ifndef THREAD
  if (my_dont_interrupt)
    my_remember_signal(sig_number,endprog);
  else
#endif
  {
    heap_panic(HA_PANIC_CLOSE);
    my_end(1);
    exit(1);
  }
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
  int error,i,first;
  ulong total_count,total_error,total_recover;
  MY_INIT(argv[0]);

  memset(&main_thread_keycache_var, 0, sizeof(st_keycache_thread_var));
  mysql_cond_init(PSI_NOT_INSTRUMENTED,
                  &main_thread_keycache_var.suspend);

  log_filename=myisam_log_filename;
  get_options(&argc,&argv);
  /* Number of MyISAM files we can have open at one time */
  max_files= (my_set_max_open_files(MY_MIN(max_files, 8)) - 6) / 2;
  if (update)
    printf("Trying to %s MyISAM files according to log '%s'\n",
	   (recover ? "recover" : "update"),log_filename);
  error= examine_log(log_filename,argv);
  if (update && ! error)
    puts("Tables updated successfully");
  total_count=total_error=total_recover=0;
  for (i=first=0 ; command_name[i] ; i++)
  {
    if (com_count[i][0])
    {
      if (!first++)
      {
	if (verbose || update)
	  puts("");
	puts("Commands   Used count    Errors   Recover errors");
      }
      printf("%-12s%9ld%10ld%17ld\n",command_name[i],com_count[i][0],
	     com_count[i][1],com_count[i][2]);
      total_count+=com_count[i][0];
      total_error+=com_count[i][1];
      total_recover+=com_count[i][2];
    }
  }
  if (total_count)
    printf("%-12s%9ld%10ld%17ld\n","Total",total_count,total_error,
	   total_recover);
  if (re_open_count)
    printf("Had to do %d re-open because of too few possibly open files\n",
	   re_open_count);
  (void) mi_panic(HA_PANIC_CLOSE);
  my_free_open_file_info();
  my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
  mysql_cond_destroy(&main_thread_keycache_var.suspend);
  exit(error);
  return 0;				/* No compiler warning */
} /* main */
int
main(int argc, char **argv)
{
	MY_INIT(argv[0]);

	if (get_options(&argc, &argv)) {
		goto err;
	}

	if (opt_mode == RUN_MODE_NONE) {
		msg("%s: either -c or -x must be specified.\n", my_progname);
		goto err;
	}

	/* Change the current directory if -C is specified */
	if (opt_directory && my_setwd(opt_directory, MYF(MY_WME))) {
		goto err;
	}

	if (opt_mode == RUN_MODE_CREATE && mode_create(argc, argv)) {
		goto err;
	} else if (opt_mode == RUN_MODE_EXTRACT && mode_extract(argc, argv)) {
		goto err;
	}

	my_cleanup_options(my_long_options);

	my_end(0);

	return EXIT_SUCCESS;
err:
	my_cleanup_options(my_long_options);

	my_end(0);

	exit(EXIT_FAILURE);
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
  int error,i,first;
  ulong total_count,total_error,total_recover;
  MY_INIT(argv[0]);

  log_filename=myisam_log_filename;
  get_options(&argc,&argv);
 /* Nr of isam-files */
  max_files=(set_maximum_open_files(min(max_files,8))-6)/2;

  if (update)
    printf("Trying to %s MyISAM files according to log '%s'\n",
	   (recover ? "recover" : "update"),log_filename);
  error= examine_log(log_filename,argv);
  if (update && ! error)
    puts("Tables updated successfully");
  total_count=total_error=total_recover=0;
  for (i=first=0 ; command_name[i] ; i++)
  {
    if (com_count[i][0])
    {
      if (!first++)
      {
	if (verbose || update)
	  puts("");
	puts("Commands   Used count    Errors   Recover errors");
      }
      printf("%-12s%9ld%10ld%17ld\n",command_name[i],com_count[i][0],
	     com_count[i][1],com_count[i][2]);
      total_count+=com_count[i][0];
      total_error+=com_count[i][1];
      total_recover+=com_count[i][2];
    }
  }
  if (total_count)
    printf("%-12s%9ld%10ld%17ld\n","Total",total_count,total_error,
	   total_recover);
  if (re_open_count)
    printf("Had to do %d re-open because of too few possibly open files\n",
	   re_open_count);
  VOID(mi_panic(HA_PANIC_CLOSE));
  my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
  exit(error);
  return 0;				/* No compiler warning */
} /* main */
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
    int i,error;
    char word_end_chars[256],*pos;
    POINTER_ARRAY from,to;
    REPLACE *replace;
    MY_INIT(argv[0]);

    if (static_get_options(&argc,&argv))
        exit(1);
    if (get_replace_strings(&argc,&argv,&from,&to))
        exit(1);

    for (i=1,pos=word_end_chars ; i < 256 ; i++)
        if (my_isspace(&my_charset_latin1,i))
            *pos++= (char) i;
    *pos=0;
    if (!(replace=init_replace((char**) from.typelib.type_names,
                               (char**) to.typelib.type_names,
                               (uint) from.typelib.count,word_end_chars)))
        exit(1);
    free_pointer_array(&from);
    free_pointer_array(&to);
    if (initialize_buffer())
        return 1;

    error=0;
    if (argc == 0)
        error=convert_pipe(replace,stdin,stdout);
    else
    {
        while (argc--)
        {
            error=convert_file(replace,*(argv++));
        }
    }
    free_buffer();
    my_free(replace);
    my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
    exit(error ? 2 : 0);
    return 0;					/* No compiler warning */
} /* main */
Ejemplo n.º 13
0
static void die(const char *fmt, ...)
{
  va_list args;
  DBUG_ENTER("die");

  /* Print the error message */
  va_start(args, fmt);
  if (fmt)
  {
    fprintf(stderr, "FATAL ERROR: ");
    vfprintf(stderr, fmt, args);
    fprintf(stderr, "\n");
    fflush(stderr);
  }
  va_end(args);

  free_used_memory();
  my_end(my_end_arg);
  exit(1);
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
  MY_INIT(argv[0]);
  {
    uint row_count;
    struct errors *error_head;
    struct languages *lang_head;
    DBUG_ENTER("main");

    charsets_dir= DEFAULT_CHARSET_DIR;
    my_umask_dir= 0777;
    if (get_options(&argc, &argv))
      DBUG_RETURN(1);
    if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head)))
    {
      fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
      DBUG_RETURN(1);
    }
    if (lang_head == NULL || error_head == NULL)
    {
      fprintf(stderr, "Failed to parse input file %s\n", TXTFILE);
      DBUG_RETURN(1);
    }

    if (create_header_files(error_head))
    {
      fprintf(stderr, "Failed to create header files\n");
      DBUG_RETURN(1);
    }
    if (create_sys_files(lang_head, error_head, row_count))
    {
      fprintf(stderr, "Failed to create sys files\n");
      DBUG_RETURN(1);
    }
    clean_up(lang_head, error_head);
    DBUG_LEAVE;			/* Can't use dbug after my_end() */
    my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
    return 0;
  }
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
  struct passwd *user_info;
  MY_INIT(argv[0]);

  if (argc < 3)
    do_usage(argv[0]);

  user_info= my_check_user(argv[1], MYF(0));
  if (user_info ? my_set_user(argv[1], user_info, MYF(MY_WME))
                : my_errno == EINVAL)
    my_exit(1);

  if (strcmp(argv[2], "log") == 0)
    do_log(argv[3]);

  if (strcmp(argv[2], "exec") == 0)
    do_exec(argv+3);

  my_end(0);
  return 1;
}
Ejemplo n.º 16
0
int main(int argc __attribute__((unused)), char **argv)
{
  MY_INIT("thd_template");

  if (argv[1] && *argv[1])
    DBUG_SET_INITIAL(argv[1]);

  pthread_mutex_init(&mutex, 0);
  pthread_cond_init(&cond, 0);
  pthread_attr_init(&thr_attr);
  pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);

#ifdef MY_ATOMIC_MODE_RWLOCKS
#if defined(HPUX11) || defined(__POWERPC__) /* showed to be very slow (scheduler-related) */
#define CYCLES 300
#else
#define CYCLES 3000
#endif
#else
#define CYCLES 3000
#endif
#define THREADS 30

  diag("N CPUs: %d, atomic ops: %s", my_getncpus(), MY_ATOMIC_MODE);

  do_tests();

  /*
    workaround until we know why it crashes randomly on some machine
    (BUG#22320).
  */
  sleep(2);
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&cond);
  pthread_attr_destroy(&thr_attr);
  my_end(0);
  return exit_status();
}
Ejemplo n.º 17
0
Archivo: dll.c Proyecto: Coco-wan/git-1
BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called,
		      LPVOID lpReserved)
{
  switch (ul_reason_being_called) {
  case DLL_PROCESS_ATTACH:	/* case of libentry call in win 3.x */
    if (!inited++)
    {
      s_hModule=hInst;
      libmysql_init();
      main_thread=GetCurrentThreadId();
    }
    break;
  case DLL_THREAD_ATTACH:
    threads++;
    my_thread_init();
    break;
  case DLL_PROCESS_DETACH:	/* case of wep call in win 3.x */
     if (!--inited)		/* Safety */
     {
       /* my_thread_init() */	/* This may give extra safety */
       my_end(0);
     }
    break;
  case DLL_THREAD_DETACH:
    /* Main thread will free by my_end() */
    threads--;
    if (main_thread != GetCurrentThreadId())
      my_thread_end();
    break;
  default:
    break;
  } /* switch */

  return TRUE;

  UNREFERENCED_PARAMETER(lpReserved);
} /* LibMain */
Ejemplo n.º 18
0
int main(int argc __attribute__((unused)), char **argv)
{
  MY_INIT(argv[0]);

  plan(7);

  if (my_atomic_initialize())
    return exit_status();

  pthread_mutex_init(&rt_mutex, 0);
  pthread_attr_init(&attr);
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
  pthread_attr_getstacksize(&attr, &stacksize);
  if (stacksize == 0)
#endif
    stacksize= PTHREAD_STACK_MIN;

#define CYCLES 10000
#define THREADS 10

  trnman_init(0);

  test_trnman_read_from();
  run_test("trnman", test_trnman, THREADS, CYCLES);

  diag("mallocs: %d", trnman_allocated_transactions);
  {
    ulonglong now= microsecond_interval_timer();
    trnman_destroy();
    now= microsecond_interval_timer() - now;
    diag("trnman_destroy: %g", ((double)now)/1e6);
  }

  pthread_mutex_destroy(&rt_mutex);
  my_end(0);
  return exit_status();
}
Ejemplo n.º 19
0
void		my_compute(int *pile1, int *pile2, int size, int opt)
{
	int		c;
	int		ret;
	char	*buf;
	int		r[3][5];

	r[0][4] = opt;
	my_init1(&c, r[0], size, &buf);
	while (++c && (r[0][3] = my_sort(pile1, r[0][1], size, -1)))
	{
		if (my_init2(pile1, pile2, r[0], r) && r[0][4] == 2)
			my_debug(pile1, pile2, r[0][1], r[0][2]);
		if ((ret = check_a(pile1, pile2, &buf, r)) == 0)
			return ;
		else if (ret == 1)
			continue ;
		if ((ret = check_b(pile1, pile2, &buf, r)) == 0)
			return ;
	}
	if (opt == 2)
		my_debug(pile1, pile2, r[0][1], r[0][2]);
	return (my_end(opt, c - 1, buf, **r - 1));
}
Ejemplo n.º 20
0
Archivo: test2.c Proyecto: OPSF/uClinux
int main(int argc, char *argv[])
{
  uint i;
  int j,n1,n2,n3,error,k;
  uint write_count,update,dupp_keys,opt_delete,start,length,blob_pos,
       reclength,ant;
  ulong lastpos,range_records,records;
  N_INFO *file;
  N_KEYDEF keyinfo[10];
  N_RECINFO recinfo[10];
  N_ISAMINFO info;
  char *filename,*blob_buffer;
  MY_INIT(argv[0]);

  filename= (char*) "test2.ISM";
  get_options(argc,argv);
  if (! async_io)
    my_disable_async_io=1;

  reclength=STANDAR_LENGTH+60+(use_blob ? 8 : 0);
  blob_pos=STANDAR_LENGTH+60;
  keyinfo[0].seg[0].base.start=0;
  keyinfo[0].seg[0].base.length=6;
  keyinfo[0].seg[0].base.type=HA_KEYTYPE_TEXT;
  keyinfo[0].seg[0].base.flag=(uint8) pack_type;
  keyinfo[0].seg[1].base.type=0;
  keyinfo[0].base.flag = (uint8) (pack_type ? HA_PACK_KEY : 0);
  keyinfo[1].seg[0].base.start=7;
  keyinfo[1].seg[0].base.length=6;
  keyinfo[1].seg[0].base.type=HA_KEYTYPE_BINARY;
  keyinfo[1].seg[0].base.flag=0;
  keyinfo[1].seg[1].base.start=0;			/* Tv}delad nyckel */
  keyinfo[1].seg[1].base.length=6;
  keyinfo[1].seg[1].base.type=HA_KEYTYPE_NUM;
  keyinfo[1].seg[1].base.flag=HA_REVERSE_SORT;
  keyinfo[1].seg[2].base.type=0;
  keyinfo[1].base.flag =0;
  keyinfo[2].seg[0].base.start=12;
  keyinfo[2].seg[0].base.length=8;
  keyinfo[2].seg[0].base.type=HA_KEYTYPE_BINARY;
  keyinfo[2].seg[0].base.flag=HA_REVERSE_SORT;
  keyinfo[2].seg[1].base.type=0;
  keyinfo[2].base.flag =HA_NOSAME;
  keyinfo[3].seg[0].base.start=0;
  keyinfo[3].seg[0].base.length=reclength-(use_blob ? 8 : 0);
  keyinfo[3].seg[0].base.type=HA_KEYTYPE_TEXT;
  keyinfo[3].seg[0].base.flag=(uint8) pack_type;
  keyinfo[3].seg[1].base.type=0;
  keyinfo[3].base.flag = (uint8) (pack_type ? HA_PACK_KEY : 0);
  keyinfo[4].seg[0].base.start=0;
  keyinfo[4].seg[0].base.length=5;
  keyinfo[4].seg[0].base.type=HA_KEYTYPE_TEXT;
  keyinfo[4].seg[0].base.flag=0;
  keyinfo[4].seg[1].base.type=0;
  keyinfo[4].base.flag = (uint8) (pack_type ? HA_PACK_KEY : 0);
  keyinfo[5].seg[0].base.start=0;
  keyinfo[5].seg[0].base.length=4;
  keyinfo[5].seg[0].base.type=HA_KEYTYPE_TEXT;
  keyinfo[5].seg[0].base.flag=(uint8) pack_type;
  keyinfo[5].seg[1].base.type=0;
  keyinfo[5].base.flag = (uint8) (pack_type ? HA_PACK_KEY : 0);

  recinfo[0].base.type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[0].base.length=7;
  recinfo[1].base.type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[1].base.length=5;
  recinfo[2].base.type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[2].base.length=9;
  recinfo[3].base.type=FIELD_NORMAL;
  recinfo[3].base.length=STANDAR_LENGTH-7-5-9-4;
  recinfo[4].base.type=pack_fields ? FIELD_SKIP_ZERO : 0;
  recinfo[4].base.length=4;
  recinfo[5].base.type=pack_fields ? FIELD_SKIP_ENDSPACE : 0;
  recinfo[5].base.length=60;
  if (use_blob)
  {
    recinfo[6].base.type=FIELD_BLOB;
    recinfo[6].base.length=4+sizeof(char*);	/* 4 byte ptr, 4 byte length */
    recinfo[7].base.type= FIELD_LAST;
  }
  else
    recinfo[6].base.type= FIELD_LAST;

  write_count=update=dupp_keys=opt_delete=0;
  blob_buffer=0;

  for (i=999 ; i>0 ; i--) key1[i]=0;
  for (i=4999 ; i>0 ; i--) key3[i]=0;

  printf("- Creating isam-file\n");
  /*  DBUG_PUSH(""); */
  my_delete(filename,MYF(0));		/* Remove old locks under gdb */
  file= 0;
  if (nisam_create(filename,keys,&keyinfo[first_key],&recinfo[0],
		   (ulong) (rec_pointer_size ? (1L << (rec_pointer_size*8))/
			    reclength : 0),100l,0,0,0L))
    goto err;
  if (use_log)
    nisam_log(1);
  if (!(file=nisam_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
    goto err;
  printf("- Writing key:s\n");
  if (key_cacheing)
    init_key_cache(IO_SIZE*16);		/* Use a small cache */
  if (locking)
    nisam_lock_database(file,F_WRLCK);
  if (write_cacheing)
    nisam_extra(file,HA_EXTRA_WRITE_CACHE);

  for (i=0 ; i < recant ; i++)
  {
    n1=rnd(1000); n2=rnd(100); n3=rnd(5000);
    sprintf(record,"%6d:%4d:%8d:Pos: %4d    ",n1,n2,n3,write_count);
    longstore(record+STANDAR_LENGTH-4,(long) i);
    fix_length(record,(uint) STANDAR_LENGTH+rnd(60));
    put_blob_in_record(record+blob_pos,&blob_buffer);
    DBUG_PRINT("test",("record: %d",i));

    if (nisam_write(file,record))
    {
      if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
      {
	printf("Error: %d in write at record: %d\n",my_errno,i);
	goto err;
      }
      if (verbose) printf("   Double key: %d\n",n3);
    }
    else
    {
      if (key3[n3] == 1 && first_key <3 && first_key+keys >= 3)
      {
	printf("Error: Didn't get error when writing second key: '%8d'\n",n3);
	goto err;
      }
      write_count++; key1[n1]++; key3[n3]=1;
    }

    /* Check if we can find key without flushing database */
    if (i == recant/2)
    {
      for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
      if (!j)
	for (j=999 ; j>0 && key1[j] == 0 ; j--) ;
      sprintf(key,"%6d",j);
      if (nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))
      {
	printf("Test in loop: Can't find key: \"%s\"\n",key);
	goto err;
      }
    }
  }
  if (testflag==1) goto end;

  if (write_cacheing)
    if (nisam_extra(file,HA_EXTRA_NO_CACHE))
    {
      puts("got error from nisam_extra(HA_EXTRA_NO_CACHE)");
      goto end;
    }

  printf("- Delete\n");
  for (i=0 ; i<recant/10 ; i++)
  {
    for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
    if (j != 0)
    {
      sprintf(key,"%6d",j);
      if (nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))
      {
	printf("can't find key1: \"%s\"\n",key);
	goto err;
      }
      if (nisam_delete(file,read_record))
      {
	printf("error: %d; can't delete record: \"%s\"\n", my_errno,read_record);
	goto err;
      }
      opt_delete++;
      key1[atoi(read_record+keyinfo[0].seg[0].base.start)]--;
      key3[atoi(read_record+keyinfo[2].seg[0].base.start)]=0;
    }
  }
  if (testflag==2) goto end;

  printf("- Update\n");
  for (i=0 ; i<recant/10 ; i++)
  {
    n1=rnd(1000); n2=rnd(100); n3=rnd(5000);
    sprintf(record2,"%6d:%4d:%8d:XXX: %4d     ",n1,n2,n3,update);
    longstore(record2+STANDAR_LENGTH-4,(long) i);
    fix_length(record2,(uint) STANDAR_LENGTH+rnd(60));

    for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
    if (j != 0)
    {
      sprintf(key,"%6d",j);
      if (nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))
      {
	printf("can't find key1: \"%s\"\n",key);
	goto err;
      }
      if (use_blob)
      {
	if (i & 1)
	  put_blob_in_record(record+blob_pos,&blob_buffer);
	else
	  bmove(record+blob_pos,read_record+blob_pos,8);
      }
      if (nisam_update(file,read_record,record2))
      {
	if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
	{
	  printf("error: %d; can't update:\nFrom: \"%s\"\nTo:   \"%s\"\n",
		 my_errno,read_record,record2);
	  goto err;
	}
	if (verbose)
	  printf("Double key when tried to update:\nFrom: \"%s\"\nTo:   \"%s\"\n",record,record2);
      }
      else
      {
	key1[atoi(read_record+keyinfo[0].seg[0].base.start)]--;
	key3[atoi(read_record+keyinfo[2].seg[0].base.start)]=0;
	key1[n1]++; key3[n3]=1;
	update++;
      }
    }
  }
  if (testflag==3) goto end;

  printf("- Same key: first - next -> last - prev -> first\n");
  DBUG_PRINT("progpos",("first - next -> last - prev -> first"));
  for (i=999, dupp_keys=j=0 ; i>0 ; i--)
  {
    if (key1[i] >dupp_keys) { dupp_keys=key1[i]; j=i; }
  }
  sprintf(key,"%6d",j);
  if (verbose) printf("	 Using key: \"%s\"  Keys: %d\n",key,dupp_keys);
  if (nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT)) goto err;
  if (nisam_rsame(file,read_record2,-1)) goto err;
  if (memcmp(read_record,read_record2,reclength) != 0)
  {
    printf("nisam_rsame didn't find same record\n");
    goto end;
  }
  nisam_info(file,&info,0);
  if (nisam_rfirst(file,read_record2,0) ||
      nisam_rsame_with_pos(file,read_record2,0,info.recpos) ||
      memcmp(read_record,read_record2,reclength) != 0)
  {
    printf("nisam_rsame_with_pos didn't find same record\n");
    goto end;
  }
  {
    int skr=nisam_rnext(file,read_record2,0);
    if ((skr && my_errno != HA_ERR_END_OF_FILE) ||
	nisam_rprev(file,read_record2,-1) ||
	memcmp(read_record,read_record2,reclength) != 0)
    {
      printf("nisam_rsame_with_pos lost position\n");
      goto end;
    }
  }
  ant=1;
  start=keyinfo[0].seg[0].base.start; length=keyinfo[0].seg[0].base.length;
  while (nisam_rnext(file,read_record2,0) == 0 &&
	 memcmp(read_record2+start,key,length) == 0) ant++;
  if (ant != dupp_keys)
  {
    printf("next: I can only find: %d keys of %d\n",ant,dupp_keys);
    goto end;
  }
  ant=0;
  while (nisam_rprev(file,read_record3,0) == 0 &&
	 bcmp(read_record3+start,key,length) == 0) ant++;
  if (ant != dupp_keys)
  {
    printf("prev: I can only find: %d records of %d\n",ant,dupp_keys);
    goto end;
  }

  printf("- All keys: first - next -> last - prev -> first\n");
  DBUG_PRINT("progpos",("All keys: first - next -> last - prev -> first"));
  ant=1;
  if (nisam_rfirst(file,read_record,0))
  {
    printf("Can't find first record\n");
    goto end;
  }
  while (nisam_rnext(file,read_record3,0) == 0 && ant < write_count+10)
    ant++;
  if (ant != write_count - opt_delete)
  {
    printf("next: I found: %d records of %d\n",ant,write_count - opt_delete);
    goto end;
  }
  if (nisam_rlast(file,read_record2,0) ||
      bcmp(read_record2,read_record3,reclength))
  {
    printf("Can't find last record\n");
    DBUG_DUMP("record2",(byte*) read_record2,reclength);
    DBUG_DUMP("record3",(byte*) read_record3,reclength);
    goto end;
  }
  ant=1;
  while (nisam_rprev(file,read_record3,0) == 0 && ant < write_count+10)
    ant++;
  if (ant != write_count - opt_delete)
  {
    printf("prev: I found: %d records of %d\n",ant,write_count);
    goto end;
  }
  if (bcmp(read_record,read_record3,reclength))
  {
    printf("Can't find first record\n");
    goto end;
  }

  printf("- Test if: Read first - next - prev - prev - next == first\n");
  DBUG_PRINT("progpos",("- Read first - next - prev - prev - next == first"));
  if (nisam_rfirst(file,read_record,0) ||
      nisam_rnext(file,read_record3,0) ||
      nisam_rprev(file,read_record3,0) ||
      nisam_rprev(file,read_record3,0) == 0 ||
      nisam_rnext(file,read_record3,0))
      goto err;
  if (bcmp(read_record,read_record3,reclength) != 0)
     printf("Can't find first record\n");

  printf("- Test if: Read last - prev - next - next - prev == last\n");
  DBUG_PRINT("progpos",("Read last - prev - next - next - prev == last"));
  if (nisam_rlast(file,read_record2,0) ||
      nisam_rprev(file,read_record3,0) ||
      nisam_rnext(file,read_record3,0) ||
      nisam_rnext(file,read_record3,0) == 0 ||
      nisam_rprev(file,read_record3,0))
      goto err;
  if (bcmp(read_record2,read_record3,reclength))
     printf("Can't find last record\n");

  puts("- Test read key-part");
  strmov(key2,key);
  for(i=strlen(key2) ; i-- > 1 ;)
  {
    key2[i]=0;
    if (nisam_rkey(file,read_record,0,key2,(uint) i,HA_READ_KEY_EXACT)) goto err;
    if (bcmp(read_record+start,key,(uint) i))
    {
      puts("Didn't find right record");
      goto end;
    }
  }
  if (dupp_keys > 2)
  {
    printf("- Read key (first) - next - delete - next -> last\n");
    DBUG_PRINT("progpos",("first - next - delete - next -> last"));
    if (nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT)) goto err;
    if (nisam_rnext(file,read_record3,0)) goto err;
    if (nisam_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    while (nisam_rnext(file,read_record3,0) == 0 &&
	   bcmp(read_record3+start,key,length) == 0) ant++;
    if (ant != dupp_keys-1)
    {
      printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-1);
      goto end;
    }
  }
  if (dupp_keys>4)
  {
    printf("- Read last of key - prev - delete - prev -> first\n");
    DBUG_PRINT("progpos",("last - prev - delete - prev -> first"));
    if (nisam_rprev(file,read_record3,0)) goto err;
    if (nisam_rprev(file,read_record3,0)) goto err;
    if (nisam_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    while (nisam_rprev(file,read_record3,0) == 0 &&
	   bcmp(read_record3+start,key,length) == 0) ant++;
    if (ant != dupp_keys-2)
    {
      printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-2);
      goto end;
    }
  }
  if (dupp_keys > 6)
  {
    printf("- Read first - delete - next -> last\n");
    DBUG_PRINT("progpos",("first - delete - next -> last"));
    if (nisam_rkey(file,read_record3,0,key,0,HA_READ_KEY_EXACT)) goto err;
    if (nisam_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    if (nisam_rnext(file,read_record,0))
      goto err;					/* Skall finnas poster */
    while (nisam_rnext(file,read_record3,0) == 0 &&
	   bcmp(read_record3+start,key,length) == 0) ant++;
    if (ant != dupp_keys-3)
    {
      printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-3);
      goto end;
    }

    printf("- Read last - delete - prev -> first\n");
    DBUG_PRINT("progpos",("last - delete - prev -> first"));
    if (nisam_rprev(file,read_record3,0)) goto err;
    if (nisam_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=0;
    while (nisam_rprev(file,read_record3,0) == 0 &&
	   bcmp(read_record3+start,key,length) == 0) ant++;
    if (ant != dupp_keys-4)
    {
      printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-4);
      goto end;
    }
  }

  puts("- Test if: Read rrnd - same");
  DBUG_PRINT("progpos",("Read rrnd - same"));
  for (i=0 ; i < write_count ; i++)
  {
    if (nisam_rrnd(file,read_record,i == 0 ? 0L : NI_POS_ERROR) == 0)
      break;
  }
  if (i == write_count)
    goto err;

  bmove(read_record2,read_record,reclength);
  for (i=2 ; i-- > 0 ;)
  {
    if (nisam_rsame(file,read_record2,(int) i)) goto err;
    if (bcmp(read_record,read_record2,reclength) != 0)
    {
      printf("is_rsame didn't find same record\n");
      goto end;
    }
  }
  puts("- Test nisam_records_in_range");
  nisam_info(file,&info,HA_STATUS_VARIABLE);
  for (i=0 ; i < info.keys ; i++)
  {
    if (nisam_rfirst(file,read_record,(int) i) ||
	nisam_rlast(file,read_record2,(int) i))
      goto err;
    copy_key(file,(uint) i,(uchar*) read_record,(uchar*) key);
    copy_key(file,(uint) i,(uchar*) read_record2,(uchar*) key2);
    range_records=nisam_records_in_range(file,(int) i,key,0,HA_READ_KEY_EXACT,
				      key2,0,HA_READ_AFTER_KEY);
    if (range_records < info.records*8/10 ||
	range_records > info.records*12/10)
    {
      printf("ni_records_range returned %lu; Should be about %lu\n",
	     range_records,info.records);
      goto end;
    }
    if (verbose)
    {
      printf("ni_records_range returned %ld;  Exact is %ld  (diff: %4.2g %%)\n",
	     range_records,info.records,
	     labs((long) range_records - (long) info.records)*100.0/
	     info.records);

    }
  }
  for (i=0 ; i < 5 ; i++)
  {
    for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
    for (k=rnd(1000) ; k>0 && key1[k] == 0 ; k--) ;
    if (j != 0 && k != 0)
    {
      if (j > k)
	swap(int,j,k);
      sprintf(key,"%6d",j);
      sprintf(key2,"%6d",k);
      range_records=nisam_records_in_range(file,0,key,0,HA_READ_AFTER_KEY,
					key2,0,HA_READ_BEFORE_KEY);
      records=0;
      for (j++ ; j < k ; j++)
	records+=key1[j];
      if ((long) range_records < (long) records*7/10-2 ||
	  (long) range_records > (long) records*13/10+2)
      {
	printf("ni_records_range returned %ld; Should be about %ld\n",
	       range_records,records);
	goto end;
      }
      if (verbose && records)
      {
	printf("ni_records_range returned %ld;  Exact is %ld  (diff: %4.2g %%)\n",
	       range_records,records,
	       labs((long) range_records-(long) records)*100.0/records);

      }
    }
    }

  printf("- nisam_info\n");
  nisam_info(file,&info,0);
  if (info.records != write_count-opt_delete || info.deleted > opt_delete + update
      || info.keys != keys)
  {
    puts("Wrong info from nisam_info");
    printf("Got: records: %ld  opt_delete: %ld  i_keys: %d\n",
	   info.records,info.deleted,info.keys);
  }
  if (verbose)
  {
    char buff[80];
    get_date(buff,3,info.create_time);
    printf("info: Created %s\n",buff);
    get_date(buff,3,info.isamchk_time);
    printf("info: checked %s\n",buff);
    get_date(buff,3,info.update_time);
    printf("info: Modified %s\n",buff);
  }

  nisam_panic(HA_PANIC_WRITE);
  nisam_panic(HA_PANIC_READ);
  if (nisam_is_changed(file))
    puts("Warning: nisam_is_changed reported that datafile was changed");

  printf("- nisam_extra(CACHE) + nisam_rrnd.... + nisam_extra(NO_CACHE)\n");
  if (nisam_extra(file,HA_EXTRA_RESET) || nisam_extra(file,HA_EXTRA_CACHE))
  {
    if (locking || (!use_blob && !pack_fields))
    {
      puts("got error from nisam_extra(HA_EXTRA_CACHE)");
      goto end;
    }
  }
  ant=0;
  while ((error=nisam_rrnd(file,record,NI_POS_ERROR)) >= 0 &&
	 ant < write_count + 10)
	ant+= error ? 0 : 1;
  if (ant != write_count-opt_delete)
  {
    printf("rrnd with cache: I can only find: %d records of %d\n",
	   ant,write_count-opt_delete);
    goto end;
  }
  if (nisam_extra(file,HA_EXTRA_NO_CACHE))
  {
    puts("got error from nisam_extra(HA_EXTRA_NO_CACHE)");
    goto end;
  }

  if (testflag == 4) goto end;

  printf("- Removing keys\n");
  lastpos = NI_POS_ERROR;
  /* DBUG_POP(); */
  nisam_extra(file,HA_EXTRA_RESET);
  while ((error=nisam_rrnd(file,read_record,NI_POS_ERROR)) >=0)
  {
    nisam_info(file,&info,1);
    if (lastpos >= info.recpos && lastpos != NI_POS_ERROR)
    {
      printf("nisam_rrnd didn't advance filepointer; old: %ld, new: %ld\n",
	     lastpos,info.recpos);
      goto err;
    }
    lastpos=info.recpos;
    if (error == 0)
    {
      if (nisam_rsame(file,read_record,-1))
      {
	printf("can't find record %lx\n",info.recpos);
	goto err;
      }
      if (use_blob)
      {
	ulong blob_length,pos;
	uchar *ptr;
	longget(blob_length,read_record+blob_pos+4);
	ptr=(uchar*) blob_length;
	longget(blob_length,read_record+blob_pos);
	for (pos=0 ; pos < blob_length ; pos++)
	{
	  if (ptr[pos] != (uchar) (blob_length+pos))
	  {
	    printf("found blob with wrong info at %ld\n",lastpos);
	    use_blob=0;
	    break;
	  }
	}
      }
      if (nisam_delete(file,read_record))
      {
	printf("can't delete record: %s\n",read_record);
	goto err;
      }
      opt_delete++;
    }
  }
  if (my_errno != HA_ERR_END_OF_FILE && my_errno != HA_ERR_RECORD_DELETED)
    printf("error: %d from nisam_rrnd\n",my_errno);
  if (write_count != opt_delete)
  {
    printf("Deleted only %d of %d records\n",write_count,opt_delete);
    goto err;
  }
end:
  if (nisam_close(file))
    goto err;
  nisam_panic(HA_PANIC_CLOSE);			/* Should close log */
  printf("\nFollowing test have been made:\n");
  printf("Write records: %d\nUpdate records: %d\nSame-key-read: %d\nDelete records: %d\n", write_count,update,dupp_keys,opt_delete);
  if (rec_pointer_size)
    printf("Record pointer size: %d\n",rec_pointer_size);
  if (key_cacheing)
    puts("Key cacheing used");
  if (write_cacheing)
    puts("Write cacheing used");
  if (async_io && locking)
    puts("Asyncron io with locking used");
  else if (locking)
    puts("Locking used");
  if (use_blob)
    puts("blobs used");
  end_key_cache();
  if (blob_buffer)
    my_free(blob_buffer,MYF(0));
  my_end(MY_CHECK_ERROR | MY_GIVE_INFO);
  return(0);
err:
  printf("got error: %d when using NISAM-database\n",my_errno);
  if (file)
    VOID(nisam_close(file));
  return(1);
} /* main */
Ejemplo n.º 21
0
int main(int argc, char **argv)
{
  char self_name[FN_REFLEN];

  MY_INIT(argv[0]);

#if __WIN__
  if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
#endif
  {
    strncpy(self_name, argv[0], FN_REFLEN);
  }

  if (init_dynamic_string(&ds_args, "", 512, 256) ||
      init_dynamic_string(&conn_args, "", 512, 256))
    die("Out of memory");

  if (load_defaults("my", load_default_groups, &argc, &argv))
    die(NULL);
  defaults_argv= argv; /* Must be freed by 'free_defaults' */

  if (handle_options(&argc, &argv, my_long_options, get_one_option))
    die(NULL);
  if (debug_info_flag)
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
  if (debug_check_flag)
    my_end_arg= MY_CHECK_ERROR;

  if (tty_password)
  {
    opt_password= get_tty_password(NullS);
    /* add password to defaults file */
    dynstr_append_os_quoted(&ds_args, "--password="******" ");
  }
  /* add user to defaults file */
  dynstr_append_os_quoted(&ds_args, "--user="******" ");

  /* Find mysql */
  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);

  /* Find mysqlcheck */
  find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);

  if (opt_systables_only && !opt_silent)
    printf("The --upgrade-system-tables option was used, user tables won't be touched.\n");


  /*
    Read the mysql_upgrade_info file to check if mysql_upgrade
    already has been run for this installation of MySQL
  */
  if (!opt_force && upgrade_already_done())
  {
    printf("This installation of MySQL is already upgraded to %s, "
           "use --force if you still need to run mysql_upgrade\n",
           MYSQL_SERVER_VERSION);
    goto end;
  }

  if (opt_version_check && check_version_match())
    die("Upgrade failed");

  upgrade_from_mysql= is_mysql();

  /*
    Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
  */
  if (run_mysqlcheck_upgrade(TRUE) ||
      run_mysqlcheck_views() ||
      run_sql_fix_privilege_tables() ||
      run_mysqlcheck_fixnames() ||
      run_mysqlcheck_upgrade(FALSE))
    die("Upgrade failed" );

  verbose("Phase %d/%d: Running 'FLUSH PRIVILEGES'", ++phase, phases_total);
  if (run_query("FLUSH PRIVILEGES", NULL, TRUE))
    die("Upgrade failed" );

  verbose("OK");

  /* Create a file indicating upgrade has been performed */
  create_mysql_upgrade_info_file();

  DBUG_ASSERT(phase == phases_total);

end:
  free_used_memory();
  my_end(my_end_arg);
  exit(0);
}
Ejemplo n.º 22
0
int main(int argc, char **argv)
{
  char self_name[FN_REFLEN];

  MY_INIT(argv[0]);

#if __WIN__
  if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
#endif
  {
    strncpy(self_name, argv[0], FN_REFLEN);
  }

  if (init_dynamic_string(&ds_args, "", 512, 256) ||
      init_dynamic_string(&conn_args, "", 512, 256))
    die("Out of memory");

  if (load_defaults("my", load_default_groups, &argc, &argv))
    die(NULL);
  defaults_argv= argv; /* Must be freed by 'free_defaults' */

  if (handle_options(&argc, &argv, my_long_options, get_one_option))
    die(NULL);
  if (debug_info_flag)
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
  if (debug_check_flag)
    my_end_arg= MY_CHECK_ERROR;

  if (tty_password)
  {
    opt_password= get_tty_password(NullS);
    /* add password to defaults file */
    dynstr_append_os_quoted(&ds_args, "--password="******" ");
  }
  /* add user to defaults file */
  dynstr_append_os_quoted(&ds_args, "--user="******" ");

  /* Find mysql */
  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);

  if (!opt_systables_only)
  {
    /* Find mysqlcheck */
    find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);
  }
  else
  {
    if (!opt_silent)
      printf("The --upgrade-system-tables option was used, databases won't be touched.\n");
  }

  /*
    Read the mysql_upgrade_info file to check if mysql_upgrade
    already has been run for this installation of MySQL
  */
  if (!opt_force && upgrade_already_done())
  {
    printf("This installation of MySQL is already upgraded to %s, "
           "use --force if you still need to run mysql_upgrade\n",
           MYSQL_SERVER_VERSION);
    die(NULL);
  }

  if (opt_version_check && check_version_match())
    die("Upgrade failed");

  /*
    Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
  */
  if ((!opt_systables_only &&
       (run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) ||
      run_sql_fix_privilege_tables())
  {
    /*
      The upgrade failed to complete in some way or another,
      significant error message should have been printed to the screen
    */
    die("Upgrade failed" );
  }
  verbose("OK");

  /* Create a file indicating upgrade has been performed */
  create_mysql_upgrade_info_file();

  free_used_memory();
  my_end(my_end_arg);
  exit(0);
}
Ejemplo n.º 23
0
int main(int argc __attribute__((unused)), char **argv)
{
  uint i;
  char *big_string= (char *)malloc(1024*1024);

  MY_INIT(argv[0]);
  plan(68);

  if (!big_string)
    exit(1);
  for (i= 0; i < 1024*1024; i++)
    big_string[i]= ('0' + (i % 10));
  test_value_single_null();
  test_value_single_uint(0, "0");
  test_value_single_uint(0xffffffffffffffffULL, "0xffffffffffffffff");
  test_value_single_uint(0xaaaaaaaaaaaaaaaaULL, "0xaaaaaaaaaaaaaaaa");
  test_value_single_uint(0x5555555555555555ULL, "0x5555555555555555");
  test_value_single_uint(27652, "27652");
  test_value_single_sint(0, "0");
  test_value_single_sint(1, "1");
  test_value_single_sint(-1, "-1");
  test_value_single_sint(0x7fffffffffffffffLL, "0x7fffffffffffffff");
  test_value_single_sint(0xaaaaaaaaaaaaaaaaLL, "0xaaaaaaaaaaaaaaaa");
  test_value_single_sint(0x5555555555555555LL, "0x5555555555555555");
  test_value_single_sint(0x8000000000000000LL, "0x8000000000000000");
  test_value_single_double(0.0, "0.0");
  test_value_single_double(1.0, "1.0");
  test_value_single_double(-1.0, "-1.0");
  test_value_single_double(1.0e100, "1.0e100");
  test_value_single_double(1.0e-100, "1.0e-100");
  test_value_single_double(9999999999999999999999999999999999999.0,
                           "9999999999999999999999999999999999999.0");
  test_value_single_double(-9999999999999999999999999999999999999.0,
                           "-9999999999999999999999999999999999999.0");
  test_value_single_decimal("0");
  test_value_single_decimal("1");
  test_value_single_decimal("-1");
  test_value_single_decimal("9999999999999999999999999999999");
  test_value_single_decimal("-9999999999999999999999999999999");
  test_value_single_decimal("0.9999999999999999999999999999999");
  test_value_single_decimal("-0.9999999999999999999999999999999");
  test_value_single_string("", 0, charset_list[0]);
  test_value_single_string("", 1, charset_list[0]);
  test_value_single_string("1234567890", 11, charset_list[0]);
  test_value_single_string("nulls\0\0\0\0\0", 10, charset_list[0]);
  sprintf(big_string, "%x", 0x7a);
  test_value_single_string(big_string, 0x7a, charset_list[0]);
  sprintf(big_string, "%x", 0x80);
  test_value_single_string(big_string, 0x80, charset_list[0]);
  sprintf(big_string, "%x", 0x7ffa);
  test_value_single_string(big_string, 0x7ffa, charset_list[0]);
  sprintf(big_string, "%x", 0x8000);
  test_value_single_string(big_string, 0x8000, charset_list[0]);
  sprintf(big_string, "%x", 1024*1024);
  test_value_single_string(big_string, 1024*1024, charset_list[0]);
  test_value_single_date(0, 0, 0, "zero date");
  test_value_single_date(9999, 12, 31, "max date");
  test_value_single_date(2011, 3, 26, "some date");
  test_value_single_time(0, 0, 0, 0, 0, "zero time");
  test_value_single_time(1, 23, 59, 59, 999999, "min time");
  test_value_single_time(0, 23, 59, 59, 999999, "max time");
  test_value_single_time(0, 21, 36, 20, 28, "some time");
  test_value_single_datetime(0, 0, 0, 0, 0, 0, 0, 0, "zero datetime");
  test_value_single_datetime(1, 9999, 12, 31, 23, 59, 59, 999999,
                             "min datetime");
  test_value_single_datetime(0, 9999, 12, 31, 23, 59, 59, 999999,
                             "max datetime");
  test_value_single_datetime(0, 2011, 3, 26, 21, 53, 12, 3445,
                             "some datetime");
  {
    uint column_numbers[]= {100,1,2,3,4,5,6,7,8};
    test_value_multi(0, 0, 0.0, "0",
                     "", 0, charset_list[0],
                     0, 0, 0,
                     0, 0, 0, 0, 0,
                     0, 0, 0, 0, 0, 0, 0, 0,
                     column_numbers,
                     "zero data");
  }
  {
    uint column_numbers[]= {10,1,12,37,4,57,6,76,87};
    test_value_multi(0xffffffffffffffffULL, 0x7fffffffffffffffLL,
                     99999999.999e120, "9999999999999999999999999999999",
                     big_string, 1024*1024, charset_list[0],
                     9999, 12, 31,
                     0, 23, 59, 59, 999999,
                     0, 9999, 12, 31, 23, 59, 59, 999999,
                     column_numbers,
                     "much data");
  }
  free(big_string);
  {
    uint column_numbers[]= {101,12,122,37,24,572,16,726,77};
    test_value_multi(37878, -3344,
                     2873.3874, "92743.238984789898",
                     "string", 6, charset_list[0],
                     2011, 3, 26,
                     1, 23, 23, 20, 333,
                     0, 2011, 3, 26, 23, 23, 53, 334,
                     column_numbers,
                     "zero data");
  }
  test_value_multi_same_num();
  {
    uint column_numbers[]= {1,2,3,4,5,6,7,2, 3, 4};
    uint column_values[]=  {1,2,3,4,5,6,7,0,30,40};
    my_bool null_values[]= {0,0,0,0,0,0,0,1, 0, 0};

    test_update_multi(column_numbers, column_values, null_values, 7, 10);
  }
  {
    uint column_numbers[]= {4,3,2,1, 1,2,3,4};
    uint column_values[]=  {4,3,2,1, 0,0,0,0};
    my_bool null_values[]= {0,0,0,0, 1,1,1,1};

    test_update_multi(column_numbers, column_values, null_values, 4, 8);
  }
  {
    uint column_numbers[]= {4,3,2,1, 4,3,2,1};
    uint column_values[]=  {4,3,2,1, 0,0,0,0};
    my_bool null_values[]= {0,0,0,0, 1,1,1,1};

    test_update_multi(column_numbers, column_values, null_values, 4, 8);
  }
  test_empty_string();
  {
    uint column_numbers[]= {1, 2, 3};
    uint column_values[]=  {1, 2, 3};
    uint update_numbers[]= {4, 3, 2, 1};
    uint update_values[]=  {40,30, 0,10};
    my_bool update_nulls[]={0, 0, 1, 0};
    uint result_numbers[]= {1, 3, 4};
    uint result_values[]=  {10,30,40};
    test_update_many(column_numbers, column_values, 3,
                     update_numbers, update_values, update_nulls, 4,
                     result_numbers, result_values, 3);
  }
  test_mdev_4994();
  test_mdev_4995();
  test_mdev_9773();

  my_end(0);
  return exit_status();
}
Ejemplo n.º 24
0
int main(int argc, char **argv)
{
  int error;
  my_bool first_argument_uses_wildcards=0;
  char *wild;
  MYSQL mysql;
  MY_INIT(argv[0]);
  sf_leaking_memory=1; /* don't report memory leaks on early exits */
  if (load_defaults("my",load_default_groups,&argc,&argv))
    exit(1);

  get_options(&argc,&argv);

  sf_leaking_memory=0; /* from now on we cleanup properly */
  wild=0;
  if (argc)
  {
    char *pos= argv[argc-1], *to;
    for (to= pos ; *pos ; pos++, to++)
    {
      switch (*pos) {
      case '*':
	*pos= '%';
	first_argument_uses_wildcards= 1;
	break;
      case '?':
	*pos= '_';
	first_argument_uses_wildcards= 1;
	break;
      case '%':
      case '_':
	first_argument_uses_wildcards= 1;
	break;
      case '\\':
	pos++;
      default: break;
      }
      *to= *pos;
    }    
    *to= *pos; /* just to copy a '\0'  if '\\' was used */
  }
  if (first_argument_uses_wildcards)
    wild= argv[--argc];
  else if (argc == 3)			/* We only want one field */
    wild= argv[--argc];

  if (argc > 2)
  {
    fprintf(stderr,"%s: Too many arguments\n",my_progname);
    exit(1);
  }
  mysql_init(&mysql);
  if (opt_compress)
    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
#ifdef HAVE_OPENSSL
  if (opt_use_ssl)
    mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
		  opt_ssl_capath, opt_ssl_cipher);
  mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
                (char*)&opt_ssl_verify_server_cert);
#endif
  if (opt_protocol)
    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
#ifdef HAVE_SMEM
  if (shared_memory_base_name)
    mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
  mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);

  if (opt_plugin_dir && *opt_plugin_dir)
    mysql_options(&mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);

  if (opt_default_auth && *opt_default_auth)
    mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);

  if (!(mysql_real_connect(&mysql,host,user,opt_password,
			   (first_argument_uses_wildcards) ? "" :
                           argv[0],opt_mysql_port,opt_mysql_unix_port,
			   0)))
  {
    fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
    exit(1);
  }
  mysql.reconnect= 1;

  switch (argc) {
  case 0:  error=list_dbs(&mysql,wild); break;
  case 1:
    if (opt_status)
      error=list_table_status(&mysql,argv[0],wild);
    else
      error=list_tables(&mysql,argv[0],wild);
    break;
  default:
    if (opt_status && ! wild)
      error=list_table_status(&mysql,argv[0],argv[1]);
    else
      error=list_fields(&mysql,argv[0],argv[1],wild);
    break;
  }
  mysql_close(&mysql);			/* Close & free connection */
  my_free(opt_password);
#ifdef HAVE_SMEM
  my_free(shared_memory_base_name);
#endif
  my_end(my_end_arg);
  exit(error ? 1 : 0);
  return 0;				/* No compiler warnings */
}
Ejemplo n.º 25
0
int main(int argc __attribute__((unused)), char **argv)
{
  int i;
  MY_INIT(argv[0]);

  my_init();
  pthread_mutex_init(&rt_mutex, 0);

  plan(40);

  if (my_atomic_initialize())
    return exit_status();


  tablockman_init(&tablockman, &loid2lo1, 50);

  for (i= 0; i < Nlos; i++)
  {
    pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
    pthread_cond_init (&conds[i], 0);

    loarray1[i].active_locks= 0;
    loarray1[i].waiting_lock= 0;
    loarray1[i].waiting_for= 0;
    loarray1[i].mutex= &mutexes[i];
    loarray1[i].cond= &conds[i];
    loarray1[i].loid= i+1;
  }

  for (i= 0; i < Ntbls; i++)
  {
    tablockman_init_locked_table(ltarray+i, Nlos);
  }

  test_tablockman_simple();

#define CYCLES 10000
#define THREADS Nlos /* don't change this line */

  /* mixed load, stress-test with random locks */
  Nrows= 100;
  Ntables= 10;
  table_lock_ratio= 10;
  run_test("\"random lock\" stress test", test_lockman, THREADS, CYCLES);
#if 0
  /* "real-life" simulation - many rows, no table locks */
  Nrows= 1000000;
  Ntables= 10;
  table_lock_ratio= 0;
  run_test("\"real-life\" simulation test", test_lockman, THREADS, CYCLES*10);
#endif
  for (i= 0; i < Nlos; i++)
  {
    tablockman_release_locks(&tablockman, &loarray1[i]);
    pthread_mutex_destroy(loarray1[i].mutex);
    pthread_cond_destroy(loarray1[i].cond);
  }

  {
    ulonglong now= my_getsystime();
    for (i= 0; i < Ntbls; i++)
    {
      tablockman_destroy_locked_table(ltarray+i);
    }
    tablockman_destroy(&tablockman);
    now= my_getsystime()-now;
    diag("lockman_destroy: %g secs", ((double)now)/1e7);
  }

  pthread_mutex_destroy(&rt_mutex);
  my_end(0);
  return exit_status();
}
Ejemplo n.º 26
0
void
ndb_end(int flags)
{
  my_end(flags);
}
Ejemplo n.º 27
0
int 
run_test(const char *filename)
{
	MI_INFO        *file;
	int		i         , j, error, deleted, rec_length, uniques = 0;
	ha_rows		found , row_count;
	my_off_t	pos;
	char		record    [MAX_REC_LENGTH], key[MAX_REC_LENGTH], read_record[MAX_REC_LENGTH];
	MI_UNIQUEDEF	uniquedef;
	MI_CREATE_INFO	create_info;

	bzero((char *)recinfo, sizeof(recinfo));

	/* First define 2 columns */
	recinfo[0].type = FIELD_NORMAL;
	recinfo[0].length = 1;	/* For NULL bits */
	recinfo[1].type = key_field;
	recinfo[1].length = (key_field == FIELD_BLOB ? 4 + mi_portable_sizeof_char_ptr :
			     key_length);
	if (key_field == FIELD_VARCHAR)
		recinfo[1].length += 2;
	recinfo[2].type = extra_field;
	recinfo[2].length = (extra_field == FIELD_BLOB ? 4 + mi_portable_sizeof_char_ptr : 24);
	if (extra_field == FIELD_VARCHAR)
		recinfo[2].length += 2;
	if (opt_unique) {
		recinfo[3].type = FIELD_CHECK;
		recinfo[3].length = MI_UNIQUE_HASH_LENGTH;
	}
	rec_length = recinfo[0].length + recinfo[1].length + recinfo[2].length +
		recinfo[3].length;


	/* Define a key over the first column */
	keyinfo[0].seg = keyseg;
	keyinfo[0].keysegs = 1;
	keyinfo[0].seg[0].type = key_type;
	keyinfo[0].seg[0].flag = pack_seg;
	keyinfo[0].seg[0].start = 1;
	keyinfo[0].seg[0].length = key_length;
	keyinfo[0].seg[0].null_bit = null_fields ? 2 : 0;
	keyinfo[0].seg[0].null_pos = 0;
	keyinfo[0].seg[0].language = MY_CHARSET_CURRENT;
	if (pack_seg & HA_BLOB_PART) {
		keyinfo[0].seg[0].bit_start = 4;	/* Length of blob length */
	}
	keyinfo[0].flag = (uint8) (pack_keys | unique_key);

	bzero((byte *) flags, sizeof(flags));
	if (opt_unique) {
		uint		start;
		uniques = 1;
		bzero((char *)&uniquedef, sizeof(uniquedef));
		bzero((char *)uniqueseg, sizeof(uniqueseg));
		uniquedef.seg = uniqueseg;
		uniquedef.keysegs = 2;

		/* Make a unique over all columns (except first NULL fields) */
		for (i = 0, start = 1; i < 2; i++) {
			uniqueseg[i].start = start;
			start += recinfo[i + 1].length;
			uniqueseg[i].length = recinfo[i + 1].length;
			uniqueseg[i].language = MY_CHARSET_CURRENT;
		}
		uniqueseg[0].type = key_type;
		uniqueseg[0].null_bit = null_fields ? 2 : 0;
		uniqueseg[1].type = HA_KEYTYPE_TEXT;
		if (extra_field == FIELD_BLOB) {
			uniqueseg[1].length = 0;	/* The whole blob */
			uniqueseg[1].bit_start = 4;	/* long blob */
			uniqueseg[1].flag |= HA_BLOB_PART;
		} else if (extra_field == FIELD_VARCHAR)
			uniqueseg[1].flag |= HA_VAR_LENGTH;
	} else
		uniques = 0;

	if (!silent)
		printf("- Creating isam-file\n");
	bzero((char *)&create_info, sizeof(create_info));
	create_info.max_rows = (ulong) (rec_pointer_size ?
					(1L << (rec_pointer_size * 8)) / 40 :
					0);
	if (mi_create(filename, 1, keyinfo, 3 + opt_unique, recinfo,
		      uniques, &uniquedef, &create_info,
		      create_flag))
		goto err;
	if (!(file = mi_open(filename, 2, HA_OPEN_ABORT_IF_LOCKED)))
		goto err;
	if (!silent)
		printf("- Writing key:s\n");

	my_errno = 0;
	row_count = deleted = 0;
	for (i = 49; i >= 1; i -= 2) {
		if (insert_count-- == 0) {
			VOID(mi_close(file));
			exit(0);
		}
		j = i % 25 + 1;
		create_record(record, j);
		error = mi_write(file, record);
		if (!error)
			row_count++;
		flags[j] = 1;
		if (verbose || error)
			printf("J= %2d  mi_write: %d  errno: %d\n", j, error, my_errno);
	}

	/* Insert 2 rows with null values */
	if (null_fields) {
		create_record(record, 0);
		error = mi_write(file, record);
		if (!error)
			row_count++;
		if (verbose || error)
			printf("J= NULL  mi_write: %d  errno: %d\n", error, my_errno);
		error = mi_write(file, record);
		if (!error)
			row_count++;
		if (verbose || error)
			printf("J= NULL  mi_write: %d  errno: %d\n", error, my_errno);
		flags[0] = 2;
	}
	if (!skip_update) {
		if (opt_unique) {
			if (!silent)
				printf("- Checking unique constraint\n");
			create_record(record, j);
			if (!mi_write(file, record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE) {
				printf("unique check failed\n");
			}
		}
		if (!silent)
			printf("- Updating rows\n");

		/* Update first last row to force extend of file */
		if (mi_rsame(file, read_record, -1)) {
			printf("Can't find last row with mi_rsame\n");
		} else {
			memcpy(record, read_record, rec_length);
			update_record(record);
			if (mi_update(file, read_record, record)) {
				printf("Can't update last row: %.*s\n",
				 keyinfo[0].seg[0].length, read_record + 1);
			}
		}

		/* Read through all rows and update them */
		pos = (my_off_t) 0;
		found = 0;
		while ((error = mi_rrnd(file, read_record, pos)) == 0) {
			if (update_count-- == 0) {
				VOID(mi_close(file));
				exit(0);
			}
			memcpy(record, read_record, rec_length);
			update_record(record);
			if (mi_update(file, read_record, record)) {
				printf("Can't update row: %.*s, error: %d\n",
				       keyinfo[0].seg[0].length, record + 1, my_errno);
			}
			found++;
			pos = HA_OFFSET_ERROR;
		}
		if (found != row_count)
			printf("Found %ld of %ld rows\n", found, row_count);
	}
	if (!silent)
		printf("- Reopening file\n");
	if (mi_close(file))
		goto err;
	if (!(file = mi_open(filename, 2, HA_OPEN_ABORT_IF_LOCKED)))
		goto err;
	if (!skip_update) {
		if (!silent)
			printf("- Removing keys\n");

		for (i = 0; i <= 10; i++) {
			/* testing */
			if (remove_count-- == 0) {
				VOID(mi_close(file));
				exit(0);
			}
			j = i * 2;
			if (!flags[j])
				continue;
			create_key(key, j);
			my_errno = 0;
			if ((error = mi_rkey(file, read_record, 0, key, 0, HA_READ_KEY_EXACT))) {
				if (verbose || (flags[j] >= 1 ||
				(error && my_errno != HA_ERR_KEY_NOT_FOUND)))
					printf("key: '%.*s'  mi_rkey:  %3d  errno: %3d\n",
					       (int)key_length, key + test(null_fields), error, my_errno);
			} else {
				error = mi_delete(file, read_record);
				if (verbose || error)
					printf("key: '%.*s'  mi_delete: %3d  errno: %3d\n",
					       (int)key_length, key + test(null_fields), error, my_errno);
				if (!error) {
					deleted++;
					flags[j]--;
				}
			}
		}
	}
	if (!silent)
		printf("- Reading rows with key\n");
	for (i = 0; i <= 25; i++) {
		create_key(key, i);
		my_errno = 0;
		error = mi_rkey(file, read_record, 0, key, 0, HA_READ_KEY_EXACT);
		if (verbose ||
		    (error == 0 && flags[i] == 0 && unique_key) ||
		    (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND))) {
			printf("key: '%.*s'  mi_rkey: %3d  errno: %3d  record: %s\n",
			       (int)key_length, key + test(null_fields), error, my_errno, record + 1);
		}
	}

	if (!silent)
		printf("- Reading rows with position\n");
	for (i = 1, found = 0; i <= 30; i++) {
		my_errno = 0;
		if ((error = mi_rrnd(file, read_record, i == 1 ? 0L : HA_OFFSET_ERROR)) == -1) {
			if (found != row_count - deleted)
				printf("Found only %ld of %ld rows\n", found, row_count - deleted);
			break;
		}
		if (!error)
			found++;
		if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED &&
				error != HA_ERR_END_OF_FILE)) {
			printf("pos: %2d  mi_rrnd: %3d  errno: %3d  record: %s\n",
			       i - 1, error, my_errno, read_record + 1);
		}
	}
	if (mi_close(file))
		goto err;
	my_end(MY_CHECK_ERROR);

	return (0);
err:
	printf("got error: %3d when using myisam-database\n", my_errno);
	return 1;		/* skipp warning */
}
int main(int argc __attribute__((unused)), char *argv[])
{
  ulong i;
  uint pagen;
  uchar long_tr_id[6];
  PAGECACHE pagecache;
  LSN lsn;
  LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
  uchar *long_buffer= malloc(LONG_BUFFER_SIZE);

  MY_INIT(argv[0]);

  plan(4);

  bzero(&pagecache, sizeof(pagecache));
  bzero(long_buffer, LONG_BUFFER_SIZE);
  maria_data_root= create_tmpdir(argv[0]);
  if (maria_log_remove(0))
    exit(1);

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

  if (ma_control_file_open(TRUE, TRUE))
  {
    fprintf(stderr, "Can't init control file (%d)\n", errno);
    exit(1);
  }
  if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
                             PCACHE_PAGE, 0, 0)) == 0)
  {
    fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
    exit(1);
  }
  if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache,
                               LOG_FLAGS, 0, &translog_example_table_init,
                               0))
  {
    fprintf(stderr, "Can't init loghandler (%d)\n", errno);
    exit(1);
  }
  /* Suppressing of automatic record writing */
  dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;

  /* write more then 1 file */
  int4store(long_tr_id, 0);
  parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
  if (translog_write_record(&lsn,
                            LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
                            &dummy_transaction_object, NULL, 6,
                            TRANSLOG_INTERNAL_PARTS + 1,
                            parts, NULL, NULL))
  {
    fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
    translog_destroy();
    exit(1);
  }

  translog_purge(lsn);
  if (!translog_is_file(1))
  {
    fprintf(stderr, "First file was removed after first record\n");
    translog_destroy();
    exit(1);
  }
  ok(1, "First is not removed");

  for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++)
  {
    if (translog_write_record(&lsn,
                              LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
                              &dummy_transaction_object, NULL, 6,
                              TRANSLOG_INTERNAL_PARTS + 1,
                              parts, NULL, NULL))
    {
      fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
      translog_destroy();
      exit(1);
    }
  }

  translog_purge(lsn);
  if (translog_is_file(1))
  {
    fprintf(stderr, "First file was not removed.\n");
    translog_destroy();
    exit(1);
  }

  ok(1, "First file is removed");

  parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_buffer;
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= LONG_BUFFER_SIZE;
  if (translog_write_record(&lsn,
			    LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE,
			    &dummy_transaction_object, NULL, LONG_BUFFER_SIZE,
			    TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
  {
    fprintf(stderr, "Can't write variable record\n");
    translog_destroy();
    exit(1);
  }

  translog_purge(lsn);
  if (!translog_is_file(2) || !translog_is_file(3))
  {
    fprintf(stderr, "Second file (%d) or third file (%d) is not present.\n",
	    translog_is_file(2), translog_is_file(3));
    translog_destroy();
    exit(1);
  }

  ok(1, "Second and third files are not removed");

  int4store(long_tr_id, 0);
  parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
  if (translog_write_record(&lsn,
                            LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
                            &dummy_transaction_object, NULL, 6,
                            TRANSLOG_INTERNAL_PARTS + 1,
                            parts, NULL, NULL))
  {
    fprintf(stderr, "Can't write last record\n");
    translog_destroy();
    exit(1);
  }

  translog_purge(lsn);
  if (translog_is_file(2))
  {
    fprintf(stderr, "Second file is not removed\n");
    translog_destroy();
    exit(1);
  }

  ok(1, "Second file is removed");

  translog_destroy();
  end_pagecache(&pagecache, 1);
  ma_control_file_end();
  if (maria_log_remove(maria_data_root))
    exit(1);

  my_uuid_end();
  my_free_open_file_info();
  my_end(0);

  exit(0);
}
Ejemplo n.º 29
0
void cleanup_and_exit(int exit_code)
{
  my_end(0);
  exit(exit_code);
}
Ejemplo n.º 30
0
void my_exit(int c)
{
  my_end(0);
  exit(c);
}