Exemplo n.º 1
0
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
                        bool df){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(df){
    if(!tchdbdefrag(hdb, INT64_MAX)){
      printerr(hdb);
      err = true;
    }
  } else {
    if(!tchdboptimize(hdb, bnum, apow, fpow, opts)){
      printerr(hdb);
      err = true;
    }
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
Exemplo n.º 2
0
void Retsu::Column::optimize() {
	if(tchdbrnum(this->database) % (1<<16) == 0) {
		if(!tchdboptimize(database, -1, -1, -1, HDBTLARGE | HDBTDEFLATE)) {
      throw StorageError("Could not optimize column at " + path());
    }
	}
}
Exemplo n.º 3
0
static bool OpenTokyoDatabase(const char *filename, TCHDB **hdb)
{
    *hdb = tchdbnew();

    if (!tchdbsetmutex(*hdb))
    {
        return false;
    }

    if (!tchdbopen(*hdb, filename, HDBOWRITER | HDBOCREAT))
    {
        return false;
    }

    static int threshold = -1; /* GLOBAL_X */

    if (threshold == -1)
    {
        /** 
           Optimize always if TCDB_OPTIMIZE_PERCENT is equal to 100
           Never optimize if  TCDB_OPTIMIZE_PERCENT is equal to 0
         */
        const char *perc = getenv("TCDB_OPTIMIZE_PERCENT");
        if (perc != NULL)
        {
            /* Environment variable exists */
            char *end;
            long result = strtol(perc, &end, 10);
 
            /* Environment variable is a number and in 0..100 range */
            if (!*end && result >-1 && result < 101)
            {
               threshold = 100 - (int)result;
            }
            else
            {
                /* This corresponds to 1% */
                threshold = 99; 
            }
        }
        else
        {
            /* This corresponds to 1% */
            threshold = 99; 
        }
    }
    if ((threshold != 100) && (threshold == 0 || (int)(rand()%threshold) == 0))
    {
        if (!tchdboptimize(*hdb, -1, -1, -1, false))
        {
            tchdbclose(*hdb);
            return false;
        }
    }

    return true;
}
Exemplo n.º 4
0
static mrb_value
hdb_optimize(mrb_state *mrb, mrb_value self)
{
  hdb_context *context = DATA_PTR(self);
  bool result;
  mrb_int bnum, apow, fpow , opts;


  mrb_get_args(mrb, "iiii", &bnum, &apow, &fpow, &opts);

  result = tchdboptimize(context->hdb, bnum, apow, fpow, opts);

  return mrb_bool_value(result);
}
Exemplo n.º 5
0
Arquivo: tchmgr.c Projeto: kadoma/fms
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdboptimize(hdb, bnum, apow, fpow, opts)){
    printerr(hdb);
    err = true;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
Exemplo n.º 6
0
 bool db_obj_local::dboptimize(int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts)
 {
   return tchdboptimize(_hdb,bnum,apow,fpow,opts);
 }
Exemplo n.º 7
0
/* optimize */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_optimize
(JNIEnv *env, jobject self, jlong bnum, jint apow, jint fpow, jint opts){
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  return tchdboptimize(hdb, bnum, apow, fpow, opts);
}