question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support multitenancy

See original GitHub issue

Support multitenancy

I work on Spring-boot+Postgre application which works in multitenant-mode. Namely, we implemented AbstractRoutingDataSource and our solution is based on using ThreadLocal:

public class MyRoutingSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        return getNameOfTenantFromThreadLocal();
    }
    // ....
}

Ultimately I would like Shedlock to support the following:

  • single LockProvider bean (as it is now)
  • database for each tenant having own shedlock table
  • cache LockRecordRegistry be tenant-dependant (i.e. private final Set<String> lockRecords transform to private final Map<Object, Set<String>> lockRecords where Object is tenant identifier (same as in AbstractRoutingDataSource).

When I tried to supply instance of AbstractRoutingDataSource to JdbcTemplateLockProvider(myRoutingSource) then I’ve got runtime exception because initialization of new Bean isn’t bound to any tenant-context and SqlStatementsSource#getDatabaseProductName is trying to query DB during initialization.

Suggested improvement

  • Give option to configuration to rather directly specify database-used OR lazy initialize DB provider name. Example:
private static String getDatabaseProductName(Configuration configuration) {
        if (configuration.getPredifnedDatabaseProductName() != null) {
                return configuration.getPredifnedDatabaseProductName();
        }
        return configuration.getJdbcTemplate().execute((ConnectionCallback<String>) connection -> connection.getMetaData().getDatabaseProductName());
    }
  • Make cache tenant-configurable.

How to use multitenancy right now Workaround solution I came with:

  • single LockProvider bean
  • separate database for shedlock which is shared by all tenants
  • wrapper util on top of shedlock where I add tenant-name as prefix to lock name

Extra I would like to say thank you for such a nice library!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lukas-krecancommented, May 11, 2020
1reaction
lukas-krecancommented, May 4, 2020

Yes, that’s why I hesitate to add DB provider to the configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SaaS: Single Tenant vs Multi-Tenant - What's the Difference?
Multi-Tenant – Multi-tenancy means that a single instance of the software and its supporting infrastructure serves multiple customers.
Read more >
What is multi-tenancy? | Definition from TechTarget
Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers. Each customer is called a tenant.
Read more >
Multitenancy - Wikipedia
Software multitenancy is a software architecture in which a single instance of software runs on a server and serves multiple tenants.
Read more >
What is multitenancy? - Red Hat
Multitenancy is a software architecture where a single software instance can serve multiple, distinct user groups.
Read more >
Definition of Multitenancy - IT Glossary - Gartner
Multitenancy is a reference to the mode of operation of software where multiple independent instances of one or multiple applications operate in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found