[Groonga-commit] groonga/groonga at ec79855 [master] load: support request ID with raw JSON input case

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 9 17:07:29 JST 2016


Kouhei Sutou	2016-03-09 17:07:29 +0900 (Wed, 09 Mar 2016)

  New Revision: ec79855674cccc13a80bf7c9a9c6d6aa25a7fd96
  https://github.com/groonga/groonga/commit/ec79855674cccc13a80bf7c9a9c6d6aa25a7fd96

  Message:
    load: support request ID with raw JSON input case
    
        POST /d/load?table=XXX&request_id=x
    
    and
    
        load --table XXX --request_id x
        [
        ...
        ]
    
    are supported.

  Modified files:
    lib/ctx.c
    lib/grn_ctx_impl.h

  Modified: lib/ctx.c (+15 -5)
===================================================================
--- lib/ctx.c    2016-03-09 15:01:54 +0900 (aed8072)
+++ lib/ctx.c    2016-03-09 17:07:29 +0900 (43182f7)
@@ -601,6 +601,7 @@ grn_ctx_impl_init(grn_ctx *ctx)
   ctx->impl->stack_curr = 0;
   ctx->impl->curr_expr = NULL;
   ctx->impl->qe_next = NULL;
+  GRN_TEXT_INIT(&ctx->impl->current_request_id, 0);
   ctx->impl->parser = NULL;
 
   GRN_TEXT_INIT(&ctx->impl->output.names, GRN_OBJ_VECTOR);
@@ -773,6 +774,7 @@ grn_ctx_fin(grn_ctx *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;
@@ -1473,17 +1475,15 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
         }
       }
       if (GRN_TEXT_LEN(&request_id) > 0) {
+        GRN_TEXT_SET(ctx, &ctx->impl->current_request_id,
+                     GRN_TEXT_VALUE(&request_id),
+                     GRN_TEXT_LEN(&request_id));
         grn_request_canceler_register(ctx,
                                       GRN_TEXT_VALUE(&request_id),
                                       GRN_TEXT_LEN(&request_id));
       }
       ctx->impl->curr_expr = expr;
       grn_expr_exec(ctx, expr, 0);
-      if (GRN_TEXT_LEN(&request_id) > 0) {
-        grn_request_canceler_unregister(ctx,
-                                        GRN_TEXT_VALUE(&request_id),
-                                        GRN_TEXT_LEN(&request_id));
-      }
     } else {
       ERR(GRN_INVALID_ARGUMENT, "invalid command name: %.*s",
           command_name_size, command_name);
@@ -1579,6 +1579,9 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len)
     }
   }
   if (GRN_TEXT_LEN(&request_id) > 0) {
+    GRN_TEXT_SET(ctx, &ctx->impl->current_request_id,
+                 GRN_TEXT_VALUE(&request_id),
+                 GRN_TEXT_LEN(&request_id));
     grn_request_canceler_register(ctx,
                                   GRN_TEXT_VALUE(&request_id),
                                   GRN_TEXT_LEN(&request_id));
@@ -1698,6 +1701,13 @@ grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags)
       if (ctx->impl->qe_next) {
         ERRCLR(ctx);
       } else {
+        if (GRN_TEXT_LEN(&ctx->impl->current_request_id) > 0) {
+          grn_obj *request_id = &ctx->impl->current_request_id;
+          grn_request_canceler_unregister(ctx,
+                                          GRN_TEXT_VALUE(request_id),
+                                          GRN_TEXT_LEN(request_id));
+          GRN_BULK_REWIND(&ctx->impl->current_request_id);
+        }
         GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_RESULT_CODE,
                       "<", "rc=%d", ctx->rc);
       }

  Modified: lib/grn_ctx_impl.h (+1 -0)
===================================================================
--- lib/grn_ctx_impl.h    2016-03-09 15:01:54 +0900 (b843edd)
+++ lib/grn_ctx_impl.h    2016-03-09 17:07:29 +0900 (0776ba2)
@@ -159,6 +159,7 @@ struct _grn_ctx_impl {
   grn_hash *expr_vars;
   grn_obj *curr_expr;
   grn_obj *qe_next;
+  grn_obj current_request_id;
   void *parser;
   grn_timeval tv;
 
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index