Esempio n. 1
0
int attachsql_drv_init(void)
{
  args.hosts = sb_get_value_list("attachsql-host");
  if (SB_LIST_IS_EMPTY(args.hosts))
  {
    log_text(LOG_FATAL, "No libAttachSQL hosts specified, aborting");
    return 1;
  }
  hosts_pos = args.hosts;
  pthread_mutex_init(&hosts_mutex, NULL);
  
  args.port = (unsigned int)sb_get_value_int("attachsql-port");
  args.socket = sb_get_value_string("attachsql-socket");
  args.user = sb_get_value_string("attachsql-user");
  args.password = sb_get_value_string("attachsql-password");
  args.db = sb_get_value_string("attachsql-db");
  attachsql_library_init();
  return 0;
}
Esempio n. 2
0
int mysql_drv_init(void)
{
  char *s;
  
  args.hosts = sb_get_value_list("mysql-host");
  if (SB_LIST_IS_EMPTY(args.hosts))
  {
    log_text(LOG_FATAL, "No MySQL hosts specified, aborting");
    return 1;
  }
  hosts_pos = args.hosts;
  pthread_mutex_init(&hosts_mutex, NULL);
  
  args.port = sb_get_value_int("mysql-port");
  args.socket = sb_get_value_string("mysql-socket");
  args.user = sb_get_value_string("mysql-user");
  args.password = sb_get_value_string("mysql-password");
  args.db = sb_get_value_string("mysql-db");
  args.myisam_max_rows = sb_get_value_int("myisam-max-rows");
  args.use_ssl = sb_get_value_flag("mysql-ssl");
  args.create_options = sb_get_value_string("mysql-create-options");
  if (args.create_options == NULL)
    args.create_options = "";
  
  use_ps = 0;
#ifdef HAVE_PS
  mysql_drv_caps.prepared_statements = 1;
  if (db_globals.ps_mode != DB_PS_MODE_DISABLE)
    use_ps = 1;
#endif

  s = sb_get_value_string("mysql-engine-trx");
  if (s == NULL)
  {
    log_text(LOG_FATAL, "--mysql-engine-trx requires an argument");
    return 1;
  }
  if (!strcasecmp(s, "yes"))
    args.engine_trx = ENGINE_TRX_YES;
  else if (!strcasecmp(s, "no"))
    args.engine_trx = ENGINE_TRX_NO;
  else if (!strcasecmp(s, "auto"))
    args.engine_trx = ENGINE_TRX_AUTO;
  else
  {
    log_text(LOG_FATAL, "Invalid value for mysql-engine-trx: %s", s);
    return 1;
  }
  
  s = sb_get_value_string("mysql-table-engine");

  mysql_library_init(0, NULL, NULL);
  
  return parse_table_engine(s);
}
Esempio n. 3
0
int memory_init(void)
{
  unsigned int i;
  char         *s;
  
  memory_block_size = sb_get_value_size("memory-block-size");
  if (memory_block_size % sizeof(int) != 0)
  {
    log_text(LOG_FATAL, "memory-block-size must be a multiple of %ld!", (long)sizeof(int));
    return 1;
  }
  memory_total_size = sb_get_value_size("memory-total-size");
  
  s = sb_get_value_string("memory-scope");
  if (!strcmp(s, "global"))
    memory_scope = SB_MEM_SCOPE_GLOBAL;
  else if (!strcmp(s, "local"))
    memory_scope = SB_MEM_SCOPE_LOCAL;
  else
  {
    log_text(LOG_FATAL, "Invalid value for memory-scope: %s", s);
    return 1;
  }

#ifdef HAVE_LARGE_PAGES
    memory_hugetlb = sb_get_value_flag("memory-hugetlb");
#endif  

  s = sb_get_value_string("memory-oper");
  if (!strcmp(s, "write"))
    memory_oper = SB_MEM_OP_WRITE;
  else if (!strcmp(s, "read"))
    memory_oper = SB_MEM_OP_READ;
  else if (!strcmp(s, "none"))
    memory_oper = SB_MEM_OP_NONE;
  else
  {
    log_text(LOG_FATAL, "Invalid value for memory-oper: %s", s);
    return 1;
  }

  s = sb_get_value_string("memory-access-mode");
  if (!strcmp(s, "seq"))
    memory_access_rnd = 0;
  else if (!strcmp(s, "rnd"))
    memory_access_rnd = 1;
  else
  {
    log_text(LOG_FATAL, "Invalid value for memory-access-mode: %s", s);
    return 1;
  }
  
  if (memory_scope == SB_MEM_SCOPE_GLOBAL)
  {
#ifdef HAVE_LARGE_PAGES
    if (memory_hugetlb)
      buffer = (int *)hugetlb_alloc(memory_block_size);
    else
#endif
    buffer = (int *)malloc(memory_block_size);
    if (buffer == NULL)
    {
      log_text(LOG_FATAL, "Failed to allocate buffer!");
      return 1;
    }

    memset(buffer, 0, memory_block_size);
  }
  else
  {
    buffers = (int **)malloc(sb_globals.num_threads * sizeof(char *));
    if (buffers == NULL)
    {
      log_text(LOG_FATAL, "Failed to allocate buffers array!");
      return 1;
    }
    for (i = 0; i < sb_globals.num_threads; i++)
    {
#ifdef HAVE_LARGE_PAGES
      if (memory_hugetlb)
        buffers[i] = (int *)hugetlb_alloc(memory_block_size);
      else
#endif
      buffers[i] = (int *)malloc(memory_block_size);
      if (buffers[i] == NULL)
      {
        log_text(LOG_FATAL, "Failed to allocate buffer for thread #%d!", i);
        return 1;
      }

      memset(buffers[i], 0, memory_block_size);
    }
  }
  
  return 0;
}
Esempio n. 4
0
int parse_arguments(void)
{
  char         *mode;
  
  num_files = sb_get_value_int("file-num");

  if (num_files <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-num: %d", num_files);
    return 1;
  }
  total_size = sb_get_value_size("file-total-size");
  if (total_size <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-total-size: %lld",
             (long long)total_size);
    return 1;
  }
  file_size = total_size / num_files;
  
  mode = sb_get_value_string("file-test-mode");

  /* File test mode is necessary only for 'run' command */
  if (sb_globals.command == SB_COMMAND_RUN)
  {
    if (mode == NULL)
    {
      log_text(LOG_FATAL, "Missing required argument: --file-test-mode");
      sb_print_options(fileio_args);
      return 1;
    }
    if (!strcmp(mode, "seqwr"))
      test_mode = MODE_WRITE;
    else if (!strcmp(mode, "seqrewr"))
      test_mode = MODE_REWRITE;
    else if (!strcmp(mode, "seqrd"))
      test_mode = MODE_READ;
    else if (!strcmp(mode, "rndrd"))
      test_mode = MODE_RND_READ;
    else if (!strcmp(mode, "rndwr"))
      test_mode = MODE_RND_WRITE;
    else if (!strcmp(mode, "ag4"))
      test_mode = MODE_AG4_WRITE;
    else if (!strcmp(mode, "rndrw"))
      test_mode = MODE_RND_RW;
    else
    {
      log_text(LOG_FATAL, "Invalid IO operations mode: %s.", mode);
      return 1;
    }
  }
  
  mode  = sb_get_value_string("file-io-mode");
  if (mode == NULL)
    mode = "sync";
  if (!strcmp(mode, "sync"))
    file_io_mode = FILE_IO_MODE_SYNC;
  else if (!strcmp(mode, "async"))
  {
#ifdef HAVE_LIBAIO
    file_io_mode = FILE_IO_MODE_ASYNC;
#else
    log_text(LOG_FATAL,
             "asynchronous I/O mode is unsupported on this platform.");
    return 1;
#endif
  }
  else if (!strcmp(mode, "mmap"))
  {
#ifdef HAVE_MMAP
    file_io_mode = FILE_IO_MODE_MMAP;
#else
    log_text(LOG_FATAL,
             "mmap'ed I/O mode is unsupported on this platform.");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "unknown I/O mode: %s", mode);
    return 1;
  }
  
  file_merged_requests = sb_get_value_int("file-merged-requests");
  if (file_merged_requests < 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-merged-requests: %d.",
             file_merged_requests);
    return 1;
  }
  
  file_block_size = sb_get_value_size("file-block-size");
  if (file_block_size <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-block-size: %d.",
             file_block_size);
    return 1;
  }

  if (file_merged_requests > 0)
    file_max_request_size = file_block_size * file_merged_requests;
  else
    file_max_request_size = file_block_size;

  mode = sb_get_value_string("file-extra-flags");
  if (mode == NULL || !strlen(mode))
    file_extra_flags = 0;
  else if (!strcmp(mode, "sync"))
  {
#ifdef _WIN32
    file_extra_flags = FILE_FLAG_WRITE_THROUGH;
#else
    file_extra_flags = O_SYNC;
#endif
  }
  else if (!strcmp(mode, "dsync"))
  {
#ifdef O_DSYNC
    file_extra_flags = O_DSYNC;
#else
    log_text(LOG_FATAL, "O_DSYNC is not supported on this platform.");
    return 1;
#endif
  }
  else if (!strcmp(mode, "direct"))
  {
#ifdef _WIN32
    file_extra_flags = FILE_FLAG_NO_BUFFERING;
#elif defined(O_DIRECT)
    file_extra_flags = O_DIRECT;
#else
    log_text(LOG_FATAL, "O_DIRECT is not supported on this platform.");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "Invalid value for file-extra-flags: %s", mode);
    return 1;
  }
  
  file_fsync_freq = sb_get_value_int("file-fsync-freq");
  if (file_fsync_freq < 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-fsync-freq: %d.",
             file_fsync_freq);
    return 1;
  }

  file_fsync_end = sb_get_value_flag("file-fsync-end");
  file_fsync_all = sb_get_value_flag("file-fsync-all");
  /* file-fsync-all overrides file-fsync-end and file-fsync-freq */
  if (file_fsync_all) {
    file_fsync_end = 0;
    file_fsync_freq = 0;
  }
  
  mode = sb_get_value_string("file-fsync-mode");
  if (!strcmp(mode, "fsync"))
    file_fsync_mode = FSYNC_ALL;
  else if (!strcmp(mode, "fdatasync"))
  {
#ifdef HAVE_FDATASYNC
    file_fsync_mode = FSYNC_DATA;
#else
    log_text(LOG_FATAL, "fdatasync() is unavailable on this platform");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "Invalid fsync mode: %s.", mode);
    return 1;
  }

  file_rw_ratio = sb_get_value_float("file-rw-ratio");
  if (file_rw_ratio < 0)
  {
    log_text(LOG_FATAL, "Invalid value file file-rw-ratio: %f.", file_rw_ratio);
    return 1;
  }

  buffer = sb_memalign(file_max_request_size);

  return 0;
}
Esempio n. 5
0
int mutex_init(void)
{
  unsigned int i;
  char *mutex_type_str;
  pthread_mutexattr_t mutex_attr;
 
  mutex_num = sb_get_value_int("mutex-num");
  mutex_loops = sb_get_value_int("mutex-loops");
  mutex_locks = sb_get_value_int("mutex-locks");
  mutex_type_str = sb_get_value_string("mutex-type");

  if (mutex_type_str == NULL)
  {
    log_text(LOG_FATAL, "Invalid value for --mutex-type");
    return 1;
  } 
  else if (!strcasecmp(mutex_type_str, "mutex"))
  {
    mutex_type = SB_MUTEX;
  }
  else if (!strcasecmp(mutex_type_str, "mutex-adaptive"))
  {
    mutex_type = SB_MUTEX_ADAPTIVE;
  }
  else if (!strcasecmp(mutex_type_str, "rwlock-read"))
  {
    mutex_type = SB_RWLOCK_READ;
  }
  else if (!strcasecmp(mutex_type_str, "rwlock-write"))
  {
    mutex_type = SB_RWLOCK_WRITE;
  }
  else
  {
    log_text(LOG_FATAL, "Invalid value for --mutex-type");
    return 1;
  }

  thread_locks = (thread_lock *)malloc(mutex_num * sizeof(thread_lock));
  if (thread_locks == NULL)
  {
    log_text(LOG_FATAL, "Memory allocation failure!");
    return 1;
  }

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
  pthread_mutexattr_init(&mutex_attr);
  pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
#else
  if (mutex_type == SB_MUTEX_ADAPTIVE)
  {
    log_text(LOG_FATAL, "Platform does not support mutex-adaptive");
    return 1;
  }
#endif

  for (i = 0; i < mutex_num; i++)
  {
    switch (mutex_type)
    {
      case SB_MUTEX:
        pthread_mutex_init(&thread_locks[i].mutex, NULL);
        break;
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
      case SB_MUTEX_ADAPTIVE:
        pthread_mutex_init(&thread_locks[i].mutex, &mutex_attr);
        break;
#endif
      case SB_RWLOCK_READ:
      case SB_RWLOCK_WRITE:
        pthread_rwlock_init(&thread_locks[i].rwlock, NULL);
        break;
    }
  }
  
  return 0;
}