Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONB Support #5

Closed
sommergis opened this issue Mar 3, 2023 · 2 comments
Closed

JSONB Support #5

sommergis opened this issue Mar 3, 2023 · 2 comments

Comments

@sommergis
Copy link

Hi Peter,

I encountered an issue when dealing with JSONB columns in a publication. When I add the test data like this:

CREATE TABLE public.json_sample (id serial PRIMARY KEY, keyval jsonb);
INSERT INTO public.json_sample (keyval) VALUES ('{"foo": "bar", "baz": 1}');

When I change the publication to this dataset, pgec seem to crash and the REST API is not available anymore:

=CRASH REPORT==== 3-Mar-2023::19:10:32.062821 === <0.6203.0> proc_lib:crash_report/4:539
  crasher:
    initial call: cowboy_stream_h:request_process/3
    pid: <0.6203.0>
    registered_name: []
    exception error: bad argument
      in function  ets:safe_fixtable/2
         called as ets:safe_fixtable(osm_rivers_sample,true)
         *** argument 1: the table identifier does not refer to an existing ETS table
      in call from ets:foldl/3 (ets.erl, line 632)
      in call from pgec_h:init/3 (src/pgec_h.erl, line 51)
      in call from cowboy_handler:execute/2 (src/cowboy_handler.erl, line 37)
      in call from cowboy_stream_h:execute/3 (src/cowboy_stream_h.erl, line 306)
      in call from cowboy_stream_h:request_process/3 (src/cowboy_stream_h.erl, line 295)
    ancestors: [<0.6201.0>,<0.217.0>,<0.216.0>,ranch_sup,<0.116.0>]
    message_queue_len: 0
    messages: []
    links: [<0.6201.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 376
    stack_size: 28
    reductions: 323
  neighbours:

=ERROR REPORT==== 3-Mar-2023::19:10:32.064281 === <0.6201.0>
Ranch listener pgec, connection process <0.6201.0>, stream 1 had its request process <0.6203.0> exit with reason badarg and stacktrace [{ets,safe_fixtable,[osm_rivers_sample,true],[{error_info,#{cause => id,module => erl_stdlib_errors}}]},{ets,foldl,3,[{file,"ets.erl"},{line,632}]},{pgec_h,init,3,[{file,"src/pgec_h.erl"},{line,51}]},{cowboy_handler,execute,2,[{file,"src/cowboy_handler.erl"},{line,37}]},{cowboy_stream_h,execute,3,[{file,"src/cowboy_stream_h.erl"},{line,306}]},{cowboy_stream_h,request_process,3,[{file,"src/cowboy_stream_h.erl"},{line,295}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]

Could look into this?

@shortishly
Copy link
Owner

I've updated pgec on develop with a JSON and JSONB example. If you could please try:

cd pgec
docker compose --profile all down --remove-orphans --volumes
git checkout develop
PGEC_VERSION=develop docker compose --profile all up --detach

http:

curl -s http://localhost:8080/pub/col_jsonb/1
{"a":{"baz":1,"foo":"bar"},"id":1}

curl -s http://localhost:8080/pub/col_json/1
{"a":{"baz":1,"foo":"bar"},"id":1}

reids:

redis-cli  HGETALL pub.col_jsonb.1
1) "id"
2) "1"
3) "a"
4) "{\"baz\":1,\"foo\":\"bar\"}"

Let me know if that solves your issue please :)

Please note that restarting pgec is currently necessary after using alter publication. However, using create publication pub for tables in schema current_schema (or a specific schema) does work, and any tables created in the schema after the publication will be picked up automatically without requiring pgec to restart.

@sommergis
Copy link
Author

Thanks a lot - it works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants