Пример #1
0
void
grn_ctx_impl_mrb_fin(grn_ctx *ctx)
{
  if (ctx->impl->mrb.state) {
    mrb_close(ctx->impl->mrb.state);
    ctx->impl->mrb.state = NULL;
    grn_hash_close(ctx, ctx->impl->mrb.checked_procs);
    grn_hash_close(ctx, ctx->impl->mrb.registered_plugins);
    GRN_OBJ_FIN(ctx, &(ctx->impl->mrb.buffer.from));
    GRN_OBJ_FIN(ctx, &(ctx->impl->mrb.buffer.to));
  }
}
Пример #2
0
void
test_read_write(gconstpointer *data)
{
  gint i, key;
  int added;
  grn_ctx *context;
  grn_hash *hash;
  const gchar *path;
  const gchar *value_string;
  gint process_number = 0;
  const gchar *process_number_string;
  void *value;
  grn_id id = GRN_ID_NIL;
  grn_rc rc;

  i = GPOINTER_TO_INT(data);
  process_number_string = g_getenv(GRN_TEST_ENV_PROCESS_NUMBER);
  if (process_number_string)
    process_number = atoi(process_number_string);

  key = i + process_number * N_THREADS;

  rc = grn_ctx_init(contexts[i], GRN_CTX_USE_QL);
  grn_test_assert(rc, cut_message("context: %d (%d)", i, process_number));
  context = contexts[i];

  path = g_getenv(GRN_TEST_ENV_HASH_PATH);
  cut_assert_not_null(path);
  hashes[i] = grn_hash_open(context, path);
  cut_assert_not_null(hashes[i],
                      cut_message("hash: %d (%d)", i, process_number));
  hash = hashes[i];

  grn_test_assert_nil(
    grn_hash_get(context, hash, &key, sizeof(key), &value),
    cut_message("lookup - fail: %d (%d:%d)", key, i, process_number));

  value_string = cut_take_printf("value: %d (%d:%d)", key, i, process_number);
  rc = grn_io_lock(context, hash->io, -1);
  if (rc != GRN_SUCCESS)
    grn_test_assert(rc);
  id = grn_hash_add(context, hash, &key, sizeof(key), &value, &added);
  grn_io_unlock(hash->io);
  grn_test_assert_not_nil(id);
  cut_assert_equal_int(1, added);
  strcpy(value, value_string);

  value = NULL;
  id = grn_hash_get(context, hash, &key, sizeof(key), &value);
  grn_test_assert_not_nil(
    id,
    cut_message("lookup - success: %d (%d:%d)", key, i, process_number));
  cut_assert_equal_string(value_string, value);

  hashes[i] = NULL;
  grn_test_assert(grn_hash_close(context, hash));

  contexts[i] = NULL;
  grn_test_assert(grn_ctx_fin(context));
}
Пример #3
0
int
hash_put(const char *path)
{
  int i;
  grn_obj buf;
  grn_hash *hash = grn_hash_create(&ctx, path, key_size, value_size,
                                   GRN_OBJ_PERSISTENT|GRN_OBJ_KEY_VAR_SIZE);
  if (!hash) { return -1; }
  GRN_TEXT_INIT(&buf, 0);
  for (i = 0; i < nloops; i++) {
    int key = GENKEY(i);
    GRN_BULK_REWIND(&buf);
    grn_text_itoh(&ctx, &buf, key, key_size);
    {
      void *value;
      grn_id rid = grn_hash_add(&ctx, hash, GRN_BULK_HEAD(&buf), key_size, &value, NULL);
      if (!rid) {
        fprintf(stderr, "table_lookup failed");
      } else {
        memcpy(value, GRN_BULK_HEAD(&buf), value_size);
      }
    }
  }
  grn_obj_close(&ctx, &buf);
  grn_hash_close(&ctx, hash);
  return 0;
}
Пример #4
0
int
hash_get(const char *path)
{
  int i;
  grn_obj buf;
  grn_hash *hash = grn_hash_open(&ctx, path);
  if (!hash) { return -1; }
  GRN_TEXT_INIT(&buf, 0);
  for (i = 0; i < nloops; i++) {
    int key = GENKEY(i);
    GRN_BULK_REWIND(&buf);
    grn_text_itoh(&ctx, &buf, key, key_size);
    {
      void *value;
      grn_id rid = grn_hash_get(&ctx, hash, GRN_BULK_HEAD(&buf), key_size, &value);
      if (!rid) {
        fprintf(stderr, "table_lookup failed");
      } else {
        if (memcmp(value, GRN_BULK_HEAD(&buf), value_size)) {
          fprintf(stderr, "value unmatch %d: %d != %d\n", i, *((int *)value), key);
        }
      }
    }
  }
  grn_obj_close(&ctx, &buf);
  grn_hash_close(&ctx, hash);
  return 0;
}
Пример #5
0
static void
grn_ctx_ql_init(grn_ctx *ctx, int flags)
{
  if (!ctx->impl) {
    grn_ctx_impl_init(ctx);
    if (ERRP(ctx, GRN_ERROR)) { return; }
  }
  if (flags & GRN_CTX_BATCH_MODE) { ctx->impl->batchmode = 1; }
  if ((ctx->impl->objects = grn_array_create(ctx, NULL, sizeof(grn_cell),
                                             GRN_ARRAY_TINY))) {
    if ((ctx->impl->symbols = grn_hash_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE,
                                              sizeof(grn_cell),
                                              GRN_OBJ_KEY_VAR_SIZE|GRN_HASH_TINY))) {
      if (!ERRP(ctx, GRN_ERROR)) {
        grn_ql_init_globals(ctx);
        if (!ERRP(ctx, GRN_ERROR)) {
          return;
        }
      }
      grn_hash_close(ctx, ctx->impl->symbols);
      ctx->impl->symbols = NULL;
    } else {
      MERR("ctx->impl->symbols init failed");
    }
    grn_array_close(ctx, ctx->impl->objects);
    ctx->impl->objects = NULL;
  } else {
    MERR("ctx->impl->objects init failed");
  }
}
Пример #6
0
static void
hash_free(void)
{
  if (context && hash) {
    grn_hash_close(context, hash);
    hash = NULL;
  }
}
Пример #7
0
grn_rc
GRN_PLUGIN_FIN(grn_ctx *ctx)
{
  if (synonyms) {
    grn_hash_close(ctx, synonyms);
    synonyms = NULL;
  }
  return GRN_SUCCESS;
}
Пример #8
0
grn_rc
grn_com_event_init(grn_ctx *ctx, grn_com_event *ev, int max_nevents, int data_size)
{
    ev->max_nevents = max_nevents;
    if ((ev->hash = grn_hash_create(ctx, NULL, sizeof(grn_sock), data_size, 0))) {
        MUTEX_INIT(ev->mutex);
        COND_INIT(ev->cond);
        GRN_COM_QUEUE_INIT(&ev->recv_old);
        ev->msg_handler = NULL;
        memset(&(ev->curr_edge_id), 0, sizeof(grn_com_addr));
        ev->acceptor = NULL;
        ev->opaque = NULL;
#ifndef USE_SELECT
# ifdef USE_EPOLL
        if ((ev->events = GRN_MALLOC(sizeof(struct epoll_event) * max_nevents))) {
            if ((ev->epfd = epoll_create(max_nevents)) != -1) {
                goto exit;
            } else {
                SERR("epoll_create");
            }
            GRN_FREE(ev->events);
        }
# else /* USE_EPOLL */
#  ifdef USE_KQUEUE
        if ((ev->events = GRN_MALLOC(sizeof(struct kevent) * max_nevents))) {
            if ((ev->kqfd = kqueue()) != -1) {
                goto exit;
            } else {
                SERR("kqueue");
            }
            GRN_FREE(ev->events);
        }
#  else /* USE_KQUEUE */
        if ((ev->events = GRN_MALLOC(sizeof(struct pollfd) * max_nevents))) {
            goto exit;
        }
#  endif /* USE_KQUEUE*/
# endif /* USE_EPOLL */
        grn_hash_close(ctx, ev->hash);
        ev->hash = NULL;
        ev->events = NULL;
#else /* USE_SELECT */
        goto exit;
#endif /* USE_SELECT */
    }
exit :
    return ctx->rc;
}
Пример #9
0
/* grn_ts_writer_expand() expands a wildcard. */
static grn_rc
grn_ts_writer_expand(grn_ctx *ctx, grn_ts_writer *writer,
                     grn_obj *table, grn_ts_str str)
{
  grn_rc rc = GRN_SUCCESS;
  grn_hash_cursor *cursor;
  grn_hash *hash = grn_hash_create(ctx, NULL, sizeof(grn_ts_id), 0,
                                   GRN_OBJ_TABLE_HASH_KEY | GRN_HASH_TINY);
  if (!hash) {
    return GRN_INVALID_ARGUMENT;
  }
  grn_table_columns(ctx, table, str.ptr, str.size - 1, (grn_obj *)hash);
  if (ctx->rc != GRN_SUCCESS) {
    return ctx->rc;
  }
  cursor = grn_hash_cursor_open(ctx, hash, NULL, 0, NULL, 0, 0, -1, 0);
  if (!cursor) {
    rc = GRN_INVALID_ARGUMENT;
  } else {
    while (grn_hash_cursor_next(ctx, cursor) != GRN_ID_NIL) {
      char name_buf[GRN_TABLE_MAX_KEY_SIZE];
      size_t name_size;
      grn_obj *column;
      grn_ts_id *column_id;
      if (!grn_hash_cursor_get_key(ctx, cursor, (void **)&column_id)) {
        rc = GRN_INVALID_ARGUMENT;
        break;
      }
      column = grn_ctx_at(ctx, *column_id);
      if (!column) {
        rc = GRN_INVALID_ARGUMENT;
        break;
      }
      name_size = grn_column_name(ctx, column, name_buf, sizeof(name_buf));
      grn_obj_unlink(ctx, column);
      rc = grn_vector_add_element(ctx, &writer->name_buf,
                                  name_buf, name_size, 0, GRN_DB_TEXT);
      if (rc != GRN_SUCCESS) {
        break;
      }
    }
    grn_hash_cursor_close(ctx, cursor);
  }
  grn_hash_close(ctx, hash);
  return rc;
}
Пример #10
0
void
cut_shutdown(void)
{
  int i;

  for (i = 0; i < N_THREADS; i++) {
    grn_ctx *context;

    context = contexts[i];
    if (context) {
      grn_hash *hash;

      hash = hashes[i];
      if (hash)
        grn_hash_close(context, hash);
      grn_ctx_fin(context);
    }
  }
}
Пример #11
0
grn_rc
grn_com_event_fin(grn_ctx *ctx, grn_com_event *ev)
{
  grn_obj *msg;
  while ((msg = (grn_obj *)grn_com_queue_deque(ctx, &ev->recv_old))) {
    grn_msg_close(ctx, msg);
  }
  if (ev->hash) { grn_hash_close(ctx, ev->hash); }
#ifndef USE_SELECT
  if (ev->events) { GRN_FREE(ev->events); }
# ifdef USE_EPOLL
  grn_close(ev->epfd);
# endif /* USE_EPOLL */
# ifdef USE_KQUEUE
  grn_close(ev->kqfd);
# endif /* USE_KQUEUE*/
#endif /* USE_SELECT */
  return GRN_SUCCESS;
}
Пример #12
0
grn_rc
grn_query_close(grn_ctx *ctx, grn_query *q)
{
  if (!q) { return GRN_INVALID_ARGUMENT; }
  if (q->opt.weight_vector) {
    GRN_FREE(q->opt.weight_vector);
  }
  if (q->weight_set) {
    grn_hash_close(ctx, q->weight_set);
  }
  if (q->snip_conds) {
    snip_cond *sc;
    for (sc = q->snip_conds; sc < q->snip_conds + q->cur_expr; sc++) {
      grn_snip_cond_close(ctx, sc);
    }
    GRN_FREE(q->snip_conds);
  }
  GRN_FREE(q);
  return GRN_SUCCESS;
}
Пример #13
0
 void cut_teardown()
 {
   grn_hash_close(ctx, hash);
   grn_obj_unlink(ctx, &buffer);
 }
Пример #14
0
static void
exec_search(grn_ctx *ctx, grn_ii *i, grn_query *q, grn_cell *c,
            grn_hash *r, grn_operator op)
{
  grn_hash *s;
  grn_cell *e, *ope = NIL;
  int n = *r->n_entries;
  grn_operator op0 = GRN_OP_OR, *opp = &op0, op1 = q->default_op;
  if (!n && op != GRN_OP_OR) { return; }
  if (n) {
    s = grn_hash_create(ctx, NULL, r->key_size, r->value_size, r->obj.header.flags);
    s->obj.header.impl_flags = 0;
    s->obj.header.domain = r->obj.header.domain;
    s->obj.range = r->obj.range;
    s->obj.max_n_subrecs = r->obj.max_n_subrecs;
    s->obj.subrec_size = r->obj.subrec_size;
    s->obj.subrec_offset = r->obj.subrec_offset;
    s->obj.id = r->obj.id;
    s->obj.db = r->obj.db;
    s->obj.source = r->obj.source;
    s->obj.source_size = r->obj.source_size;
    /*
    grn_hook_entry entry;
    for (entry = 0; entry < N_HOOK_ENTRIES; entry++) {
      s->obj.hooks[entry] = NULL;
    }
    */
  } else {
    s = r;
  }
  while (c != NIL) {
    POP(e, c);
    switch (e->header.type) {
    case GRN_CELL_OP :
      if (opp == &op0 && e->u.op.op == GRN_OP_BUT) {
        POP(e, c);
      } else {
        ope = e;
        op1 = ope->u.op.op;
      }
      continue;
    case GRN_CELL_STR :
      if (ope != NIL) {
        q->opt.mode = ope->u.op.mode == -1 ? q->default_mode : ope->u.op.mode;
        q->opt.max_interval = q->opt.similarity_threshold = ope->u.op.option;
        if (!q->opt.weight_vector) {
          q->opt.vector_size = ope->u.op.weight + q->weight_offset;
        }
        if (ope->u.op.mode == GRN_OP_SIMILAR) {
          q->opt.max_interval = q->default_mode;
        }
      } else {
        q->opt.mode = q->default_mode;
        q->opt.max_interval = DEFAULT_MAX_INTERVAL;
        q->opt.similarity_threshold = DEFAULT_SIMILARITY_THRESHOLD;
        if (!q->opt.weight_vector) {
          q->opt.vector_size = DEFAULT_WEIGHT + q->weight_offset;
        }
      }
      if (grn_ii_select(ctx, i, e->u.b.value, e->u.b.size, s, *opp, &q->opt)) {
        GRN_LOG(ctx, GRN_LOG_ERROR, "grn_inv_select on exec_search failed !");
        return;
      }
      break;
    case GRN_CELL_LIST :
      exec_search(ctx, i, q, e, s, *opp);
      break;
    default :
      GRN_LOG(ctx, GRN_LOG_NOTICE, "invalid object assigned in query (%d)", e->header.type);
      break;
    }
    opp = &op1;
    ope = NIL;
    op1 = q->default_op;
  }
  if (n) {
    grn_table_setoperation(ctx, (grn_obj *)r, (grn_obj *)s, (grn_obj *)r, op);
    grn_hash_close(ctx, s);
  }
}
Пример #15
0
  CRITICAL_SECTION_INIT(grn_plugins_lock);
  grn_plugins = grn_hash_create(&grn_gctx, NULL, PATH_MAX, sizeof(grn_plugin *),
                                GRN_OBJ_KEY_VAR_SIZE);
  if (!grn_plugins) { return GRN_NO_MEMORY_AVAILABLE; }
  return GRN_SUCCESS;
}

grn_rc
grn_plugins_fin(void)
{
  grn_rc rc;
  if (!grn_plugins) { return GRN_INVALID_ARGUMENT; }
  GRN_HASH_EACH(&grn_gctx, grn_plugins, id, NULL, NULL, NULL, {
    grn_plugin_close(&grn_gctx, id);
  });
  rc = grn_hash_close(&grn_gctx, grn_plugins);
  CRITICAL_SECTION_FIN(grn_plugins_lock);
  return rc;
}

const char *
grn_plugin_get_suffix(void)
{
  return GRN_PLUGIN_SUFFIX;
}

const char *
grn_plugin_get_ruby_suffix(void)
{
  return ".rb";
}