Dynamic Auto Sharding support for Scala Slick -
Dynamic Auto Sharding support for Scala Slick -
this post related issue raised @ dynamically changing database shard connecting too.
pointers code should changed implement feature given @ https://github.com/slick/slick/issues/703
am newbie scala , slick , can help ? , how proceed implementing feature. there slick/scala pattern @ application level.
my problem "i have pool of connections of different shards of mysql, when write query/queries involving id's (sharding keys), slick should dynamically run particular query on respective database shard"
for example: if write query
val q = ( user <- users.filter(_.name === "cat") post <- posts.filter(_.postedby === user.id) comment <- comments.filter(_.postid === post.id) } yield comment.content q.run trivial case should 1 below. users += user(id = 1, name = "cat", email = "cat@mat.com") => hits shard no 1
even if user id, post id, comment id dynamically produced, slick should nail right database shard using sharding criteria ( key (id) % 3 ) , should happen @ background single database query.
to implement feature @ application level
is there way read query object state dynamically can write function
def func(q: query[something], shards: map[int, database], num: int): unit = { shards(q.getid % num).withsession{ implicit session => { q.run } }
usage:
val q = users.insert(user(id = 1, name = "cat", email = "cat@cat.com")) func(q, shards, 10) => q executes on 1 of 10 shards.
thanks.
scala slick sharding typesafe
Comments
Post a Comment