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

Resolve TODO for secondary DB #705

Open
pooja1pathak opened this issue Nov 22, 2022 · 3 comments
Open

Resolve TODO for secondary DB #705

pooja1pathak opened this issue Nov 22, 2022 · 3 comments

Comments

@pooja1pathak
Copy link
Collaborator

Resolve TODO for secondary DB at:

# TODO add not critical check if a secondary db is configured

@Ravisaketi
Copy link
Contributor

Hi @c0c0n3 @chicco785 i have check for this issue about adding not critical check if a secondary db is configured and i found these comments related this issue
#377 (comment)
and I'm not sure about secondary db, could you please guide me about secondary db.

@Ravisaketi Ravisaketi mentioned this issue Dec 5, 2022
12 tasks
@c0c0n3
Copy link
Member

c0c0n3 commented Jan 6, 2023

Hi @Necravisaketi, sorry for getting back to you sooo late on this. But as they say, better late than never :-)

Quantum Leap is designed to work with different DB backends simultaneously. At the moment we only support two DBs, namely Crate and Timescale, but we could add more in the future. For any given API call requiring a DB, QL selects a DB backend depending on the tenant (FIWARE service header) the call is for. The algo that does this tenant-to-DB routing is:

  1. Load a tenant-to-DB-ID map M.
  2. If M[tenant] = db-id exists, then use the DB identified by db-id.
  3. Otherwise, use the DB specified by the QL_DEFAULT_DB env var if set or Crate if the var isn't set. When this is the case, we say we're using the "default backend".

The map M gets loaded from QL's config YAML file (QL_CONFIG env var) if that file exists, otherwise M is the empty map---which results in every call using the "default backend" b/c of (3) above.

The YAML configuration file specifies what backend to use for which tenant as well as the default backend to use for any other tenant not explicitly mentioned in the file. Here's an example YAML configuration:

tenants:
    t1:
        backend: Timescale
    t2:
        backend: Crate
    t3:
        backend: Timescale

default-backend: Crate

With this configuration, any NGSI entity coming in for tenant t1 or t3 gets stored in Timescale whereas tenant t2 gets to use Crate. Any tenant other than t1, t2, or t3 gets the default Crate backend.

@c0c0n3
Copy link
Member

c0c0n3 commented Jan 6, 2023

Now let's talk about "secondary DB". I think this is a bit of a misnomer, since you could be in a situation where half of your tenants use Crate and the other half Timescale. What's the meaning of "secondary" in this case? So let's just drop that term and talk about configured DBs.

So if you want a sane implementation of that health check, you should first determine the set of configured DBs and then ping each DB in the set. How to figure out that set though? Well, the set is given by taking the values in M plus the value of QL_DEFAULT_DB if set and remove duplicates.

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

3 participants