How to create sharded-queue tube the right way?

150 Views Asked by At

Let's say we have Tarantool Cartridge based service, which stores posts made by users. When user makes a new post, it is inserted to corresponding space. Simultaneously into sharded-queue tube notify_friends is added task for notifying user friends about new post.

Question is about creation of tube notify_friends. Initially I planned to do that in init() method of the service role, but it causes error, because tube creation modifies clusterwide-config and it is being changed when init() runs. I could try creating tube at first task add request, but not sure if it's the best approach.

2

There are 2 best solutions below

0
On BEST ANSWER

You can put it to "default config" of your app.

Check it here: How to implement default config section for a custom Tarantool Cartridge role?

3
On

There are 2 ways I'd go with it:

  1. Create the tube on the first request as you propose. Nothing bad will happen.
  2. If you want to do it in advance - create a fiber in the init function that will try to create the tube after 10 seconds since the initialization, if the tube doesn't exist. You can figure out all instances that have sharded_queue storage, and run the fiber only on the first one (sort alphabetically by instance URI).