Example #1
0
static PyObject *
FDB_putcat(FDB *self, PyObject *args)
{
    long long key;
    void *value;
    int value_size;
    PyObject *pyvalue;

    if (!PyArg_ParseTuple(args, "LO:putcat", &key, &pyvalue)) {
        return NULL;
    }
    if (bytes_to_void(pyvalue, &value, &value_size)) {
        return NULL;
    }
    if (!tcfdbputcat(self->fdb, key, value, value_size)) {
        return set_fdb_error(self->fdb, 0);
    }
    self->changed = true;
    Py_RETURN_NONE;
}
Example #2
0
/* perform rcat command */
static int procrcat(const char *path, int rnum, int width, int64_t limsiz,
                    bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru){
  my_my_my_iprintf("<Random Concatenating Test>\n"
          "  seed=%u  path=%s  rnum=%d  width=%d  limsiz=%lld  mt=%d  omode=%d  pnum=%d"
          "  dai=%d  dad=%d  rl=%d  ru=%d\n\n",
          g_randseed, path, rnum, width, (long long)limsiz, mt, omode, pnum, dai, dad, rl, ru);
  if(pnum < 1) pnum = rnum;
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, width, limsiz)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(pnum) + 1);
    if(dai){
      if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(3)) == INT_MIN){
        eprint(fdb, __LINE__, "tcfdbaddint");
        err = true;
        break;
      }
    } else if(dad){
      if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(30) / 10.0))){
        eprint(fdb, __LINE__, "tcfdbadddouble");
        err = true;
        break;
      }
    } else if(rl){
      char vbuf[PATH_MAX];
      int vsiz = myrand(PATH_MAX);
      for(int j = 0; j < vsiz; j++){
        vbuf[j] = myrand(0x100);
      }
      if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
        eprint(fdb, __LINE__, "tcfdbputcat");
        err = true;
        break;
      }
    } else if(ru){
      int id = myrand(pnum) + 1;
      switch(myrand(8)){
        case 0:
          if(!tcfdbput(fdb, id, kbuf, ksiz)){
            eprint(fdb, __LINE__, "tcfdbput");
            err = true;
          }
          break;
        case 1:
          if(!tcfdbputkeep(fdb, id, kbuf, ksiz) && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbputkeep");
            err = true;
          }
          break;
        case 2:
          if(!tcfdbout(fdb, id) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout");
            err = true;
          }
          break;
        case 3:
          if(tcfdbaddint(fdb, id, 1) == INT_MIN && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbaddint");
            err = true;
          }
          break;
        case 4:
          if(isnan(tcfdbadddouble(fdb, id, 1.0)) && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbadddouble");
            err = true;
          }
          break;
        case 5:
          if(myrand(2) == 0){
            if(!tcfdbputproc(fdb, id, kbuf, ksiz, pdprocfunc, NULL) &&
               tcfdbecode(fdb) != TCEKEEP){
              eprint(fdb, __LINE__, "tcfdbputproc");
              err = true;
            }
          } else {
            if(!tcfdbputproc(fdb, id, NULL, 0, pdprocfunc, NULL) &&
               tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbputproc");
              err = true;
            }
          }
          break;
        default:
          if(!tcfdbputcat(fdb, id, kbuf, ksiz)){
            eprint(fdb, __LINE__, "tcfdbputcat");
            err = true;
          }
          break;
      }
      if(err) break;
    } else {
      if(!tcfdbputcat2(fdb, kbuf, ksiz, kbuf, ksiz)){
        eprint(fdb, __LINE__, "tcfdbputcat");
        err = true;
        break;
      }
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}