Exemplo n.º 1
0
void start_test(int id)
{
  uint i;
  int error,lock_type;
  MI_ISAMINFO isam_info;
  MI_INFO *file,*file1,*file2=0,*lock;

  if (use_log)
    mi_log(1);
  if (!(file1=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)) ||
      !(file2=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)))
  {
    fprintf(stderr,"Can't open isam-file: %s\n",filename);
    exit(1);
  }
  if (key_cacheing && rnd(2) == 0)
    init_key_cache(dflt_key_cache, KEY_CACHE_BLOCK_SIZE, 65536L, 0, 0);
  printf("Process %d, pid: %d\n",id,getpid()); fflush(stdout);

  for (error=i=0 ; i < tests && !error; i++)
  {
    file= (rnd(2) == 1) ? file1 : file2;
    lock=0 ; lock_type=0;
    if (rnd(10) == 0)
    {
      if (mi_lock_database(lock=(rnd(2) ? file1 : file2),
			   lock_type=(rnd(2) == 0 ? F_RDLCK : F_WRLCK)))
      {
	fprintf(stderr,"%2d: start: Can't lock table %d\n",id,my_errno);
	error=1;
	break;
      }
    }
    switch (rnd(4)) {
    case 0: error=test_read(file,id); break;
    case 1: error=test_rrnd(file,id); break;
    case 2: error=test_write(file,id,lock_type); break;
    case 3: error=test_update(file,id,lock_type); break;
    }
    if (lock)
      mi_lock_database(lock,F_UNLCK);
  }
  if (!error)
  {
    mi_status(file1,&isam_info,HA_STATUS_VARIABLE);
    printf("%2d: End of test.  Records:  %ld  Deleted:  %ld\n",
	   id,(long) isam_info.records, (long) isam_info.deleted);
    fflush(stdout);
  }

  mi_close(file1);
  mi_close(file2);
  if (use_log)
    mi_log(0);
  if (error)
  {
    printf("%2d: Aborted\n",id); fflush(stdout);
    exit(1);
  }
}
Exemplo n.º 2
0
Arquivo: mi-out.c Projeto: 0mp/freebsd
void
mi_table_end (struct ui_out *uiout)
{
  mi_out_data *data = ui_out_data (uiout);
  data->suppress_output = 0;
  mi_close (uiout, ui_out_type_list); /* body */
  mi_close (uiout, ui_out_type_tuple);
}
Exemplo n.º 3
0
void
mi_table_end (struct ui_out *uiout)
{
  struct ui_out_data *data = ui_out_data (uiout);
  data->suppress_output = 0;
  if (data->mi_version == 0)
    {
      mi_close (uiout, ui_out_type_tuple);
      return;
    }
  mi_close (uiout, ui_out_type_list); /* body */
  mi_close (uiout, ui_out_type_tuple);
}
Exemplo n.º 4
0
// Close all the connections in the connection pool
// Release the resources used by connection pool
void tm_close_conn_pool (void)
{
	unsigned int i;
	
	for (i = 0; i < MAX_THREADS; i++)
	{
		mi_close (tm_own_connpool_1[i].db_connection);	
		mi_close (tm_own_connpool_2[i].db_connection);			
	}
	for (i = 0; i < MAX_CONNECTION; i++)
	{
		mi_close (tm_common_connpool[i].db_connection);
	}
	DeleteCriticalSection (&conn_pool_lock);
}
Exemplo n.º 5
0
/*
   Cleaner's job is to delete all the processed tokens from the update queue table
   and from the main memory global cleanup queue. It sleeps for some time to allow
   the movers and doers to do some work so that it will have work to do when it wakes up
 */
DWORD WINAPI cleaner(LPVOID ptr)
{
#if !defined _MIDDLE
    MI_CONNECTION *conn = NULL;
    conn = startup();
#endif

    while (!g_fTerminate)
    {
        Sleep(SLEEP_CLEANER_PERIOD);

        // Lock the mutex so that the cleaner and the movers are not
        // active at the same time
        EnterCriticalSection(&mover_cleaner_mutex);

#ifdef _MIDDLE
        vl_cleanup_tasks();
#else
        execUDR(conn,"execute procedure vl_cleanup_tasks();");
#endif
        LeaveCriticalSection(&mover_cleaner_mutex);
    }

#if !defined _MIDDLE
    mi_close(conn);
#endif

    return 1;
}
Exemplo n.º 6
0
int mi_panic(enum ha_panic_function flag)
{
  int error=0;
  LIST *list_element,*next_open;
  MI_INFO *info;
  DBUG_ENTER("mi_panic");

  mysql_mutex_lock(&THR_LOCK_myisam);
  for (list_element=myisam_open_list ; list_element ; list_element=next_open)
  {
    next_open=list_element->next;		/* Save if close */
    info=(MI_INFO*) list_element->data;
    switch (flag) {
    case HA_PANIC_CLOSE:
      mysql_mutex_unlock(&THR_LOCK_myisam);     /* Not exactly right... */
      if (mi_close(info))
	error=my_errno();
      mysql_mutex_lock(&THR_LOCK_myisam);
      break;
    case HA_PANIC_WRITE:		/* Do this to free databases */
      if (flush_key_blocks(info->s->key_cache, keycache_thread_var(),
                           info->s->kfile, FLUSH_RELEASE))
	error=my_errno();
      if (info->opt_flag & WRITE_CACHE_USED)
	if (flush_io_cache(&info->rec_cache))
	  error=my_errno();
      if (info->opt_flag & READ_CACHE_USED)
      {
	if (flush_io_cache(&info->rec_cache))
	  error=my_errno();
	reinit_io_cache(&info->rec_cache,READ_CACHE,0,
		       (pbool) (info->lock_type != F_UNLCK),1);
      }
      if (info->lock_type != F_UNLCK && ! info->was_locked)
      {
	info->was_locked=info->lock_type;
	if (mi_lock_database(info,F_UNLCK))
	  error=my_errno();
      }
    case HA_PANIC_READ:			/* Restore to before WRITE */
      if (info->was_locked)
      {
	if (mi_lock_database(info, info->was_locked))
	  error=my_errno();
	info->was_locked=0;
      }
      break;
    }
  }
  if (flag == HA_PANIC_CLOSE)
  {
    (void) mi_log(0);				/* Close log if neaded */
    ft_free_stopwords();
  }
  mysql_mutex_unlock(&THR_LOCK_myisam);
  if (!error)
    DBUG_RETURN(0);
  set_my_errno(error);
  DBUG_RETURN(error);
} /* mi_panic */
Exemplo n.º 7
0
// Remove the update queue tables associated with every data source.
void remove_update_queue_tables(void)
{
	mi_integer  result;
	MI_ROW     *row;
	int         updq_name_len;
    char       *updq_name;
	char        sql_stmt[2 * DB_MAX_SIZE];    

    result = mi_exec (cursor_conn, "select updqueuename from vl_datasrc", MI_QUERY_NORMAL);
    
    if ( result != MI_ERROR )
    {
		mi_get_result (cursor_conn);
		
		row = mi_next_row (cursor_conn, &result);
		
		while ( row )
		{
			sql_stmt[0] = '\0';
			
			result = mi_value (row, 0, (MI_DATUM) &updq_name, (MI_DATUM) &updq_name_len);
			
			sprintf (sql_stmt, "drop table %s", updq_name);
			mi_exec (stmt_conn, sql_stmt, MI_QUERY_NORMAL);
			mi_query_finish (stmt_conn);
			puts (updq_name);
			
			row = mi_next_row (cursor_conn, &result);
		}
	}
	mi_close (cursor_conn);
}
Exemplo n.º 8
0
Arquivo: mi-out.c Projeto: 0mp/freebsd
void
mi_table_body (struct ui_out *uiout)
{
  mi_out_data *data = ui_out_data (uiout);
  if (data->suppress_output)
    return;
  /* close the table header line if there were any headers */
  mi_close (uiout, ui_out_type_list);
  mi_open (uiout, "body", ui_out_type_list);
}
Exemplo n.º 9
0
void
mi_end (struct ui_out *uiout,
	enum ui_out_type type,
	int level)
{
  struct ui_out_data *data = ui_out_data (uiout);
  if (data->suppress_output)
    return;
  mi_close (uiout, type);
}
Exemplo n.º 10
0
int test_write(MI_INFO *file,int id,int lock_type)
{
  uint i,tries,count,lock;

  lock=0;
  if (rnd(2) == 0 || lock_type == F_RDLCK)
  {
    lock=1;
    if (mi_lock_database(file,F_WRLCK))
    {
      if (lock_type == F_RDLCK && my_errno == EDEADLK)
      {
	printf("%2d: write:  deadlock\n",id); fflush(stdout);
	return 0;
      }
      fprintf(stderr,"%2d: Can't lock table (%d)\n",id,my_errno);
      mi_close(file);
      return 1;
    }
    if (rnd(2) == 0)
      mi_extra(file,HA_EXTRA_WRITE_CACHE,0);
  }

  sprintf((char*) record.id,"%7d",getpid());
  strnmov((char*) record.text,"Testing...", sizeof(record.text));

  tries=(uint) rnd(100)+10;
  for (i=count=0 ; i < tries ; i++)
  {
    uint32 tmp=rnd(80000)+20000;
    int4store(record.nr,tmp);
    if (!mi_write(file,record.id))
      count++;
    else
    {
      if (my_errno != HA_ERR_FOUND_DUPP_KEY)
      {
	fprintf(stderr,"%2d: Got error %d (errno %d) from write\n",id,my_errno,
		errno);
	return 1;
      }
    }
  }
  if (lock)
  {
    mi_extra(file,HA_EXTRA_NO_CACHE,0);
    if (mi_lock_database(file,F_UNLCK))
    {
      fprintf(stderr,"%2d: Can't unlock table\n",id);
      exit(0);
    }
  }
  printf("%2d: write:  %5d\n",id,count); fflush(stdout);
  return 0;
}
int myrg_close(MYRG_INFO *info)
{
  int error=0,new_error;
  MYRG_TABLE *file;
  DBUG_ENTER("myrg_close");

  /*
    Assume that info->children_attached means that this is called from
    direct use of MERGE, not from a MySQL server. In this case the
    children must be closed and info->rec_per_key_part is part of the
    'info' multi_alloc.
    If info->children_attached is false, this is called from a MySQL
    server. Children are closed independently but info->rec_per_key_part
    must be freed.
    Just in case of a server panic (myrg_panic()) info->children_attached
    might be true. We would close the children though they should be
    closed independently and info->rec_per_key_part is not freed.
    This should be acceptable for a panic.
    In case of a MySQL server and no children, children_attached is
    always true. In this case no rec_per_key_part has been allocated.
    So it is correct to use the branch where an empty list of tables is
    (not) closed.
  */
  if (info->children_attached)
  {
    for (file= info->open_tables; file != info->end_table; file++)
    {
      /* purecov: begin inspected */
      if ((new_error= mi_close(file->table)))
        error= new_error;
      else
        file->table= NULL;
      /* purecov: end */
    }
  }
  else
    my_free((uchar*) info->rec_per_key_part, MYF(MY_ALLOW_ZERO_PTR));
  delete_queue(&info->by_key);
  pthread_mutex_lock(&THR_LOCK_open);
  myrg_open_list=list_delete(myrg_open_list,&info->open_list);
  pthread_mutex_unlock(&THR_LOCK_open);
  VOID(pthread_mutex_destroy(&info->mutex));
  my_free((uchar*) info,MYF(0));
  if (error)
  {
    DBUG_RETURN(my_errno=error);
  }
  DBUG_RETURN(0);
}
Exemplo n.º 12
0
Arquivo: mi-out.c Projeto: 0mp/freebsd
void
mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
		 const char *col_name,
		 const char *colhdr)
{
  mi_out_data *data = ui_out_data (uiout);
  if (data->suppress_output)
    return;
  mi_open (uiout, NULL, ui_out_type_tuple);
  mi_field_int (uiout, 0, 0, 0, "width", width);
  mi_field_int (uiout, 0, 0, 0, "alignment", alignment);
  mi_field_string (uiout, 0, 0, 0, "col_name", col_name);
  mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
  mi_close (uiout, ui_out_type_tuple);
}
Exemplo n.º 13
0
int mi_delete_table(const char *name)
{
  char from[FN_REFLEN];
#ifdef USE_RAID
  uint raid_type=0,raid_chunks=0;
#endif
  DBUG_ENTER("mi_delete_table");

#ifdef EXTRA_DEBUG
  check_table_is_closed(name,"delete");
#endif
#ifdef USE_RAID
  {
    MI_INFO *info;
    /*
      When built with RAID support, we need to determine if this table
      makes use of the raid feature. If yes, we need to remove all raid
      chunks. This is done with my_raid_delete(). Unfortunately it is
      necessary to open the table just to check this. We use
      'open_for_repair' to be able to open even a crashed table. If even
      this open fails, we assume no raid configuration for this table
      and try to remove the normal data file only. This may however
      leave the raid chunks behind.
    */
    if (!(info= mi_open(name, O_RDONLY, HA_OPEN_FOR_REPAIR)))
      raid_type= 0;
    else
    {
      raid_type=   info->s->base.raid_type;
      raid_chunks= info->s->base.raid_chunks;
      mi_close(info);
    }
  }
#ifdef EXTRA_DEBUG
  check_table_is_closed(name,"delete");
#endif
#endif /* USE_RAID */

  fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
  if (my_delete_with_symlink(from, MYF(MY_WME)))
    DBUG_RETURN(my_errno);
  fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
#ifdef USE_RAID
  if (raid_type)
    DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0);
#endif
  DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0);
}
Exemplo n.º 14
0
int test_rrnd(MI_INFO *file,int id)
{
  uint count,lock;

  lock=0;
  if (rnd(2) == 0)
  {
    lock=1;
    if (mi_lock_database(file,F_RDLCK))
    {
      fprintf(stderr,"%2d: Can't lock table (%d)\n",id,my_errno);
      mi_close(file);
      return 1;
    }
    if (rnd(2) == 0)
      mi_extra(file,HA_EXTRA_CACHE,0);
  }

  count=0;
  if (mi_rrnd(file,record.id,0L))
  {
    if (my_errno == HA_ERR_END_OF_FILE)
      goto end;
    fprintf(stderr,"%2d: Can't read first record (%d)\n",id,my_errno);
    return 1;
  }
  for (count=1 ; !mi_rrnd(file,record.id,HA_OFFSET_ERROR) ;count++) ;
  if (my_errno != HA_ERR_END_OF_FILE)
  {
    fprintf(stderr,"%2d: Got error %d from rrnd\n",id,my_errno);
    return 1;
  }

end:
  if (lock)
  {
    mi_extra(file,HA_EXTRA_NO_CACHE,0);
    if (mi_lock_database(file,F_UNLCK))
    {
      fprintf(stderr,"%2d: Can't unlock table\n",id);
      exit(0);
    }
  }
  printf("%2d: rrnd:   %5d\n",id,count); fflush(stdout);
  return 0;
}
Exemplo n.º 15
0
/*
   Doers process the unprocessed tokens from the task queue and move them
   to the cleanup queue once they are processed
 */
DWORD WINAPI doer(LPVOID ptr)
{
#if !defined _MIDDLE
    MI_CONNECTION *conn=NULL;
    conn = startup();
#endif

    while (!g_fTerminate)
    {
        // Either the doer_dispatcher or the movers can wake up the doers.
        WaitForMultipleObjects(NUM_WAKEUP_DOER_HANDLE, wakeup_doer_array, FALSE, INFINITE);
        if (g_fTerminate)
            break;

        // Increment the number of active doers.
        EnterCriticalSection(&doer_num_mutex);
        num_doer++;
        LeaveCriticalSection( &doer_num_mutex );

        {
            int result;
#ifdef _MIDDLE
            result = vl_do_tasks();
#else
            result = execUDR (conn, "execute function vl_do_tasks();");
#endif
        }
        // Decrement the number of active doers.
        EnterCriticalSection(&doer_num_mutex);
        num_doer--;
        LeaveCriticalSection( &doer_num_mutex );
    }

#if !defined _MIDDLE
    mi_close(conn);
#endif


    return 1;
}
Exemplo n.º 16
0
int 
mi_rename(const char *old_name, const char *new_name)
{
	char		from      [FN_REFLEN], to[FN_REFLEN];
#ifdef USE_RAID
	uint		raid_type = 0, raid_chunks = 0;
#endif
	DBUG_ENTER("mi_rename");

#ifdef EXTRA_DEBUG
	check_table_is_closed(old_name, "rename old_table");
	check_table_is_closed(new_name, "rename new table2");
#endif
#ifdef USE_RAID
	{
		MI_INFO        *info;
		if (!(info = mi_open(old_name, O_RDONLY, 0)))
			DBUG_RETURN(my_errno);
		raid_type = info->s->base.raid_type;
		raid_chunks = info->s->base.raid_chunks;
		mi_close(info);
	}
#ifdef EXTRA_DEBUG
	check_table_is_closed(old_name, "rename raidcheck");
#endif
#endif				/* USE_RAID */

	fn_format(from, old_name, "", MI_NAME_IEXT, 4);
	fn_format(to, new_name, "", MI_NAME_IEXT, 4);
	if (my_rename(from, to, MYF(MY_WME)))
		DBUG_RETURN(my_errno);
	fn_format(from, old_name, "", MI_NAME_DEXT, 4);
	fn_format(to, new_name, "", MI_NAME_DEXT, 4);
#ifdef USE_RAID
	if (raid_type)
		DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno :
			    0);
#endif
	DBUG_RETURN(my_rename(from, to, MYF(MY_WME)) ? my_errno : 0);
}
Exemplo n.º 17
0
int main(int argc,char *argv[])
{
  int error=0, subkeys;
  uint keylen, keylen2=0, inx, doc_cnt=0;
  float weight= 1.0;
  double gws, min_gws=0, avg_gws=0;
  MI_INFO *info;
  char buf[MAX_LEN], buf2[MAX_LEN], buf_maxlen[MAX_LEN], buf_min_gws[MAX_LEN];
  ulong total=0, maxlen=0, uniq=0, max_doc_cnt=0;
  struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */

  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);

  if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
    exit(error);
  if (count || dump)
    verbose=0;
  if (!count && !dump && !lstats && !query)
    stats=1;

  if (verbose)
    setbuf(stdout,NULL);

  if (argc < 2)
    usage();

  {
    char *end;
    inx= (uint) my_strtoll(argv[1], &end, 10);
    if (*end)
      usage();
  }

  init_key_cache(dflt_key_cache,MI_KEY_BLOCK_LENGTH,USE_BUFFER_INIT, 0, 0);

  if (!(info=mi_open(argv[0], O_RDONLY,
                     HA_OPEN_ABORT_IF_LOCKED|HA_OPEN_FROM_SQL_LAYER)))
  {
    error=my_errno();
    goto err;
  }

  *buf2=0;
  aio->info=info;

  if ((inx >= info->s->base.keys) ||
      !(info->s->keyinfo[inx].flag & HA_FULLTEXT))
  {
    printf("Key %d in table %s is not a FULLTEXT key\n", inx, info->filename);
    goto err;
  }

  mi_lock_database(info, F_EXTRA_LCK);

  info->lastpos= HA_OFFSET_ERROR;
  info->update|= HA_STATE_PREV_FOUND;

  while (!(error=mi_rnext(info,NULL,inx)))
  {
    keylen=*(info->lastkey);

    subkeys=ft_sintXkorr(info->lastkey+keylen+1);
    if (subkeys >= 0)
      ft_floatXget(weight, info->lastkey+keylen+1);

    my_snprintf(buf,MAX_LEN,"%.*s",(int) keylen,info->lastkey+1);
    my_casedn_str(default_charset_info,buf);
    total++;
    lengths[keylen]++;

    if (count || stats)
    {
      if (strcmp(buf, buf2))
      {
        if (*buf2)
        {
          uniq++;
          avg_gws+=gws=GWS_IN_USE;
          if (count)
            printf("%9u %20.7f %s\n",doc_cnt,gws,buf2);
          if (maxlen<keylen2)
          {
            maxlen=keylen2;
            my_stpcpy(buf_maxlen, buf2);
          }
          if (max_doc_cnt < doc_cnt)
          {
            max_doc_cnt=doc_cnt;
            my_stpcpy(buf_min_gws, buf2);
            min_gws=gws;
          }
        }
        my_stpcpy(buf2, buf);
        keylen2=keylen;
        doc_cnt=0;
      }
      doc_cnt+= (subkeys >= 0 ? 1 : -subkeys);
    }
    if (dump)
    {
      if (subkeys>=0)
        printf("%9lx %20.7f %s\n", (long) info->lastpos,weight,buf);
      else
        printf("%9lx => %17d %s\n",(long) info->lastpos,-subkeys,buf);
    }
    if (verbose && (total%HOW_OFTEN_TO_WRITE)==0)
      printf("%10ld\r",total);
  }
  mi_lock_database(info, F_UNLCK);

  if (count || stats)
  {
    if (*buf2)
    {
      uniq++;
      avg_gws+=gws=GWS_IN_USE;
      if (count)
        printf("%9u %20.7f %s\n",doc_cnt,gws,buf2);
      if (maxlen<keylen2)
      {
        maxlen=keylen2;
        my_stpcpy(buf_maxlen, buf2);
      }
      if (max_doc_cnt < doc_cnt)
      {
        max_doc_cnt=doc_cnt;
        my_stpcpy(buf_min_gws, buf2);
        min_gws=gws;
      }
    }
  }

  if (stats)
  {
    count=0;
    for (inx=0;inx<256;inx++)
    {
      count+=lengths[inx];
      if ((ulong) count >= total/2)
        break;
    }
    printf("Total rows: %lu\nTotal words: %lu\n"
           "Unique words: %lu\nLongest word: %lu chars (%s)\n"
           "Median length: %u\n"
           "Average global weight: %f\n"
           "Most common word: %lu times, weight: %f (%s)\n",
           (long) info->state->records, total, uniq, maxlen, buf_maxlen,
           inx, avg_gws/uniq, max_doc_cnt, min_gws, buf_min_gws);
  }
  if (lstats)
  {
    count=0;
    for (inx=0; inx<256; inx++)
    {
      count+=lengths[inx];
      if (count && lengths[inx])
        printf("%3u: %10lu %5.2f%% %20lu %4.1f%%\n", inx,
               (ulong) lengths[inx],100.0*lengths[inx]/total,(ulong) count,
               100.0*count/total);
    }
  }

err:
  if (error && error != HA_ERR_END_OF_FILE)
    printf("got error %d\n",my_errno());
  if (info)
    mi_close(info);
  mysql_cond_destroy(&main_thread_keycache_var.suspend);
  return 0;
}
Exemplo n.º 18
0
void remove_catalogs(void)
{	
    conn_info.server_name = server;
    db_info.database_name = hostdb;
    db_info.user_name = username;
    db_info.password = password;

    cursor_conn = mi_server_connect (&conn_info);
    stmt_conn = mi_server_connect (&conn_info);

    if ( cursor_conn == NULL || stmt_conn == NULL )
    {
        printf ("Error: unable to connect to %s.\n", server);
        puts ("Ensure that the DBMS is running and that your Informix Setnet32 settings are correct.");
        exit (EXIT_FAILURE);
    }

    if( mi_login (cursor_conn, &db_info) != MI_OK ||
        mi_login (stmt_conn, &db_info) != MI_OK )
    {
        printf ("\n\nError: unable to log in to %s@%s.\n", hostdb, server);
        puts ("Ensure the DBMS is running, verify the database exists, and check your username and password.");
        exit (EXIT_FAILURE);
    }

	printf ("\n\nConnected to %s@%s.\n\n", hostdb, server);

	puts ("Removing Vigilert's catalogs will delete your Vigilert triggers,");
	puts ("triggersets, data sources, pending mail, pending OS commands, and pending notices.");
	printf ("Are you sure you want to do this (Y/N)? ");
	fgets (yesno, sizeof (yesno), stdin);
    yesno[strlen (yesno) - 1] = '\0';  // Remove trailing \n.

	if (stricmp (yesno, "y") != 0)
	{
		exit (EXIT_SUCCESS);
	}

	puts ("");

	remove_update_queue_tables();

	exec_sql_stmt("drop table vl_DataSrc");
	puts ("vl_DataSrc");

	exec_sql_stmt("drop table vl_DataSrcAtb"),
	puts ("vl_datasrcatb");

	exec_sql_stmt("drop table vl_IDTable");
	puts ("vl_idtable");

	exec_sql_stmt("drop table vl_TriggerSet");
	puts ("vl_TriggerSet");

	exec_sql_stmt("drop table vl_Trigger");
	puts ("vl_Trigger");

	exec_sql_stmt("drop table vl_TrigDataSrcReln");
	puts ("vl_TrigDataSrcReln");

	exec_sql_stmt("drop table vl_mail");
	puts ("vl_mail");

	exec_sql_stmt("drop table vl_osexec");
	puts ("vl_osexec");

	exec_sql_stmt("drop table vl_notice");
	puts ("vl_notice");

	exec_sql_stmt("drop table vl_DataSrcMtb");
	puts ("vl_DataSrcMtb");

	exec_sql_stmt("drop table vl_null_tbl");
	puts ("vl_null_tbl");

	exec_sql_stmt("drop table vl_mon_watch");
	puts ("vl_mon_watch");

	exec_sql_stmt("drop table vl_mon_update");
	puts ("vl_mon_update");

	exec_sql_stmt("drop table vl_ext_fcn_tbl");
	puts ("vl_ext_fcn_tbl");

	exec_sql_stmt("delete from systraceclasses where name = 'Vigilert'");
	puts ("systraceclasses");

	mi_close (stmt_conn);
}
Exemplo n.º 19
0
int mi_panic(enum ha_panic_function flag)
{
  int error=0;
  LIST *list_element,*next_open;
  MI_INFO *info;
  DBUG_ENTER("mi_panic");

  mysql_mutex_lock(&THR_LOCK_myisam);
  for (list_element=myisam_open_list ; list_element ; list_element=next_open)
  {
    next_open=list_element->next;		/* Save if close */
    info=(MI_INFO*) list_element->data;
    switch (flag) {
    case HA_PANIC_CLOSE:
      mysql_mutex_unlock(&THR_LOCK_myisam);     /* Not exactly right... */
      if (mi_close(info))
	error=my_errno;
      mysql_mutex_lock(&THR_LOCK_myisam);
      break;
    case HA_PANIC_WRITE:		/* Do this to free databases */
#ifdef CANT_OPEN_FILES_TWICE
      if (info->s->options & HA_OPTION_READ_ONLY_DATA)
	break;
#endif
      if (flush_key_blocks(info->s->key_cache, info->s->kfile, FLUSH_RELEASE))
	error=my_errno;
      if (info->opt_flag & WRITE_CACHE_USED)
	if (flush_io_cache(&info->rec_cache))
	  error=my_errno;
      if (info->opt_flag & READ_CACHE_USED)
      {
	if (flush_io_cache(&info->rec_cache))
	  error=my_errno;
	reinit_io_cache(&info->rec_cache,READ_CACHE,0,
		       (pbool) (info->lock_type != F_UNLCK),1);
      }
      if (info->lock_type != F_UNLCK && ! info->was_locked)
      {
	info->was_locked=info->lock_type;
	if (mi_lock_database(info,F_UNLCK))
	  error=my_errno;
      }
#ifdef CANT_OPEN_FILES_TWICE
      if (info->s->kfile >= 0 && mysql_file_close(info->s->kfile, MYF(0)))
	error = my_errno;
      if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0)))
	error = my_errno;
      info->s->kfile=info->dfile= -1;	/* Files aren't open anymore */
      break;
#endif
    case HA_PANIC_READ:			/* Restore to before WRITE */
#ifdef CANT_OPEN_FILES_TWICE
      {					/* Open closed files */
	char name_buff[FN_REFLEN];
	if (info->s->kfile < 0)
          if ((info->s->kfile= mysql_file_open(mi_key_file_kfile,
                                               fn_format(name_buff,
                                                         info->filename, "",
                                                         N_NAME_IEXT, 4),
                                               info->mode, MYF(MY_WME))) < 0)
	    error = my_errno;
	if (info->dfile < 0)
	{
          if ((info->dfile= mysql_file_open(mi_key_file_dfile,
                                            fn_format(name_buff,
                                                      info->filename, "",
                                                      N_NAME_DEXT, 4),
                                            info->mode, MYF(MY_WME))) < 0)
	    error = my_errno;
	  info->rec_cache.file=info->dfile;
	}
      }
#endif
      if (info->was_locked)
      {
	if (mi_lock_database(info, info->was_locked))
	  error=my_errno;
	info->was_locked=0;
      }
      break;
    }
  }
  if (flag == HA_PANIC_CLOSE)
  {
    (void) mi_log(0);				/* Close log if neaded */
    ft_free_stopwords();
  }
  mysql_mutex_unlock(&THR_LOCK_myisam);
  if (!error)
    DBUG_RETURN(0);
  DBUG_RETURN(my_errno=error);
} /* mi_panic */
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
  MI_INFO *file;
  int i,j;

  MY_INIT(argv[0]);
  get_options(argc,argv);
  bzero((char*)recinfo,sizeof(recinfo));

  /* First define 2 columns */
  recinfo[0].type=FIELD_SKIP_ENDSPACE;
  recinfo[0].length=docid_length;
  recinfo[1].type=FIELD_BLOB;
  recinfo[1].length= 4+portable_sizeof_char_ptr;

  /* Define a key over the first column */
  keyinfo[0].seg=keyseg;
  keyinfo[0].keysegs=1;
  keyinfo[0].block_length= 0;                   /* Default block length */
  keyinfo[0].seg[0].type= HA_KEYTYPE_TEXT;
  keyinfo[0].seg[0].flag= HA_BLOB_PART;
  keyinfo[0].seg[0].start=recinfo[0].length;
  keyinfo[0].seg[0].length=key_length;
  keyinfo[0].seg[0].null_bit=0;
  keyinfo[0].seg[0].null_pos=0;
  keyinfo[0].seg[0].bit_start=4;
  keyinfo[0].seg[0].language=MY_CHARSET_CURRENT;
  keyinfo[0].flag = HA_FULLTEXT;

  if (!silent)
    printf("- Creating isam-file\n");
  if (mi_create(filename,1,keyinfo,2,recinfo,0,NULL,(MI_CREATE_INFO*) 0,0))
    goto err;
  if (!(file=mi_open(filename,2,0)))
    goto err;
  if (!silent)
    printf("Initializing stopwords\n");
  ft_init_stopwords(stopwordlist);

  if (!silent)
    printf("- Writing key:s\n");

  my_errno=0;
  i=0;
  while (create_record(record,df))
  {
    error=mi_write(file,record);
    if (error)
      printf("I= %2d  mi_write: %d  errno: %d\n",i,error,my_errno);
    i++;
  }
  fclose(df);

  if (mi_close(file)) goto err;
  if (!silent)
    printf("- Reopening file\n");
  if (!(file=mi_open(filename,2,0))) goto err;
  if (!silent)
    printf("- Reading rows with key\n");
  for (i=1;create_record(record,qf);i++)
  {
    FT_DOCLIST *result;
    double w;
    int t, err;

    result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
    if (!result)
    {
      printf("Query %d failed with errno %3d\n",i,my_errno);
      goto err;
    }
    if (!silent)
      printf("Query %d. Found: %d.\n",i,result->ndocs);
    for (j=0;(err=ft_nlq_read_next(result, read_record))==0;j++)
    {
      t=uint2korr(read_record);
      w=ft_nlq_get_relevance(result);
      printf("%d %.*s %f\n",i,t,read_record+2,w);
    }
    if (err != HA_ERR_END_OF_FILE)
    {
      printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
      goto err;
    }
    ft_nlq_close_search(result);
  }

  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;			/* skip warning */

}
Exemplo n.º 21
0
MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
{
  int save_errno,errpos=0;
  uint files= 0, i, dir_length, length, UNINIT_VAR(key_parts), min_keys= 0;
  ulonglong file_offset=0;
  char name_buff[FN_REFLEN*2],buff[FN_REFLEN],*end;
  MYRG_INFO *m_info=0;
  File fd;
  IO_CACHE file;
  MI_INFO *isam=0;
  uint found_merge_insert_method= 0;
  size_t name_buff_length;
  my_bool bad_children= FALSE;
  DBUG_ENTER("myrg_open");

  memset(&file, 0, sizeof(file));
  if ((fd= mysql_file_open(rg_key_file_MRG,
                           fn_format(name_buff, name, "", MYRG_NAME_EXT,
                                     MY_UNPACK_FILENAME|MY_APPEND_EXT),
                           O_RDONLY | O_SHARE, MYF(0))) < 0)
    goto err;
  errpos=1;
  if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0,
		    MYF(MY_WME | MY_NABP)))
    goto err;
  errpos=2;
  dir_length=dirname_part(name_buff, name, &name_buff_length);
  while ((length=my_b_gets(&file,buff,FN_REFLEN-1)))
  {
    if ((end=buff+length)[-1] == '\n')
      end[-1]='\0';
    if (buff[0] && buff[0] != '#')
      files++;
  }

  my_b_seek(&file, 0);
  while ((length=my_b_gets(&file,buff,FN_REFLEN-1)))
  {
    if ((end=buff+length)[-1] == '\n')
      *--end='\0';
    if (!buff[0])
      continue;		/* Skip empty lines */
    if (buff[0] == '#')
    {
      if (!strncmp(buff+1,"INSERT_METHOD=",14))
      {			/* Lookup insert method */
	int tmp= find_type(buff + 15, &merge_insert_method, FIND_TYPE_BASIC);
	found_merge_insert_method = (uint) (tmp >= 0 ? tmp : 0);
      }
      continue;		/* Skip comments */
    }

    if (!has_path(buff))
    {
      (void) strmake(name_buff+dir_length,buff,
                   sizeof(name_buff)-1-dir_length);
      (void) cleanup_dirname(buff,name_buff);
    }
    else
      fn_format(buff, buff, "", "", 0);
    if (!(isam=mi_open(buff,mode,(handle_locking?HA_OPEN_WAIT_IF_LOCKED:0))))
    {
      if (handle_locking & HA_OPEN_FOR_REPAIR)
      {
        myrg_print_wrong_table(buff);
        bad_children= TRUE;
        continue;
      }
      goto bad_children;
    }
    if (!m_info)                                /* First file */
    {
      key_parts=isam->s->base.key_parts;
      if (!(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO) +
                                           files*sizeof(MYRG_TABLE) +
                                           key_parts*sizeof(long),
                                           MYF(MY_WME|MY_ZEROFILL))))
        goto err;
      DBUG_ASSERT(files);
      m_info->open_tables=(MYRG_TABLE *) (m_info+1);
      m_info->rec_per_key_part=(ulong *) (m_info->open_tables+files);
      m_info->tables= files;
      files= 0;
      m_info->reclength=isam->s->base.reclength;
      min_keys= isam->s->base.keys;
      errpos=3;
    }
    m_info->open_tables[files].table= isam;
    m_info->open_tables[files].file_offset=(my_off_t) file_offset;
    file_offset+=isam->state->data_file_length;
    files++;
    if (m_info->reclength != isam->s->base.reclength)
    {
      if (handle_locking & HA_OPEN_FOR_REPAIR)
      {
        myrg_print_wrong_table(buff);
        bad_children= TRUE;
        continue;
      }
      goto bad_children;
    }
    m_info->options|= isam->s->options;
    m_info->records+= isam->state->records;
    m_info->del+= isam->state->del;
    m_info->data_file_length+= isam->state->data_file_length;
    if (min_keys > isam->s->base.keys)
      min_keys= isam->s->base.keys;
    for (i=0; i < key_parts; i++)
      m_info->rec_per_key_part[i]+= (isam->s->state.rec_per_key_part[i] /
                                     m_info->tables);
  }

  if (bad_children)
    goto bad_children;
  if (!m_info && !(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO),
                                                  MYF(MY_WME | MY_ZEROFILL))))
    goto err;
  /* Don't mark table readonly, for ALTER TABLE ... UNION=(...) to work */
  m_info->options&= ~(HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA);
  m_info->merge_insert_method= found_merge_insert_method;

  if (sizeof(my_off_t) == 4 && file_offset > (ulonglong) (ulong) ~0L)
  {
    my_errno=HA_ERR_RECORD_FILE_FULL;
    goto err;
  }
  m_info->keys= min_keys;
  memset(&m_info->by_key, 0, sizeof(m_info->by_key));

  /* this works ok if the table list is empty */
  m_info->end_table=m_info->open_tables+files;
  m_info->last_used_table=m_info->open_tables;
  m_info->children_attached= TRUE;

  (void) mysql_file_close(fd, MYF(0));
  end_io_cache(&file);
  mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex,
                   &m_info->mutex, MY_MUTEX_INIT_FAST);
  m_info->open_list.data=(void*) m_info;
  mysql_mutex_lock(&THR_LOCK_open);
  myrg_open_list=list_add(myrg_open_list,&m_info->open_list);
  mysql_mutex_unlock(&THR_LOCK_open);
  DBUG_RETURN(m_info);

bad_children:
  my_errno= HA_ERR_WRONG_MRG_TABLE_DEF;
err:
  save_errno=my_errno;
  switch (errpos) {
  case 3:
    while (files)
      (void) mi_close(m_info->open_tables[--files].table);
    my_free(m_info);
    /* Fall through */
  case 2:
    end_io_cache(&file);
    /* Fall through */
  case 1:
    (void) mysql_file_close(fd, MYF(0));
  }
  my_errno=save_errno;
  DBUG_RETURN (NULL);
}
Exemplo n.º 22
0
/*
   Movers move the unprocessed updated tokens from the update queue table to
   the main memory task queue. They also wake up the doers whenever they move
   any new tokens to the task queue.
 */
DWORD WINAPI mover(LPVOID ptr)
{
    int result;
    int i;

#if !defined _MIDDLE
    MI_CONNECTION *conn = NULL;
    conn = startup();
#endif

    while (!g_fTerminate)
    {
        // The mover dispatcher can wake up the movers when a data source is updated
        WaitForSingleObject(wakeup_mover_by_mover_dispatcher_sem, INFINITE);
        if (g_fTerminate)
            break;

        // Increment the number of active movers
        EnterCriticalSection(&mover_num_mutex);
        num_mover++;
        LeaveCriticalSection(&mover_num_mutex );

        EnterCriticalSection(&suspend_mutex);
        // Lock the mutex so that the cleaners and the movers are not
        // active at the same time
        EnterCriticalSection(&mover_cleaner_mutex);

#ifdef _MIDDLE
        // Movers perform till the task queue is full or when all the tokens from the updated
        // data sources have been moved.
        // A ceiling is imposed on the task queue to apply back pressure on the movers
        // to stop after the task queue is full. This will prevent the doers from lagging behind
        // and movers from moving too many tolens at the same time.
        result = TASK_QUEUE_NOT_FULL;
        while (result == TASK_QUEUE_NOT_FULL)
        {
            result = vl_move_tasks();
            if ((result == TASK_QUEUE_FULL) || (result == TASK_QUEUE_NOT_FULL))
                // Wake up all the doers
            {
                for (i = 0; i < MAXDOER; i++)
                    ReleaseSemaphore(wakeup_doer_by_mover_sem, 1, NULL);
            }
        }
#else
        result = execUDR(conn,"execute function vl_move_tasks();");
#endif

        LeaveCriticalSection(&mover_cleaner_mutex);
        LeaveCriticalSection(&suspend_mutex);

        // Decrement the number of active movers
        EnterCriticalSection(&mover_num_mutex);
        num_mover--;
        LeaveCriticalSection(&mover_num_mutex );
    }

    // Release the doers.
    for (i = 0; i < MAXDOER; i++)
    {
        ReleaseSemaphore(wakeup_doer_by_mover_sem, 1, NULL);
    }
#if !defined _MIDDLE
    mi_close(conn);
#endif

    return 1;
}
Exemplo n.º 23
0
/*
    Close LCD display panel.

    Call this api to close the LCD panel device.

    @param[in] pDevIF Please refer to dispdevctrl.h for details.

    @return
     - @b E_OK:     LCD Close done and success.
*/
static ER dispdev_closeIFMi(void)
{
    UINT32                  i,CmdNumber;
    tPANEL_CMD              *pStandby=NULL;
    DISPDEV_IOCTRL_PARAM    DevIOCtrl;
    PINMUX_FUNC_ID          PinFuncID;
    #if   (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD1)
    DISPDEV_IOCTRL          pDispDevControl = pIFMiIoControl1;
    #elif (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD2)
    DISPDEV_IOCTRL          pDispDevControl = pIFMiIoControl2;
    #endif
    MI_TYPE     Type;
    //#NT#2011/11/15#Klins Chen -begin
    MI_AUTO_FMT             AutoType;
    MI_DATAFMT              DataFMT;
    BOOL                    bRGBSWAP;
    BOOL                    bBITSWAP;
    BOOL                    bSync;
    BOOL                    bPINMUX;

    dispanl_debug(("closeIFMi START\r\n"));

    mi_getCtrl(&Type, &AutoType, &DataFMT, &bRGBSWAP, &bBITSWAP, &bSync, &bPINMUX);

    if(bSync == FALSE)
        mi_setEn(FALSE);

    DevIOCtrl.SEL.SET_ENABLE.bEn = FALSE;
    pDispDevControl(DISPDEV_IOCTRL_SET_ENABLE, &DevIOCtrl);
    pDispDevControl(DISPDEV_IOCTRL_WAIT_FRAMEEND, NULL);

    if(bSync == TRUE)
        mi_setEn(FALSE);

    #if   (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD1)
    //pll_disableClock(IDE1_CLK);
    //pll_disableClock(IDE2_CLK);
    DevIOCtrl.SEL.SET_CLK_EN.bClkEn = FALSE;
    pDispDevControl(DISPDEV_IOCTRL_SET_CLK_EN, &DevIOCtrl);
    #endif

    mi_setManual(TRUE);

    mi_setCtrl(Type,   AutoType,  DataFMT,  bRGBSWAP,  bBITSWAP,  FALSE,  bPINMUX);
    //#NT#2011/11/15#Klins Chen -end

    pStandby = dispdev_getStandbyCmdMI(&CmdNumber);
    if(pStandby != NULL)
    {
        // Set display device into Standby or powerdown.
        for(i=0; i<CmdNumber; i++)
        {

            if(pStandby[i].uiAddress == CMDDELAY_MS)
            {
                Delay_DelayMs(pStandby[i].uiValue);
            }
            else if (pStandby[i].uiAddress == CMDDELAY_US)
            {
                Delay_DelayUs(pStandby[i].uiValue);
            }
            else
            {
                dispdev_writeLcdReg(pStandby[i].uiAddress, pStandby[i].uiValue);
            }
        }
    }

    mi_close();

    // close pinmux if needed.
    #if (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD1)
    PinFuncID = PINMUX_FUNC_ID_LCD;
    #elif ((DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD2))
    PinFuncID = PINMUX_FUNC_ID_LCD2;
    #endif
    if (pinmux_getDispMode(PinFuncID) & PINMUX_LCDMODE_AUTO_PINMUX)
    {
        pinmux_setPinmux(PinFuncID, PINMUX_LCD_SEL_GPIO);
    }

    dispanl_debug(("closeIFMi Done\r\n"));
    return E_OK;
}
Exemplo n.º 24
0
/*
    Display Device API of open LCD with MI interface

    Display Device API of open LCD with MI interface

    @param[in] pDevIF   Please refer to dispdevctrl.h for details.

    @return
     - @b E_PAR:    Error pDevIF content.
     - @b E_NOSPT:  Driver without supporting the specified LCD Mode.
     - @b E_OK:     LCD Open done and success.
*/
static ER dispdev_openIFMi(void)
{
    UINT32                  i;
    tLCD_PARAM              *pMode      = NULL;
    tLCD_PARAM              *pConfigMode= NULL;
    PINMUX_LCDINIT          LcdMode;
    UINT32                  ModeNumber;
    tMI_CONFIG              MiConfig;
    PINMUX_FUNC_ID          PinFuncID;
    #if   (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD1)
    DISPDEV_IOCTRL          pDispDevControl = pIFMiIoControl1;
    #elif (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD2)
    DISPDEV_IOCTRL          pDispDevControl = pIFMiIoControl2;
    #endif

    dispanl_debug(("openIFMi START\r\n"));

    if(pDispDevControl == NULL)
        return E_PAR;

    //
    //  Sortig the SysInit Config Mode support
    //
    #if   (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD1)
    PinFuncID = PINMUX_FUNC_ID_LCD;
    #elif (DISPLCDSEL_IFMI_TYPE == DISPLCDSEL_IFMI_LCD2)
    PinFuncID = PINMUX_FUNC_ID_LCD2;
    #endif
    LcdMode = pinmux_getDispMode(PinFuncID) & (~PINMUX_LCDMODE_AUTO_PINMUX);
    pConfigMode = dispdev_getConfigModeMI(&ModeNumber);
    if((pConfigMode != NULL)&&(ModeNumber>0))
    {
        for(i=0;i<ModeNumber;i++)
        {
            if(pConfigMode[i].Panel.LCDMode == LcdMode)
            {
                pMode = (tLCD_PARAM*)&pConfigMode[i];
                break;
            }
        }
    }

    if(pMode==NULL)
    {
        DBG_ERR("LCDMode=%d not support\r\n", LcdMode);
        return E_NOSPT;
    }

    if(mi_isOpened())
        mi_close();

    mi_open();

    switch (LcdMode)
    {
    case PINMUX_LCDMODE_MI_FMT0:
        MiConfig.DataFmt = MI_DATAFMT0;
        break;
    case PINMUX_LCDMODE_MI_FMT1:
        MiConfig.DataFmt = MI_DATAFMT1;
        break;
    case PINMUX_LCDMODE_MI_FMT2:
        MiConfig.DataFmt = MI_DATAFMT2;
        break;
    case PINMUX_LCDMODE_MI_FMT3:
        MiConfig.DataFmt = MI_DATAFMT3;
        break;
    case PINMUX_LCDMODE_MI_FMT4:
        MiConfig.DataFmt = MI_DATAFMT4;
        break;
    case PINMUX_LCDMODE_MI_FMT5:
        MiConfig.DataFmt = MI_DATAFMT5;
        break;
    case PINMUX_LCDMODE_MI_FMT6:
        MiConfig.DataFmt = MI_DATAFMT6;
        break;
    case PINMUX_LCDMODE_MI_FMT7:
        MiConfig.DataFmt = MI_DATAFMT7;
        break;
    case PINMUX_LCDMODE_MI_FMT8:
        MiConfig.DataFmt = MI_DATAFMT8;
        break;
    case PINMUX_LCDMODE_MI_FMT9:
        MiConfig.DataFmt = MI_DATAFMT9;
        break;
    case PINMUX_LCDMODE_MI_FMT10:
        MiConfig.DataFmt = MI_DATAFMT10;
        break;
    case PINMUX_LCDMODE_MI_FMT11:
        MiConfig.DataFmt = MI_DATAFMT11;
        break;
    case PINMUX_LCDMODE_MI_FMT12:
        MiConfig.DataFmt = MI_DATAFMT12;
        break;
    case PINMUX_LCDMODE_MI_FMT13:
        MiConfig.DataFmt = MI_DATAFMT13;
        break;
    case PINMUX_LCDMODE_MI_FMT14:
        MiConfig.DataFmt = MI_DATAFMT14;
        break;
    case PINMUX_LCDMODE_MI_SERIAL_BI:
        MiConfig.DataFmt = MI_DATAFMT1;
        break;

    default:
        DBG_ERR("openIFMi not supported mode! \r\n");
        break;
    }

#if _FPGA_EMULATION_
    MiConfig.fMiSrcClk = 24.0;
#else
    MiConfig.fMiSrcClk = 240.0;
#endif
    dispdev_setMiConfig(&MiConfig);

    mi_setManual(TRUE);

    // Config & Enable Display physical engine
    dispdev_setDisplay(pDispDevControl, tLCD_INF_MI, pMode, PinFuncID);

    // Config & Enable display device
    DispDeviceInit(pMode);

    dispdev_setMiAutoCmd();

    mi_setManual(FALSE);
    mi_setEn(TRUE);

    dispanl_debug(("openIFMi Done\r\n"));
    #if 0
    // Test Panel Frame Rate
    {
        UINT32 i;

        Perf_Open();
        Perf_Mark();
        for(i=0;i<1000;i++)
        {
            pDevIF->waitFrmEnd();
        }
        debug_err(("Time tick = %d us\r\n",Perf_GetDuration()));
        Perf_Close();
    }
    #endif

    return E_OK;
}
Exemplo n.º 25
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 */
}
Exemplo n.º 26
0
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,found_parts;
  my_off_t lastpos;
  ha_rows range_records,records;
  MI_INFO *file;
  MI_KEYDEF keyinfo[10];
  MI_COLUMNDEF recinfo[10];
  MI_ISAMINFO info;
  const char *filename;
  char *blob_buffer;
  MI_CREATE_INFO create_info;
  MY_INIT(argv[0]);

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

  reclength=STANDARD_LENGTH+60+(use_blob ? 8 : 0);
  blob_pos=STANDARD_LENGTH+60;
  keyinfo[0].seg= &glob_keyseg[0][0];
  keyinfo[0].seg[0].start=0;
  keyinfo[0].seg[0].length=6;
  keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT;
  keyinfo[0].seg[0].language= default_charset_info->number;
  keyinfo[0].seg[0].flag=(uint8) pack_seg;
  keyinfo[0].seg[0].null_bit=0;
  keyinfo[0].seg[0].null_pos=0;
  keyinfo[0].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[0].keysegs=1;
  keyinfo[0].flag = pack_type;
  keyinfo[0].block_length= 0;                   /* Default block length */
  keyinfo[1].seg= &glob_keyseg[1][0];
  keyinfo[1].seg[0].start=7;
  keyinfo[1].seg[0].length=6;
  keyinfo[1].seg[0].type=HA_KEYTYPE_BINARY;
  keyinfo[1].seg[0].flag=0;
  keyinfo[1].seg[0].null_bit=0;
  keyinfo[1].seg[0].null_pos=0;
  keyinfo[1].seg[1].start=0;			/* two part key */
  keyinfo[1].seg[1].length=6;
  keyinfo[1].seg[1].type=HA_KEYTYPE_NUM;
  keyinfo[1].seg[1].flag=HA_REVERSE_SORT;
  keyinfo[1].seg[1].null_bit=0;
  keyinfo[1].seg[1].null_pos=0;
  keyinfo[1].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[1].keysegs=2;
  keyinfo[1].flag =0;
  keyinfo[1].block_length= MI_MIN_KEY_BLOCK_LENGTH;  /* Diff blocklength */
  keyinfo[2].seg= &glob_keyseg[2][0];
  keyinfo[2].seg[0].start=12;
  keyinfo[2].seg[0].length=8;
  keyinfo[2].seg[0].type=HA_KEYTYPE_BINARY;
  keyinfo[2].seg[0].flag=HA_REVERSE_SORT;
  keyinfo[2].seg[0].null_bit=0;
  keyinfo[2].seg[0].null_pos=0;
  keyinfo[2].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[2].keysegs=1;
  keyinfo[2].flag =HA_NOSAME;
  keyinfo[2].block_length= 0;                   /* Default block length */
  keyinfo[3].seg= &glob_keyseg[3][0];
  keyinfo[3].seg[0].start=0;
  keyinfo[3].seg[0].length=reclength-(use_blob ? 8 : 0);
  keyinfo[3].seg[0].type=HA_KEYTYPE_TEXT;
  keyinfo[3].seg[0].language=default_charset_info->number;
  keyinfo[3].seg[0].flag=(uint8) pack_seg;
  keyinfo[3].seg[0].null_bit=0;
  keyinfo[3].seg[0].null_pos=0;
  keyinfo[3].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[3].keysegs=1;
  keyinfo[3].flag = pack_type;
  keyinfo[3].block_length= 0;                   /* Default block length */
  keyinfo[4].seg= &glob_keyseg[4][0];
  keyinfo[4].seg[0].start=0;
  keyinfo[4].seg[0].length=5;
  keyinfo[4].seg[0].type=HA_KEYTYPE_TEXT;
  keyinfo[4].seg[0].language=default_charset_info->number;
  keyinfo[4].seg[0].flag=0;
  keyinfo[4].seg[0].null_bit=0;
  keyinfo[4].seg[0].null_pos=0;
  keyinfo[4].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[4].keysegs=1;
  keyinfo[4].flag = pack_type;
  keyinfo[4].block_length= 0;                   /* Default block length */
  keyinfo[5].seg= &glob_keyseg[5][0];
  keyinfo[5].seg[0].start=0;
  keyinfo[5].seg[0].length=4;
  keyinfo[5].seg[0].type=HA_KEYTYPE_TEXT;
  keyinfo[5].seg[0].language=default_charset_info->number;
  keyinfo[5].seg[0].flag=pack_seg;
  keyinfo[5].seg[0].null_bit=0;
  keyinfo[5].seg[0].null_pos=0;
  keyinfo[5].key_alg=HA_KEY_ALG_BTREE;
  keyinfo[5].keysegs=1;
  keyinfo[5].flag = pack_type;
  keyinfo[5].block_length= 0;                   /* Default block length */

  recinfo[0].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[0].length=7;
  recinfo[0].null_bit=0;
  recinfo[0].null_pos=0;
  recinfo[1].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[1].length=5;
  recinfo[1].null_bit=0;
  recinfo[1].null_pos=0;
  recinfo[2].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
  recinfo[2].length=9;
  recinfo[2].null_bit=0;
  recinfo[2].null_pos=0;
  recinfo[3].type=FIELD_NORMAL;
  recinfo[3].length=STANDARD_LENGTH-7-5-9-4;
  recinfo[3].null_bit=0;
  recinfo[3].null_pos=0;
  recinfo[4].type=pack_fields ? FIELD_SKIP_ZERO : 0;
  recinfo[4].length=4;
  recinfo[4].null_bit=0;
  recinfo[4].null_pos=0;
  recinfo[5].type=pack_fields ? FIELD_SKIP_ENDSPACE : 0;
  recinfo[5].length=60;
  recinfo[5].null_bit=0;
  recinfo[5].null_pos=0;
  if (use_blob)
  {
    recinfo[6].type=FIELD_BLOB;
    recinfo[6].length=4+portable_sizeof_char_ptr;
    recinfo[6].null_bit=0;
    recinfo[6].null_pos=0;
  }

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

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

  if (!silent)
    printf("- Creating isam-file\n");
  /*  DBUG_PUSH(""); */
  /* my_delete(filename,MYF(0)); */	/* Remove old locks under gdb */
  file= 0;
  bzero((char*) &create_info,sizeof(create_info));
  create_info.max_rows=(ha_rows) (rec_pointer_size ?
				  (1L << (rec_pointer_size*8))/
				  reclength : 0);
  create_info.reloc_rows=(ha_rows) 100;
  if (mi_create(filename,keys,&keyinfo[first_key],
		use_blob ? 7 : 6, &recinfo[0],
		0,(MI_UNIQUEDEF*) 0,
		&create_info,create_flag))
    goto err;
  if (use_log)
    mi_log(1);
  if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
    goto err;
  if (!silent)
    printf("- Writing key:s\n");
  if (key_cacheing)
    init_key_cache(dflt_key_cache,key_cache_block_size,key_cache_size,0,0);
  if (locking)
    mi_lock_database(file,F_WRLCK);
  if (write_cacheing)
    mi_extra(file,HA_EXTRA_WRITE_CACHE,0);
  if (opt_quick_mode)
    mi_extra(file,HA_EXTRA_QUICK,0);

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

    if (mi_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)+1 ; j>0 && key1[j] == 0 ; j--) ;
      if (!j)
	for (j=999 ; j>0 && key1[j] == 0 ; j--) ;
      sprintf((char*) key,"%6d",j);
      if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,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 (mi_extra(file,HA_EXTRA_NO_CACHE,0))
    {
      puts("got error from mi_extra(HA_EXTRA_NO_CACHE)");
      goto end;
    }
  }
  if (key_cacheing)
    resize_key_cache(dflt_key_cache,key_cache_block_size,key_cache_size*2,0,0);

  if (!silent)
    printf("- Delete\n");
  for (i=0 ; i<recant/10 ; i++)
  {
    for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
    if (j != 0)
    {
      sprintf((char*) key,"%6d",j);
      if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      {
	printf("can't find key1: \"%s\"\n",key);
	goto err;
      }
      if (opt_delete == (uint) remove_count)		/* While testing */
	goto end;
      if (mi_delete(file,read_record))
      {
	printf("error: %d; can't delete record: \"%s\"\n", my_errno,read_record);
	goto err;
      }
      opt_delete++;
      key1[atoi((char*) read_record+keyinfo[0].seg[0].start)]--;
      key3[atoi((char*) read_record+keyinfo[2].seg[0].start)]=0;
    }
    else
      puts("Warning: Skipping delete test because no dupplicate keys");
  }
  if (testflag==2) goto end;

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

    for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
    if (j != 0)
    {
      sprintf((char*) key,"%6d",j);
      if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      {
	printf("can't find key1: \"%s\"\n",(char*) 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 (mi_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((char*) read_record+keyinfo[0].seg[0].start)]--;
	key3[atoi((char*) read_record+keyinfo[2].seg[0].start)]=0;
	key1[n1]++; key3[n3]=1;
	update++;
      }
    }
  }
  if (testflag == 3)
    goto end;

  for (i=999, dupp_keys=j=0 ; i>0 ; i--)
  {
    if (key1[i] > dupp_keys)
    {
      dupp_keys=key1[i]; j=i;
    }
  }
  sprintf((char*) key,"%6d",j);
  start=keyinfo[0].seg[0].start;
  length=keyinfo[0].seg[0].length;
  if (dupp_keys)
  {
    if (!silent)
      printf("- Same key: first - next -> last - prev -> first\n");
    DBUG_PRINT("progpos",("first - next -> last - prev -> first"));
    if (verbose) printf("	 Using key: \"%s\"  Keys: %d\n",key,dupp_keys);

    if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      goto err;
    if (mi_rsame(file,read_record2,-1))
      goto err;
    if (memcmp(read_record,read_record2,reclength) != 0)
    {
      printf("mi_rsame didn't find same record\n");
      goto end;
    }
    info.recpos=mi_position(file);
    if (mi_rfirst(file,read_record2,0) ||
	mi_rsame_with_pos(file,read_record2,0,info.recpos) ||
	memcmp(read_record,read_record2,reclength) != 0)
    {
      printf("mi_rsame_with_pos didn't find same record\n");
      goto end;
    }
    {
      int skr=mi_rnext(file,read_record2,0);
      if ((skr && my_errno != HA_ERR_END_OF_FILE) ||
	  mi_rprev(file,read_record2,-1) ||
	  memcmp(read_record,read_record2,reclength) != 0)
      {
	printf("mi_rsame_with_pos lost position\n");
	goto end;
      }
    }
    ant=1;
    while (mi_rnext(file,read_record2,0) == 0 &&
	   memcmp(read_record2+start,key,length) == 0) ant++;
    if (ant != dupp_keys)
    {
      printf("next: Found: %d keys of %d\n",ant,dupp_keys);
      goto end;
    }
    ant=0;
    while (mi_rprev(file,read_record3,0) == 0 &&
	   memcmp(read_record3+start,key,length) == 0) ant++;
    if (ant != dupp_keys)
    {
      printf("prev: Found: %d records of %d\n",ant,dupp_keys);
      goto end;
    }

    /* Check of mi_rnext_same */
    if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      goto err;
    ant=1;
    while (!mi_rnext_same(file,read_record3) && ant < dupp_keys+10)
      ant++;
    if (ant != dupp_keys || my_errno != HA_ERR_END_OF_FILE)
    {
      printf("mi_rnext_same: Found: %d records of %d\n",ant,dupp_keys);
      goto end;
    }
  }

  if (!silent)
    printf("- All keys: first - next -> last - prev -> first\n");
  DBUG_PRINT("progpos",("All keys: first - next -> last - prev -> first"));
  ant=1;
  if (mi_rfirst(file,read_record,0))
  {
    printf("Can't find first record\n");
    goto end;
  }
  while ((error=mi_rnext(file,read_record3,0)) == 0 && ant < write_count+10)
    ant++;
  if (ant != write_count - opt_delete || error != HA_ERR_END_OF_FILE)
  {
    printf("next: I found: %d records of %d (error: %d)\n",
	   ant, write_count - opt_delete, error);
    goto end;
  }
  if (mi_rlast(file,read_record2,0) ||
      memcmp(read_record2,read_record3,reclength))
  {
    printf("Can't find last record\n");
    DBUG_DUMP("record2",(uchar*) read_record2,reclength);
    DBUG_DUMP("record3",(uchar*) read_record3,reclength);
    goto end;
  }
  ant=1;
  while (mi_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 (memcmp(read_record,read_record3,reclength))
  {
    printf("Can't find first record\n");
    goto end;
  }

  if (!silent)
    printf("- Test if: Read first - next - prev - prev - next == first\n");
  DBUG_PRINT("progpos",("- Read first - next - prev - prev - next == first"));
  if (mi_rfirst(file,read_record,0) ||
      mi_rnext(file,read_record3,0) ||
      mi_rprev(file,read_record3,0) ||
      mi_rprev(file,read_record3,0) == 0 ||
      mi_rnext(file,read_record3,0))
      goto err;
  if (memcmp(read_record,read_record3,reclength) != 0)
     printf("Can't find first record\n");

  if (!silent)
    printf("- Test if: Read last - prev - next - next - prev == last\n");
  DBUG_PRINT("progpos",("Read last - prev - next - next - prev == last"));
  if (mi_rlast(file,read_record2,0) ||
      mi_rprev(file,read_record3,0) ||
      mi_rnext(file,read_record3,0) ||
      mi_rnext(file,read_record3,0) == 0 ||
      mi_rprev(file,read_record3,0))
      goto err;
  if (memcmp(read_record2,read_record3,reclength))
     printf("Can't find last record\n");
#ifdef NOT_ANYMORE
  if (!silent)
    puts("- Test read key-part");
  strmov(key2,key);
  for(i=strlen(key2) ; i-- > 1 ;)
  {
    key2[i]=0;

    /* The following row is just to catch some bugs in the key code */
    bzero((char*) file->lastkey,file->s->base.max_key_length*2);
    if (mi_rkey(file,read_record,0,key2,(uint) i,HA_READ_PREFIX))
      goto err;
    if (memcmp(read_record+start,key,(uint) i))
    {
      puts("Didn't find right record");
      goto end;
    }
  }
#endif
  if (dupp_keys > 2)
  {
    if (!silent)
      printf("- Read key (first) - next - delete - next -> last\n");
    DBUG_PRINT("progpos",("first - next - delete - next -> last"));
    if (mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      goto err;
    if (mi_rnext(file,read_record3,0)) goto err;
    if (mi_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    while (mi_rnext(file,read_record3,0) == 0 &&
	   memcmp(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)
  {
    if (!silent)
      printf("- Read last of key - prev - delete - prev -> first\n");
    DBUG_PRINT("progpos",("last - prev - delete - prev -> first"));
    if (mi_rprev(file,read_record3,0)) goto err;
    if (mi_rprev(file,read_record3,0)) goto err;
    if (mi_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    while (mi_rprev(file,read_record3,0) == 0 &&
	   memcmp(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)
  {
    if (!silent)
      printf("- Read first - delete - next -> last\n");
    DBUG_PRINT("progpos",("first - delete - next -> last"));
    if (mi_rkey(file,read_record3,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
      goto err;
    if (mi_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=1;
    if (mi_rnext(file,read_record,0))
      goto err;					/* Skall finnas poster */
    while (mi_rnext(file,read_record3,0) == 0 &&
	   memcmp(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;
    }

    if (!silent)
      printf("- Read last - delete - prev -> first\n");
    DBUG_PRINT("progpos",("last - delete - prev -> first"));
    if (mi_rprev(file,read_record3,0)) goto err;
    if (mi_delete(file,read_record3)) goto err;
    opt_delete++;
    ant=0;
    while (mi_rprev(file,read_record3,0) == 0 &&
	   memcmp(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;
    }
  }

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

  bmove(read_record2,read_record,reclength);
  for (i=min(2,keys) ; i-- > 0 ;)
  {
    if (mi_rsame(file,read_record2,(int) i)) goto err;
    if (memcmp(read_record,read_record2,reclength) != 0)
    {
      printf("is_rsame didn't find same record\n");
      goto end;
    }
  }
  if (!silent)
    puts("- Test mi_records_in_range");
  mi_status(file,&info,HA_STATUS_VARIABLE);
  for (i=0 ; i < info.keys ; i++)
  {
    key_range min_key, max_key;
    if (mi_rfirst(file,read_record,(int) i) ||
	mi_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);
    min_key.key= key;
    min_key.keypart_map= HA_WHOLE_KEY;
    min_key.flag= HA_READ_KEY_EXACT;
    max_key.key= key2;
    max_key.keypart_map= HA_WHOLE_KEY;
    max_key.flag= HA_READ_AFTER_KEY;

    range_records= mi_records_in_range(file,(int) i, &min_key, &max_key);
    if (range_records < info.records*8/10 ||
	range_records > info.records*12/10)
    {
      printf("mi_records_range returned %ld; Should be about %ld\n",
	     (long) range_records,(long) info.records);
      goto end;
    }
    if (verbose)
    {
      printf("mi_records_range returned %ld;  Exact is %ld  (diff: %4.2g %%)\n",
	     (long) range_records, (long) info.records,
	     labs((long) range_records - (long) info.records)*100.0/
	     info.records);
    }
  }
  for (i=0 ; i < 5 ; i++)
  {
    for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
    for (k=rnd(1000)+1 ; k>0 && key1[k] == 0 ; k--) ;
    if (j != 0 && k != 0)
    {
      key_range min_key, max_key;
      if (j > k)
	swap_variables(int, j, k);
      sprintf((char*) key,"%6d",j);
      sprintf((char*) key2,"%6d",k);

      min_key.key= key;
      min_key.length= USE_WHOLE_KEY;
      min_key.flag= HA_READ_AFTER_KEY;
      max_key.key= key2;
      max_key.length= USE_WHOLE_KEY;
      max_key.flag= HA_READ_BEFORE_KEY;
      range_records= mi_records_in_range(file, 0, &min_key, &max_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*14/10+2)
      {
	printf("mi_records_range for key: %d returned %lu; Should be about %lu\n",
	       i, (ulong) range_records, (ulong) records);
	goto end;
      }
      if (verbose && records)
      {
	printf("mi_records_range returned %lu;  Exact is %lu  (diff: %4.2g %%)\n",
	       (ulong) range_records, (ulong) records,
	       labs((long) range_records-(long) records)*100.0/records);

      }
    }
    }

  if (!silent)
    printf("- mi_info\n");
  mi_status(file,&info,HA_STATUS_VARIABLE | HA_STATUS_CONST);
  if (info.records != write_count-opt_delete || info.deleted > opt_delete + update
      || info.keys != keys)
  {
    puts("Wrong info from mi_info");
    printf("Got: records: %lu  delete: %lu  i_keys: %d\n",
	   (ulong) info.records, (ulong) 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.check_time);
    printf("info: checked %s\n",buff);
    get_date(buff,3,info.update_time);
    printf("info: Modified %s\n",buff);
  }

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

  if (!silent)
    printf("- mi_extra(CACHE) + mi_rrnd.... + mi_extra(NO_CACHE)\n");
  if (mi_reset(file) || mi_extra(file,HA_EXTRA_CACHE,0))
  {
    if (locking || (!use_blob && !pack_fields))
    {
      puts("got error from mi_extra(HA_EXTRA_CACHE)");
      goto end;
    }
  }
  ant=0;
  while ((error=mi_rrnd(file,record,HA_OFFSET_ERROR)) != HA_ERR_END_OF_FILE &&
	 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 (mi_extra(file,HA_EXTRA_NO_CACHE,0))
  {
    puts("got error from mi_extra(HA_EXTRA_NO_CACHE)");
    goto end;
  }

  ant=0;
  mi_scan_init(file);
  while ((error=mi_scan(file,record)) != HA_ERR_END_OF_FILE &&
	 ant < write_count + 10)
	ant+= error ? 0 : 1;
  if (ant != write_count-opt_delete)
  {
    printf("scan with cache: I can only find: %d records of %d\n",
	   ant,write_count-opt_delete);
    goto end;
  }

  if (testflag == 4) goto end;

  if (!silent)
    printf("- Removing keys\n");
  DBUG_PRINT("progpos",("Removing keys"));
  lastpos = HA_OFFSET_ERROR;
  /* DBUG_POP(); */
  mi_reset(file);
  found_parts=0;
  while ((error=mi_rrnd(file,read_record,HA_OFFSET_ERROR)) !=
	 HA_ERR_END_OF_FILE)
  {
    info.recpos=mi_position(file);
    if (lastpos >= info.recpos && lastpos != HA_OFFSET_ERROR)
    {
      printf("mi_rrnd didn't advance filepointer; old: %ld, new: %ld\n",
	     (long) lastpos, (long) info.recpos);
      goto err;
    }
    lastpos=info.recpos;
    if (error == 0)
    {
      if (opt_delete == (uint) remove_count)		/* While testing */
	goto end;
      if (mi_rsame(file,read_record,-1))
      {
	printf("can't find record %lx\n",(long) 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",(long) lastpos);
	    use_blob=0;
	    break;
	  }
	}
      }
      if (mi_delete(file,read_record))
      {
	printf("can't delete record: %6.6s,  delete_count: %d\n",
	       read_record, opt_delete);
	goto err;
      }
      opt_delete++;
    }
    else
      found_parts++;
  }
  if (my_errno != HA_ERR_END_OF_FILE && my_errno != HA_ERR_RECORD_DELETED)
    printf("error: %d from mi_rrnd\n",my_errno);
  if (write_count != opt_delete)
  {
    printf("Deleted only %d of %d records (%d parts)\n",opt_delete,write_count,
	   found_parts);
    goto err;
  }
end:
  if (mi_close(file))
    goto err;
  mi_panic(HA_PANIC_CLOSE);			/* Should close log */
  if (!silent)
  {
    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);
    printf("myisam_block_size:    %lu\n", myisam_block_size);
    if (key_cacheing)
    {
      puts("Key cache used");
      printf("key_cache_block_size: %u\n", key_cache_block_size);
      if (write_cacheing)
	puts("Key cache resized");
    }
    if (write_cacheing)
      puts("Write cacheing used");
    if (write_cacheing)
      puts("quick mode");
    if (async_io && locking)
      puts("Asyncron io with locking used");
    else if (locking)
      puts("Locking used");
    if (use_blob)
      puts("blobs used");
    printf("key cache status: \n\
blocks used:%10lu\n\
not flushed:%10lu\n\
w_requests: %10lu\n\
writes:     %10lu\n\
r_requests: %10lu\n\
reads:      %10lu\n",
           dflt_key_cache->blocks_used,
           dflt_key_cache->global_blocks_changed,
           (ulong) dflt_key_cache->global_cache_w_requests,
           (ulong) dflt_key_cache->global_cache_write,
           (ulong) dflt_key_cache->global_cache_r_requests,
           (ulong) dflt_key_cache->global_cache_read);
  }
Exemplo n.º 27
0
MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
{
  int save_errno,i,errpos;
  uint files,dir_length,length,key_parts;
  ulonglong file_offset;
  char name_buff[FN_REFLEN*2],buff[FN_REFLEN],*end;
  MYRG_INFO info,*m_info;
  File fd;
  IO_CACHE file;
  MI_INFO *isam,*last_isam;
  DBUG_ENTER("myrg_open");

  LINT_INIT(last_isam);
  LINT_INIT(m_info);
  isam=0;
  errpos=files=0;
  bzero((gptr) &info,sizeof(info));
  bzero((char*) &file,sizeof(file));
  if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT,4),
		  O_RDONLY | O_SHARE,MYF(0))) < 0 ||
      init_io_cache(&file, fd, IO_SIZE, READ_CACHE, 0, 0,
		    MYF(MY_WME | MY_NABP)))
    goto err;
  errpos=1;
  dir_length=dirname_part(name_buff,name);
  info.reclength=0;
  while ((length=my_b_gets(&file,buff,FN_REFLEN-1)))
  {
    if ((end=buff+length)[-1] == '\n')
      end[-1]='\0';
    if (!buff[0])
      continue;		/* Skip empty lines */
    if (buff[0] == '#')
    {
      if( !strncmp(buff+1,"INSERT_METHOD=",14))
      {			/* Lookup insert method */
	int tmp=find_type(buff+15,&merge_insert_method,2);
	info.merge_insert_method = (uint) (tmp >= 0 ? tmp : 0);
      }
      continue;		/* Skip comments */
    }

    if (!test_if_hard_path(buff))
    {
      VOID(strmake(name_buff+dir_length,buff,
                   sizeof(name_buff)-1-dir_length));
      VOID(cleanup_dirname(buff,name_buff));
    }
    if (!(isam=mi_open(buff,mode,(handle_locking?HA_OPEN_WAIT_IF_LOCKED:0))))
	goto err;
    files++;
    last_isam=isam;
    if (info.reclength && info.reclength != isam->s->base.reclength)
    {
      my_errno=HA_ERR_WRONG_MRG_TABLE_DEF;
      goto err;
    }
    info.reclength=isam->s->base.reclength;
  }
  key_parts=(isam ? isam->s->base.key_parts : 0);
  if (!(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO)+
                                       files*sizeof(MYRG_TABLE)+
                                       sizeof(long)*key_parts,
				       MYF(MY_WME))))
    goto err;
  *m_info=info;
  m_info->tables=files;
  if (files)
  {
    m_info->open_tables=(MYRG_TABLE *) (m_info+1);
    m_info->rec_per_key_part=(ulong *) (m_info->open_tables+files);
    bzero((char*) m_info->rec_per_key_part,sizeof(long)*key_parts);
  }
  else
  {
    m_info->open_tables=0;
    m_info->rec_per_key_part=0;
  }
  errpos=2;

  for (i=files ; i-- > 0 ; )
  {
    uint j;
    m_info->open_tables[i].table=isam;
    m_info->options|=isam->s->options;
    m_info->records+=isam->state->records;
    m_info->del+=isam->state->del;
    m_info->data_file_length+=isam->state->data_file_length;
    for (j=0; j < key_parts; j++)
      m_info->rec_per_key_part[j]+=isam->s->state.rec_per_key_part[j] / files;
    if (i)
      isam=(MI_INFO*) (isam->open_list.next->data);
  }
  /* Don't mark table readonly, for ALTER TABLE ... UNION=(...) to work */
  m_info->options&= ~(HA_OPTION_COMPRESS_RECORD | HA_OPTION_READ_ONLY_DATA);

  /* Fix fileinfo for easyer debugging (actually set by rrnd) */
  file_offset=0;
  for (i=0 ; (uint) i < files ; i++)
  {
    m_info->open_tables[i].file_offset=(my_off_t) file_offset;
    file_offset+=m_info->open_tables[i].table->state->data_file_length;
  }
  if (sizeof(my_off_t) == 4 && file_offset > (ulonglong) (ulong) ~0L)
  {
    my_errno=HA_ERR_RECORD_FILE_FULL;
    goto err;
  }
  m_info->keys=(files) ? m_info->open_tables->table->s->base.keys : 0;
  bzero((char*) &m_info->by_key,sizeof(m_info->by_key));

  /* this works ok if the table list is empty */
  m_info->end_table=m_info->open_tables+files;
  m_info->last_used_table=m_info->open_tables;

  VOID(my_close(fd,MYF(0)));
  end_io_cache(&file);
  m_info->open_list.data=(void*) m_info;
  pthread_mutex_lock(&THR_LOCK_open);
  myrg_open_list=list_add(myrg_open_list,&m_info->open_list);
  pthread_mutex_unlock(&THR_LOCK_open);
  DBUG_RETURN(m_info);

err:
  save_errno=my_errno;
  switch (errpos) {
  case 2:
    my_free((char*) m_info,MYF(0));
    /* Fall through */
  case 1:
    VOID(my_close(fd,MYF(0)));
    end_io_cache(&file);
    for (i=files ; i-- > 0 ; )
    {
      isam=last_isam;
      if (i)
	last_isam=(MI_INFO*) (isam->open_list.next->data);
      mi_close(isam);
    }
  }
  my_errno=save_errno;
  DBUG_RETURN (NULL);
}