biokoda / actordb

ActorDB distributed SQL database
Mozilla Public License 2.0
1.89k stars 72 forks source link

key-value sharding questions / examples #37

Closed glycerine closed 7 years ago

glycerine commented 7 years ago

I am interested in the key-value functionality, but I don't understand what actordb provides from reading the docs. Particularly I'm curious about how sharding and the key-value functionality interact.

  1. For a kv actor, are keys kept in sorted order, so range queries are supported?

  2. What happens if my key-value actor needs to expand beyond a single shard?

  3. How does sharding and rebalancing happen in a key-value actor -- is balancing automatic? If not, could you give an example of how it should be done.

  4. I see example create table commands for kv actor, but a fuller worked example with selects and updates and inserts would be helpful.

  5. I don't understand the sub-table needing a foreign key to the main kv table -- perhaps an example would help here too. I didn't understand the purpose of splitting a key into master and sub-table.

Thank you.

SergejJurecko commented 7 years ago
  1. actor name is a key and yes they are indexed. This type of query is fine:

ACTOR type1(* where id like 'some_prefix%');

  1. kv actors are always across multiple shards. ~12 per cluster.

  2. When you add new clusters, shards will get split in half. The first half remains on the old servers, the top half goes to new nodes. It is automatic. Basically what happens is a copy of the complete shard to the new node, then the origin shard runs delete from actors where hash >= SPLIT_POINT and the new shard runs delete from actors where hash < SPLIT_POINT.

  3. This pretty much covers the main points of the functionality. http://www.actordb.com/docs-kvstore.html#about_kv_store

  4. Sub table needs to be linked to the main key so that sharding works. delete * from actors where hash >= SPLIT_POINT must delete all data for keys that are no longer required. And when you query for data to subtable it must be in the same shard as the main actors table.

glycerine commented 7 years ago

Thanks @SergejJurecko, very helpful.