Giter VIP home page Giter VIP logo

Comments (8)

5HT avatar 5HT commented on July 26, 2024 1

This is not correct usage of KVS. The example of table creation you can see in n2o/samples.

Basically you need to plug KVS schema into sys.config file.

$ cat sys.config
[
 {kvs, [{dba,store_mnesia},
        {schema, [kvs_feed ]} ]}
].
-module(kvs_feed).
metainfo() ->  #schema{name=kvs,tables= core() }.

core()
  -> [ #table{name=config,fields=record_info(fields,config)},
       #table{name=log,container=true,fields=record_info(fields,log)},
       #table{name=operation,container=log,fields=record_info(fields,operation)},
       #table{name=id_seq,fields=record_info(fields,id_seq),keys=[thing]} ].

Just follow the examples. Did you try to read the README.md ? ;-)

from kvs.

5HT avatar 5HT commented on July 26, 2024 1

This is wrong.

-record(text, {id=[], title=[], body=[]}).

Please read this fucking manual :-) You need to include ?ITERATOR field package in order this machinery to work.

from kvs.

5HT avatar 5HT commented on July 26, 2024 1

When record has no ITER section it means you can't use kvs:add, but only kvs:put.

from kvs.

5HT avatar 5HT commented on July 26, 2024

The story is that KVS after 3.3 KVS tables support versioning. It means you can tune KVS to rip the table when number of objects exceed some limit (in this example is 5):

> kvs:id_seq(user).
30
> kvs:config(user).
[{interval,31,infinity,user6,user},
 {interval,25,30,user5,user},
 {interval,19,24,user4,user},
 {interval,13,18,user3,user},
 {interval,7,12,user2,user}]

So when you read from mnesia you see only 5 entries as they are stored in dedicated table.

>  mnesia:transaction(fun() ->  qlc:eval(mnesia:table(user4)) end).
{atomic,[{user4,19,[],feed,user,18,20,[],true,
                [],[],[],[],[],[],
                [],[],[],[],[],[],
                [],[],[],[]},
         {user4,20,[],feed,user,19,21,[],true,[],
                [],[],[],[],[],[],
                [],[],[],[],[],[],
                [],[],[]},
         {user4,21,[],feed,user,20,22,[],true,[],
                [],[],[],[],[],[],
                [],[],[],[],[],[],
                [],[],...},
         {user4,22,[],feed,user,21,23,[],true,[],
                [],[],[],[],[],[],
                [],[],[],[],[],[],
                [],...},
         {user4,23,[],feed,user,22,24,[],true,[],
                [],[],[],[],[],[],
                [],[],[],[],[],[],...},
         {user4,24,[],feed,user,23,25,[],true,[],
                [],[],[],[],[],[],
                [],[],[],[],[],...}]}

But when you perform KVS traversal it uses config table and switch tables during traversal.

> length(kvs:entries(kvs:get(feed,user),user,infinity)).
30

This approach is not new, something similar happens in SQL and BitTables. But the reason I'm describing this here is directly connected with your questions. From 3.3 index fields (which is second field in record after atomic record name) should be.

> [ kvs:add(#user{id=kvs:next_id("user",1)}) || _ <- lists:seq(1,30) ], ok.
ok

That means when you populating data, you can put in id field only integer. Because the table will selected on particular interval intersection (taken from list of intervals: kvs:config/1).

Hope this helps. It is clearly that you put <<"Test title">> as index for kvs:rname/1

[{erlang,atom_to_list,[<<"Test title">>],undefined}, {kvs,rname,1,383}

Could you please give me the KVS schema definition (not mnesia one) of your table?

from kvs.

Spoowy avatar Spoowy commented on July 26, 2024

Hi @5HT,
Thank you for your help!

This is all the code I wrote to create the table & schema:

-module(database_logic).

-include_lib("stdlib/include/qlc.hrl").

-export([init/0, insert/0]).

-record(text, {id=[], title=[], body=[]}).

init () ->
	mnesia:create_table(text, [{attributes, record_info(fields, text)},
		{type, bag},
		{disc_copies, [node()]}]).

Hope this helps.

from kvs.

Spoowy avatar Spoowy commented on July 26, 2024

Ah yes, I've edited that file before! (I've been somewhat irritated by the example users.hrl file that you find in the review project)
Let me try again, and come back with the results.

from kvs.

Spoowy avatar Spoowy commented on July 26, 2024

I have succeeded in creating the table according to kvs's way, however, I'm still receiving an error in the console, when trying to insert data:

n2o_nitrogen:Pickle: {pickle,<<"submit">>,
                                                                       <<"g2gCaAVkAAJldmQABXNtb2tlZAAGc3VibWl0bQAAAAZzdWJtaXRkAAVldmVudGgDYgAABepiAAZSgWIADjSt">>,
                                               [{{"submit",<<"detail">>},[]},
                                   {title,"weafwef"},
                                                                                   {body,"awefawef"}]}
n2o_nitrogen:Catch: error:badarg
                                [{erlang,atom_to_list,[<<"weafwef">>],undefined},
          {kvs,rname,1,383},
                             {kvs,range,2,334},
                                                {kvs,get,3,261},
                                                                 {kvs,ensure_link,2,103},

My table schema has been -record(text, {id=[], title=[], body=[]}).

6> kvs:id_seq(text).
47
7> kvs:config(text).
[]
8> mnesia:transaction(fun() ->  qlc:eval(mnesia:table(text)) end). 
{atomic,[]}
9> length(kvs:entries(kvs:get(feed,text),text,infinity)).
0
10> [ kvs:add(#text{id=kvs:next_id("text",1)}) || _ <- lists:seq(1,30) ], ok.
* 1: record text undefined

getting undefined for user as well, a table which comes installed with kvs

11> [ kvs:add(#user{id=kvs:next_id("user",1)}) || _ <- lists:seq(1,30) ], ok.
* 1: record user undefined

Does this help?

from kvs.

Spoowy avatar Spoowy commented on July 26, 2024

I'm not having such a hard time reading the manual, and I've restarted the whole process with the ?ITERATOR field (note, in subscription.hrl there is no ?ITERATOR field as well for some reason).

And yes! It works!

Hope this may be beneficial to other newcomers. Thanks again, @5HT.

from kvs.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.