Multi-tenant #331
Replies: 5 comments 12 replies
-
Hello @pelletier197 , That's a good idea. We actually have it in our roadmap for the coming version 5(we are not adding any new feature to current version). We are actually going further in Spring, we will provide the ability to load the changeLogs from the Spring context. However, this has to be approached with caution. All the parameters Mongock pass to. a changeSet are proxies(unless the developers specifies the opposite) to ensure that the lock is wrapping the i/o operations to the database, at least the writes. If you construct your changeLog on your own, this is going to be a problem, as a lot of developers won't be aware of this fact. Can you tell me why do you really need this? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply, and thanks to you for providing such a great framework to the community!
I unserstand perfectly your concern. However, this arises a small question : why do you put a lock on every parameter of the changelog? Wouldn't it be simpler to wrap the call to the changeset methods in a transaction and revert if any of the changelog fail? Sorry for that question out of no-where, but it feels a little funny the whole proxy thing on every parameter, especially since this doesn't fit well with kotlin where everything is final by default.
Yes, so I have a special use case for Mongo to support multi-tenancy, meaning each customer uses the same instance of Mongo, but will see his data stored in a completely different database. This is not well supported by Mongo either (we use spring), so we had to develop a little custom code to make this work. However, this means I have to run my migrations on multiple databases, which does not really fit into the use case for spring (or maybe there's a magical way to do this I don't know of) . So instead, I though of having an Interface Si here I am. Maybe there's a better alternative I didn't think of? Thanks for your help! |
Beta Was this translation helpful? Give feedback.
-
That would be a much easier approach. Mongock acquires the lock before the process starts, lets say for 3 minutes, and before every changeLog runs, it makes sure the lock is acquired for 3 minutes, right? What happens if a changeLog takes 4 minutes? The changeLog will be partially executed without lock. A solution it's to reserve the lock longer, lets say 5 minutes. Now, if another changeLog takes 6 minutes?...well, put something safe, an hour, as we know that mongock will release the lock once the process is finished, it won't probably take the hour ever. Well, that's ok, but what happens if the jvm is interrupted and Mongock cannot release the lock. The lock will be "unreleaseable" for an hour, which in most of cases will mean that the service running Mongock on that database won't be able to start. That's a unacceptable risk to take in production, specially in containerised environments 😉 I guess you get my point, basically that's not a robust approach. Instead, we have provided a more sophisticated mechanism hat guarantees the process is fully synchronised, based on a pessimistic lock which ensures every access(at least every write) is synchronised. Performance-wise doesn't mean a big impact as it's keep it in local memory and hits the database just when is required to refresh the lock. You may suggest using demon, but that's not that reliable and threads my not fit all the ecosystems.
As part of version 5 we are addressing this scenario, as it's starting to be a common one, specially for consultancies. That's what I made this questions, I'd like to understand your needs so we can provide the best solution :) |
Beta Was this translation helpful? Give feedback.
-
Yeah, I understand the problems with the lock. This is actually the first system I see that has a lock with a duration. Usually, I believe they put the lock in the database at the beginning of the process and remove it at the end (either the changelog crashes or not). This is an interesting approach, but i honestly don't see the advantages of it right away. You surely designed it this way for a reason, so I trust your judgment 😉 Anyway here's the answer to both questions above :
Hope this helps 🙂 |
Beta Was this translation helpful? Give feedback.
-
I see your point. This is something that doesn't really shines and may not be needed in most of the cases for you, but it's a must for a robust system, specially in containerised environments where automation is key. Actually the reason we started this project was because we experienced a big issue, that happened sometimes, but when it happened, was terrorific. The service couldn't get recovered and we had to remove the lock collection and deploy it manually again. It was reeeeally hard to find. It may look a bit over-engineered, but we are obsessed with robustness, so the tool gives the less problems possible and you can focus on your business.
Just out of curiosity? Which company are you? If you can't give the name, could you at least provides the industry? Cheers |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a feature request for mongock that could be interesting. I see mongock is able to scan packages looking for changesets and automatically instantiate classes, which is good. However, in some use-cases, changesets could be manually instantiated, and in my use-case I would need to provide those instances directly to mongock, instead of letting the framework instantiate them.
Something like this:
I haven't looked deep into the architecture, but I believe this would be quite simple to implement. Let me know what you think!
Beta Was this translation helpful? Give feedback.
All reactions