Example #1
0
static void
update_data(grn_id record_id, unsigned int section,
            const gchar *old_name, const gchar *new_name)
{
    grn_obj old_value, new_value;
    const gchar *old_data, *new_data;

    GRN_TEXT_INIT(&old_value, GRN_OBJ_DO_SHALLOW_COPY);
    GRN_TEXT_INIT(&new_value, GRN_OBJ_DO_SHALLOW_COPY);

    if (old_name) {
        old_data = cut_get_fixture_data_string(old_name, NULL);
        GRN_TEXT_SET_REF(&old_value, old_data, strlen(old_data));
    }

    if (new_name) {
        new_data = cut_get_fixture_data_string(new_name, NULL);
        GRN_TEXT_SET_REF(&new_value, new_data, strlen(new_data));
    }

    grn_ii_column_update(context, inverted_index, record_id, section,
                         &old_value, &new_value, NULL);
    grn_obj_close(context, &old_value);
    grn_obj_close(context, &new_value);
}
Example #2
0
void
test_fix_size_set_value_increment(void)
{
  gint32 count = 29;
  gint32 increment_count = 5;
  gint32 retrieved_count;
  grn_obj *record_value;
  grn_obj *retrieved_record_value;

  record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32);
  grn_bulk_write(context, record_value, (const char *)&count, sizeof(count));
  grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id,
                                    record_value, GRN_OBJ_SET));
  grn_obj_close(context, record_value);

  record_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32);
  grn_bulk_write(context, record_value,
                 (const char *)&increment_count, sizeof(increment_count));
  grn_test_assert(grn_obj_set_value(context, count_column, groonga_bookmark_id,
                                    record_value, GRN_OBJ_INCR));
  grn_obj_close(context, record_value);

  retrieved_record_value = grn_obj_get_value(context, count_column,
                                             groonga_bookmark_id, NULL);
  memcpy(&retrieved_count,
         GRN_BULK_HEAD(retrieved_record_value),
         GRN_BULK_VSIZE(retrieved_record_value));
  cut_assert_equal_int(count + increment_count, retrieved_count);
  grn_obj_close(context, retrieved_record_value);
}
Example #3
0
MRN_API void mroonga_snippet_html_deinit(UDF_INIT *init)
{
  MRN_DBUG_ENTER_FUNCTION();

  mrn_snippet_html_info *info =
    reinterpret_cast<mrn_snippet_html_info *>(init->ptr);
  if (!info) {
    DBUG_VOID_RETURN;
  }

  if (info->snippet) {
    grn_obj_close(info->ctx, info->snippet);
  }
  if (info->query_mode.used) {
    if (info->query_mode.default_column) {
      grn_obj_close(info->ctx, info->query_mode.default_column);
    }
    if (info->query_mode.table) {
      grn_obj_close(info->ctx, info->query_mode.table);
    }
  }
  GRN_OBJ_FIN(info->ctx, &(info->result));
  if (!info->use_shared_db) {
    grn_obj_close(info->ctx, info->db);
  }
  mrn_context_pool->release(info->ctx);
  my_free(info);

  DBUG_VOID_RETURN;
}
Example #4
0
File: kv.c Project: darashi/groonga
int
table_put_allocate(void)
{
  int i;
  grn_obj *buf;
  grn_obj *key_type = grn_ctx_at(&ctx, GRN_DB_SHORT_TEXT);
  grn_obj *table = grn_table_create(&ctx, "<t1>", 4, NULL,
                                    GRN_OBJ_TABLE_HASH_KEY|GRN_OBJ_PERSISTENT,
                                    key_type, value_type);
  if (!table) { return -1; }
  for (i = 0; i < nloops; i++) {
    int key = GENKEY(i);
    buf = grn_obj_open(&ctx, GRN_BULK, 0, 0);
    grn_text_itoh(&ctx, buf, key, key_size);
    {
      grn_id rid = grn_table_add(&ctx, table, GRN_BULK_HEAD(buf), key_size, NULL);
      if (!rid) {
        fprintf(stderr, "table_lookup failed");
      } else {
        grn_obj *value_buf;
        value_buf = grn_obj_open(&ctx, GRN_BULK, 0, 0);
        grn_text_itoh(&ctx, value_buf, key, key_size);
        if (grn_obj_set_value(&ctx, table, rid, value_buf, GRN_OBJ_SET)) {
          fprintf(stderr, "grn_obj_set_value failed");
        }
        grn_obj_close(&ctx, value_buf);
      }
    }
    grn_obj_close(&ctx, buf);
  }
  return 0;
}
Example #5
0
File: kv.c Project: darashi/groonga
int
table_get(void)
{
  int i;
  grn_obj buf;
  grn_obj *table = grn_ctx_get(&ctx, "<t1>", 4);
  if (!table) { 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);
    {
      grn_id rid = grn_table_get(&ctx, table, GRN_BULK_HEAD(&buf), key_size);
      if (!rid) {
        fprintf(stderr, "table_lookup failed");
      } else {
        grn_obj obj, *p;
        GRN_TEXT_INIT(&obj, 0);
        p = grn_obj_get_value(&ctx, table, rid, &obj);
        if (!p) {
          fprintf(stderr, "grn_obj_get_value failed\n");
        } else {
          if (memcmp(GRN_BULK_HEAD(p), GRN_BULK_HEAD(&buf), value_size)) {
            fprintf(stderr, "value unmatch\n");
          }
          grn_obj_close(&ctx, p);
        }
      }
    }
  }
  grn_obj_close(&ctx, &buf);
  return 0;
}
Example #6
0
void
test_table_scan(void)
{
  grn_obj *cond, *v, *res, textbuf, intbuf;
  GRN_TEXT_INIT(&textbuf, 0);
  GRN_UINT32_INIT(&intbuf, 0);

  prepare_data(&textbuf, &intbuf);

  cut_assert_not_null((cond = grn_expr_create(&context, NULL, 0)));
  v = grn_expr_add_var(&context, cond, NULL, 0);
  GRN_RECORD_INIT(v, 0, grn_obj_id(&context, docs));
  grn_expr_append_obj(&context, cond, v);
  GRN_TEXT_SETS(&context, &textbuf, "size");
  grn_expr_append_const(&context, cond, &textbuf);
  grn_expr_append_op(&context, cond, GRN_OP_OBJ_GET_VALUE, 2);
  GRN_UINT32_SET(&context, &intbuf, 14);
  grn_expr_append_const(&context, cond, &intbuf);
  grn_expr_append_op(&context, cond, GRN_OP_EQUAL, 2);
  grn_expr_compile(&context, cond);

  res = grn_table_create(&context, NULL, 0, NULL,
                         GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, docs, 0);
  cut_assert_not_null(res);

  grn_test_assert(grn_table_scan(&context, docs, cond, res, GRN_SEL_OR));

  cut_assert_equal_uint(3, grn_table_size(&context, res));

  grn_test_assert(grn_obj_close(&context, res));
  grn_test_assert(grn_obj_close(&context, cond));
  grn_test_assert(grn_obj_close(&context, &textbuf));
  grn_test_assert(grn_obj_close(&context, &intbuf));
}
Example #7
0
void
test_accessor(void)
{
    int i;
    grn_obj *t1, *t2, *c1, *c2, r1, r2;
    t1 = grn_table_create(context, "t1", 2, NULL,
                          GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT, NULL, NULL);
    cut_assert_not_null(t1);
    t2 = grn_table_create(context, "t2", 2, NULL,
                          GRN_OBJ_TABLE_NO_KEY|GRN_OBJ_PERSISTENT, NULL, NULL);
    cut_assert_not_null(t2);
    c1 = grn_column_create(context, t1, "c1", 2, NULL,
                           GRN_OBJ_PERSISTENT, t2);
    cut_assert_not_null(c1);
    c2 = grn_column_create(context, t2, "c2", 2, NULL,
                           GRN_OBJ_PERSISTENT, t1);
    cut_assert_not_null(c2);
    GRN_RECORD_INIT(&r1, 0, grn_obj_id(context, t1));
    GRN_RECORD_INIT(&r2, 0, grn_obj_id(context, t2));
    for (i = 0; i < NRECORDS; i++) {
        grn_id i1, i2;
        i1 = grn_table_add(context, t1, NULL, 0, NULL);
        i2 = grn_table_add(context, t2, NULL, 0, NULL);
        GRN_RECORD_SET(context, &r1, i1);
        GRN_RECORD_SET(context, &r2, i2);
        grn_obj_set_value(context, c1, i1, &r2, GRN_OBJ_SET);
        grn_obj_set_value(context, c2, i2, &r1, GRN_OBJ_SET);
    }
    {
        grn_id id;
        uint64_t et;
        int nerr = 0;
        struct timeval tvb, tve;
        grn_obj *a = grn_obj_column(context, t1, "c1.c2.c1", 8);
        grn_table_cursor *tc = grn_table_cursor_open(context, t1, NULL, 0, NULL, 0, 0, -1, 0);
        cut_assert_not_null(a);
        cut_assert_not_null(tc);
        gettimeofday(&tvb, NULL);
        while ((id = grn_table_cursor_next(context, tc))) {
            GRN_BULK_REWIND(&r2);
            grn_obj_get_value(context, a, id, &r2);
            if (GRN_RECORD_VALUE(&r2) != id) {
                nerr++;
            }
        }
        gettimeofday(&tve, NULL);
        et = (tve.tv_sec - tvb.tv_sec) * 1000000 + (tve.tv_usec - tvb.tv_usec);
        // printf("et=%zu\n", et);
        cut_assert_equal_uint(0, nerr);
        grn_test_assert(grn_table_cursor_close(context, tc));
        grn_test_assert(grn_obj_close(context, a));
    }
    grn_test_assert(grn_obj_close(context, &r1));
    grn_test_assert(grn_obj_close(context, &r2));
}
Example #8
0
static grn_bool
exec_text_operator_raw_text_raw_text(grn_ctx *ctx,
                                     grn_operator op,
                                     const char *target,
                                     unsigned int target_len,
                                     const char *query,
                                     unsigned int query_len)
{
  grn_obj *normalizer;
  grn_obj *norm_target;
  grn_obj *norm_query;
  const char *norm_target_raw;
  const char *norm_query_raw;
  unsigned int norm_target_raw_length_in_bytes;
  unsigned int norm_query_raw_length_in_bytes;
  grn_bool matched = GRN_FALSE;

  if (target_len == 0 || query_len == 0) {
    return GRN_FALSE;
  }

  normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
  norm_target = grn_string_open(ctx, target, target_len, normalizer, 0);
  grn_string_get_normalized(ctx, norm_target,
                            &norm_target_raw,
                            &norm_target_raw_length_in_bytes,
                            NULL);

  if (op == GRN_OP_REGEXP) {
    norm_query = NULL;
    norm_query_raw = query;
    norm_query_raw_length_in_bytes = query_len;
  } else {
    norm_query = grn_string_open(ctx, query,  query_len,  normalizer, 0);
    grn_string_get_normalized(ctx, norm_query,
                              &norm_query_raw,
                              &norm_query_raw_length_in_bytes,
                              NULL);
  }

  matched = exec_text_operator(ctx, op,
                               norm_target_raw,
                               norm_target_raw_length_in_bytes,
                               norm_query_raw,
                               norm_query_raw_length_in_bytes);

  grn_obj_close(ctx, norm_target);
  if (norm_query) {
    grn_obj_close(ctx, norm_query);
  }
  grn_obj_unlink(ctx, normalizer);

  return matched;
}
Example #9
0
void
cut_teardown(void)
{
    grn_obj_close(context, &textbuf);
    grn_obj_close(context, &intbuf);

    if (expr)
        grn_obj_close(context, expr);

    grn_db_close(context, database);
    grn_ctx_fin(context);
    g_free(context);

    cut_remove_path(tmp_directory, NULL);
    g_free(path);
}
Example #10
0
void
cut_teardown(void)
{
  if (context) {
    inverted_index_free();
    if (path)
      grn_ii_remove(context, path);
    grn_obj_close(context, db);
    grn_ctx_fin(context);
    g_free(context);
  }

  if (path) {
    g_free(path);
    path = NULL;
  }

  remove_tmp_directory();

  record_ids_free();

  expected_messages_free();

  teardown_grn_logger(logger);
}
Example #11
0
/* It should be renamed to grn_snip_close() and marked as internal.
 * TODO: 3.0 */
grn_rc
grn_snip_close_real(grn_ctx *ctx, grn_snip *snip)
{
  snip_cond *cond, *cond_end;
  if (!snip) { return GRN_INVALID_ARGUMENT; }
  GRN_API_ENTER;
  if (snip->flags & GRN_SNIP_COPY_TAG) {
    int i;
    snip_cond *sc;
    const char *dot = snip->defaultopentag, *dct = snip->defaultclosetag;
    for (i = snip->cond_len, sc = snip->cond; i; i--, sc++) {
      if (sc->opentag != dot) { GRN_FREE((void *)sc->opentag); }
      if (sc->closetag != dct) { GRN_FREE((void *)sc->closetag); }
    }
    if (dot) { GRN_FREE((void *)dot); }
    if (dct) { GRN_FREE((void *)dct); }
  }
  if (snip->nstr) {
    grn_obj_close(ctx, snip->nstr);
  }
  for (cond = snip->cond, cond_end = cond + snip->cond_len;
       cond < cond_end; cond++) {
    grn_snip_cond_close(ctx, cond);
  }
  GRN_FREE(snip);
  GRN_API_RETURN(GRN_SUCCESS);
}
Example #12
0
void
test_score_set(void)
{
  grn_obj *v, *res2;

  prepare_data();

  GRN_EXPR_CREATE_FOR_QUERY(&context, docs, cond, v);
  cut_assert_not_null(cond);
  cut_assert_not_null(v);
  PARSE(cond, "size:>0",
        GRN_EXPR_SYNTAX_QUERY|GRN_EXPR_ALLOW_PRAGMA|GRN_EXPR_ALLOW_COLUMN);
  res = grn_table_select(&context, docs, cond, NULL, GRN_OP_OR);
  cut_assert_not_null(res);
  grn_test_assert_select_all(res);
  grn_test_assert(grn_obj_close(&context, cond));
  cond = NULL;

  GRN_EXPR_CREATE_FOR_QUERY(&context, res, expr, v);
  PARSE(expr, "_score = size",
        GRN_EXPR_SYNTAX_SCRIPT|GRN_EXPR_ALLOW_UPDATE);
  GRN_TABLE_EACH(&context, res, 0, 0, id, NULL, 0, NULL, {
    GRN_RECORD_SET(&context, v, id);
    grn_expr_exec(&context, expr, 0);
  });
Example #13
0
void
teardown (void)
{
  GRN_OBJ_FIN(&context, &buffer);
  grn_obj_close(&context, database);
  grn_ctx_fin(&context);
}
Example #14
0
grn_obj *
grn_string_open_(grn_ctx *ctx, const char *str, unsigned int str_len,
                 grn_obj *normalizer, int flags, grn_encoding encoding)
{
  grn_string *string;
  grn_obj *obj;
  grn_bool is_normalizer_auto;

  if (!str || !str_len) {
    return NULL;
  }

  is_normalizer_auto = (normalizer == GRN_NORMALIZER_AUTO);
  if (is_normalizer_auto) {
    normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
    if (!normalizer) {
      ERR(GRN_INVALID_ARGUMENT,
          "[string][open] NormalizerAuto normalizer isn't available");
      return NULL;
    }
  }

  string = GRN_MALLOCN(grn_string, 1);
  if (!string) {
    if (is_normalizer_auto) {
      grn_obj_unlink(ctx, normalizer);
    }
    GRN_LOG(ctx, GRN_LOG_ALERT,
            "[string][open] failed to allocate memory");
    return NULL;
  }

  obj = (grn_obj *)string;
  GRN_OBJ_INIT(obj, GRN_STRING, GRN_OBJ_ALLOCATED, GRN_ID_NIL);
  string->original = str;
  string->original_length_in_bytes = str_len;
  string->normalized = NULL;
  string->normalized_length_in_bytes = 0;
  string->n_characters = 0;
  string->checks = NULL;
  string->ctypes = NULL;
  string->encoding = encoding;
  string->flags = flags;

  if (!normalizer) {
    return (grn_obj *)grn_fake_string_open(ctx, string);
  }

  grn_normalizer_normalize(ctx, normalizer, (grn_obj *)string);
  if (ctx->rc) {
    grn_obj_close(ctx, obj);
    obj = NULL;
  }

  if (is_normalizer_auto) {
    grn_obj_unlink(ctx, normalizer);
  }

  return obj;
}
Example #15
0
grn_rc
grn_index_close(grn_ctx *ctx, grn_index *index)
{
  grn_obj_close(ctx, index->db);
  free(index);
  return ctx->rc;
}
Example #16
0
/*
 * Normalizes the @string@.
 *
 * @example
 *   # Normalizes "ABC" with the default normalizer
 *   Groonga::Normalizer.normalize("AbC") # => "abc"
 *
 * @overload normalize(string)
 *   @return [String] The normalized string
 *   @param [String] string The original string
 */
static VALUE
rb_grn_normalizer_s_normalize (VALUE klass, VALUE rb_string)
{
    VALUE rb_context = Qnil;
    VALUE rb_encoded_string;
    VALUE rb_normalized_string;
    grn_ctx *context = NULL;
    grn_obj *grn_string;
    grn_obj *normalizer = GRN_NORMALIZER_AUTO;
    /* TODO: make customizable */
    int flags = GRN_STRING_REMOVE_BLANK;
    const char *normalized_string;
    unsigned int normalized_string_length;

    context = rb_grn_context_ensure(&rb_context);
    rb_encoded_string = rb_grn_context_rb_string_encode(context, rb_string);
    grn_string = grn_string_open(context,
                                 RSTRING_PTR(rb_encoded_string),
                                 RSTRING_LEN(rb_encoded_string),
                                 normalizer,
                                 flags);
    rb_grn_context_check(context, rb_string);
    grn_string_get_normalized(context, grn_string,
                              &normalized_string, &normalized_string_length,
                              NULL);
    rb_normalized_string =
        rb_grn_context_rb_string_new(context,
                                     normalized_string,
                                     normalized_string_length);
    grn_obj_close(context, grn_string);

    return rb_normalized_string;
}
Example #17
0
static void
grn_tokenizer_query_ensure_normalized(grn_ctx *ctx, grn_tokenizer_query *query)
{
  if (!query->need_normalize) {
    return;
  }

  query->need_normalize = GRN_FALSE;

  if (query->normalized_query) {
    grn_obj_close(ctx, query->normalized_query);
  }
  query->normalized_query = grn_string_open_(ctx,
                                             query->ptr,
                                             query->length,
                                             query->lexicon,
                                             query->normalize_flags,
                                             query->encoding);
  if (!query->normalized_query) {
    query->have_tokenized_delimiter = GRN_FALSE;
    GRN_PLUGIN_ERROR(ctx, GRN_TOKENIZER_ERROR,
                     "[tokenizer][normalize] failed to open normalized string");
    return;
  }

  query->need_delimiter_check = GRN_TRUE;
}
Example #18
0
grn_rc
grn_ctx_fin(grn_ctx *ctx)
{
  grn_rc rc = GRN_SUCCESS;
  if (!ctx) { return GRN_INVALID_ARGUMENT; }
  if (ctx->stat == GRN_CTX_FIN) { return GRN_INVALID_ARGUMENT; }
  if (!(ctx->flags & GRN_CTX_ALLOCATED)) {
    CRITICAL_SECTION_ENTER(grn_glock);
    ctx->next->prev = ctx->prev;
    ctx->prev->next = ctx->next;
    CRITICAL_SECTION_LEAVE(grn_glock);
  }
  if (ctx->impl) {
    grn_ctx_impl_clear_n_same_error_messagges(ctx);
    if (ctx->impl->finalizer) {
      ctx->impl->finalizer(ctx, 0, NULL, &(ctx->user_data));
    }
    grn_ctx_impl_mrb_fin(ctx);
    grn_ctx_loader_clear(ctx);
    if (ctx->impl->parser) {
      grn_expr_parser_close(ctx);
    }
    GRN_OBJ_FIN(ctx, &ctx->impl->current_request_id);
    if (ctx->impl->values) {
#ifndef USE_MEMORY_DEBUG
      grn_db_obj *o;
      GRN_ARRAY_EACH(ctx, ctx->impl->values, 0, 0, id, &o, {
        grn_obj_close(ctx, *((grn_obj **)o));
      });
Example #19
0
void
cut_teardown(void)
{
  if (cursor) {
    grn_obj_unlink(context, cursor);
  }

  if (result) {
    grn_obj_unlink(context, result);
  }

  if (column) {
    grn_obj_unlink(context, column);
  }

  if (table) {
    grn_obj_unlink(context, table);
  }

  grn_obj_close(context, database);
  grn_ctx_fin(context);
  g_free(context);

  remove_tmp_directory();
}
Example #20
0
static int
run(grn_ctx *ctx, const char *db_path, const char *ruby_script_path)
{
  grn_obj *db;

  db = grn_db_open(ctx, db_path);
  if (!db) {
    if (ctx->rc == GRN_NO_SUCH_FILE_OR_DIRECTORY) {
      db = grn_db_create(ctx, db_path, NULL);
      if (!db) {
        fprintf(stderr, "Failed to create database: <%s>: %s",
                db_path, ctx->errbuf);
        return EXIT_FAILURE;
      }
    } else {
      fprintf(stderr, "Failed to open database: <%s>: %s",
              db_path, ctx->errbuf);
      return EXIT_FAILURE;
    }
  }

  grn_mrb_load(ctx, ruby_script_path);
  if (ctx->rc != GRN_SUCCESS) {
      fprintf(stderr, "Failed to load Ruby script: <%s>: %s",
              ruby_script_path, ctx->errbuf);
  }

  grn_obj_close(ctx, db);

  if (ctx->rc == GRN_SUCCESS) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}
Example #21
0
void
grn_output_geo_point(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
                     grn_geo_point *value)
{
  put_delimiter(ctx, outbuf, output_type);
  switch (output_type) {
  case GRN_CONTENT_JSON:
    if (value) {
      GRN_TEXT_PUTC(ctx, outbuf, '"');
      grn_text_itoa(ctx, outbuf, value->latitude);
      GRN_TEXT_PUTC(ctx, outbuf, 'x');
      grn_text_itoa(ctx, outbuf, value->longitude);
      GRN_TEXT_PUTC(ctx, outbuf, '"');
    } else {
      GRN_TEXT_PUTS(ctx, outbuf, "null");
    }
    break;
  case GRN_CONTENT_TSV:
    if (value) {
      GRN_TEXT_PUTC(ctx, outbuf, '"');
      grn_text_itoa(ctx, outbuf, value->latitude);
      GRN_TEXT_PUTC(ctx, outbuf, 'x');
      grn_text_itoa(ctx, outbuf, value->longitude);
      GRN_TEXT_PUTC(ctx, outbuf, '"');
    } else {
      GRN_TEXT_PUTS(ctx, outbuf, "\"\"");
    }
    break;
  case GRN_CONTENT_XML:
    GRN_TEXT_PUTS(ctx, outbuf, "<GEO_POINT>");
    if (value) {
      grn_text_itoa(ctx, outbuf, value->latitude);
      GRN_TEXT_PUTC(ctx, outbuf, 'x');
      grn_text_itoa(ctx, outbuf, value->longitude);
    }
    GRN_TEXT_PUTS(ctx, outbuf, "</GEO_POINT>");
    break;
  case GRN_CONTENT_MSGPACK :
#ifdef HAVE_MESSAGE_PACK
    if (value) {
      grn_obj buf;
      GRN_TEXT_INIT(&buf, 0);
      grn_text_itoa(ctx, &buf, value->latitude);
      GRN_TEXT_PUTC(ctx, &buf, 'x');
      grn_text_itoa(ctx, &buf, value->longitude);
      msgpack_pack_raw(&ctx->impl->msgpacker, GRN_TEXT_LEN(&buf));
      msgpack_pack_raw_body(&ctx->impl->msgpacker,
                            GRN_TEXT_VALUE(&buf),
                            GRN_TEXT_LEN(&buf));
      grn_obj_close(ctx, &buf);
    } else {
      msgpack_pack_nil(&ctx->impl->msgpacker);
    }
#endif
    break;
  case GRN_CONTENT_NONE:
    break;
  }
  INCR_LENGTH;
}
Example #22
0
File: kv.c Project: darashi/groonga
int
pat_put(const char *path)
{
  int i;
  grn_obj buf;
  grn_pat *pat = grn_pat_create(&ctx, path, key_size, value_size,
                                   GRN_OBJ_PERSISTENT|GRN_OBJ_KEY_VAR_SIZE);
  if (!pat) { 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_pat_add(&ctx, pat,
                               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_pat_close(&ctx, pat);
  return 0;
}
static void
ngx_http_groonga_close_database_callback(ngx_http_groonga_loc_conf_t *location_conf,
                                         void *user_data)
{
  ngx_http_groonga_database_callback_data_t *data = user_data;
  grn_ctx *context;

  context = &(location_conf->context);
  ngx_http_groonga_context_init_logger(context,
                                       location_conf,
                                       data->pool,
                                       data->log);
  ngx_http_groonga_context_init_query_logger(context,
                                             location_conf,
                                             data->pool,
                                             data->log);
  grn_cache_current_set(context, location_conf->cache);

  grn_obj_close(context, grn_ctx_db(context));
  ngx_http_groonga_context_log_error(data->log, context);

  grn_cache_current_set(context, NULL);
  grn_cache_close(context, location_conf->cache);

  grn_ctx_fin(context);
}
Example #24
0
File: kv.c Project: darashi/groonga
int
pat_get(const char *path)
{
  int i;
  grn_obj buf;
  grn_pat *pat = grn_pat_open(&ctx, path);
  if (!pat) { 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_pat_get(&ctx, pat, 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_pat_close(&ctx, pat);
  return 0;
}
Example #25
0
grn_rc
grn_msg_close(grn_ctx *ctx, grn_obj *obj)
{
  grn_msg *msg = (grn_msg *)obj;
  if (ctx == msg->ctx) { return grn_obj_close(ctx, obj); }
  return grn_com_queue_enque(ctx, msg->old, (grn_com_queue_entry *)msg);
}
Example #26
0
static void
teardown_database(void)
{
  grn_obj_close(&context, database);
  cut_remove_path(tmp_directory, NULL);
  g_free(tmp_directory);
}
Example #27
0
void
test_read_write(gconstpointer *data)
{
  gint i;
  int added;
  grn_ctx *context;
  grn_obj *table;
  const gchar *path;
  const gchar *value_string;
  gint process_number = 0;
  const gchar *process_number_string;
  const gchar table_name[] = "performance-read-write";
  grn_obj value;
  grn_obj *retrieved_value;
  grn_id id;
  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);

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

  path = g_getenv(GRN_TEST_ENV_TABLE_PATH);
  cut_assert_not_null(path);
  tables[i] = grn_table_open(context, table_name, strlen(table_name),
                             path);
  cut_assert_not_null(tables[i],
                      cut_message("table: %d (%d)", i, process_number));
  table = tables[i];

  grn_test_assert_nil(grn_table_get(context, table, &i, sizeof(grn_id)),
                      cut_message("lookup - fail: (%d:%d)", i, process_number));

  value_string = cut_take_printf("value: (%d:%d)", i, process_number);
  id = grn_table_add(context, table, &i, sizeof(grn_id), &added);
  grn_test_assert_not_nil(id);
  cut_assert_equal_int(1, added);

  GRN_TEXT_INIT(&value, GRN_OBJ_DO_SHALLOW_COPY);
  GRN_TEXT_SET_REF(&value, value_string, strlen(value_string));
  grn_obj_set_value(context, table, id, &value, GRN_OBJ_SET);

  retrieved_value = grn_obj_get_value(context, table, id, NULL);
  grn_test_assert_not_nil(
    id,
    cut_message("lookup - success: (%d:%d)", i, process_number));
  GRN_TEXT_PUTC(context, retrieved_value, '\0');
  cut_assert_equal_string(value_string, GRN_BULK_HEAD(retrieved_value));

  tables[i] = NULL;
  grn_test_assert(grn_obj_close(context, table));

  //  contexts[i] = NULL;
  grn_test_assert(grn_ctx_fin(context));
}
Example #28
0
void
test_expression_lifetime_over_database(void)
{
  const gchar *path;
  gint i, n_tries = 100;
  grn_obj *expression;

  cut_omit("will be SEGVed.");
  path = cut_build_path(tmp_directory, "database.groonga", NULL);
  for (i = 0; i < n_tries; i++) {
    gint j, n_records = 100;
    const gchar *query;
    grn_obj *table, *variable;
    grn_obj default_column;

    database = grn_db_create(context, path, NULL);
    grn_test_assert_context(context);

    assert_send_command("table_create Sites 0 ShortText");
    assert_send_command("column_create Sites point COLUMN_SCALAR Int32");
    for (j = 0; j < n_records; j++) {
      gchar *command;

      command = g_strdup_printf("load '"
                                "[[\"_key\", \"point\"],"
                                "[\"http://groonga.org/version/%d\",%d]]' "
                                "Sites",
                                j, j);
      assert_send_command(command);
      g_free(command);
    }

    table = get_object("Sites");
    GRN_EXPR_CREATE_FOR_QUERY(context, table, expression, variable);
    grn_obj_unlink(context, table);

    GRN_TEXT_INIT(&default_column, 0);
    GRN_TEXT_PUTS(context, &default_column, "point");
    query = "point:50";
    grn_expr_parse(context, expression,
                   query, strlen(query),
                   &default_column,
                   GRN_OP_MATCH, GRN_OP_AND,
                   GRN_EXPR_SYNTAX_QUERY | GRN_EXPR_ALLOW_COLUMN);
    grn_test_assert_context(context);
    grn_obj_unlink(context, &default_column);
    grn_expr_compile(context, expression);

    grn_obj_close(context, database);
    database = NULL;

    remove_tmp_directory();
    g_mkdir_with_parents(tmp_directory, 0700);
  }

  grn_ctx_fin(context);
  g_free(context);
  context = NULL;
}
Example #29
0
static void
bench_shutdown(BenchmarkData *data)
{
  grn_ctx *context = &(data->context);

  grn_obj_close(context, data->database);
  grn_ctx_fin(context);
}
Example #30
0
void
cut_teardown(void)
{
  grn_obj_close(context, database);
  grn_ctx_fin(context);
  g_free(context);
  teardown_grn_logger(logger);
}