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

multitenant support #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

anttip
Copy link

@anttip anttip commented Dec 13, 2011

I saw that you were considering implementing multitenant support to play-morphia. I would really like to see this happen, so here's one take on implementing multitenant support to play-morphia.

This implementation allows modifying the collection name for each tenant. I couldn't find clear documentation on how to modify Morphia's collection names dynamically, but overriding DatastoreImpl.getCollection seemed to work against the current test suite and also in my own testing.

…tenant).

Modified build.xml to read build.properties.
@ahmetb
Copy link

ahmetb commented Dec 25, 2011

pardon me but is this a support for managing multiple databases (rather than different collections in a db) in one single morphia session? I'm not clear with that.

@anttip
Copy link
Author

anttip commented Dec 25, 2011

This implementation is for managing collection names. By implementing the TenantContext interface you can modify the collection names to include a tenant-specific identifier, see the interface: https://github.com/anttip/play-morphia/blob/f01ac360e06f23d2d5455c1a3c103aa98b47dc79/src/play/modules/morphia/TenantContext.java and an example implementation https://github.com/anttip/play-morphia/blob/f01ac360e06f23d2d5455c1a3c103aa98b47dc79/src/play/modules/morphia/ThreadLocalTenantContext.java

@greenlaw110
Copy link
Collaborator

Hi, sorry for the late response. Just come back from holiday.

So it looks like it's not what I am thinking of. I prefer to provide a way that programmer could specify a different db rather than a different collection where the model could be mapped into. Anyway let me check your code and see how it goes.

*
*/
public class ThreadLocalTenantContext implements TenantContext {
private static ThreadLocal<String> userLocal = new ThreadLocal<String>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using threadlocal variable in this way is not safe in play environment. Because a thread might very possible be to handle another incoming request where the context is totally different.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain how it is not safe? This is meant to be used from Play's lifecycle methods (@before, @Final). I followed this discussion and assumed it would be ok : http://groups.google.com/group/play-framework/browse_thread/thread/5a568d6aa7cb8c9b

@anttip
Copy link
Author

anttip commented Jan 10, 2012

Hi,

the reason I went with using collections/customer instead of
databases/customer was how mongodb saves it data files. Mongodb
preallocates the files so you will end up having quite a bit of unused
diskspace allocated but unused. Here's a more detailed explanation:
http://blog.boxedice.com/2010/02/28/notes-from-a-production-mongodb-deployment/#comment-818

But I think these approaches are not mutually exclusive. For example Grails
has a mongodb-multitenant plugin that does both schemes. It puts 500
customers in a single database with renaming collections and if you have
more it will allocate a new db for every set of 500 customers.
http://grails.org/plugin/mongodb-multitenant

2012/1/10 Green Luo <
[email protected]

Hi, sorry for the late response. Just come back from holiday.

So it looks like it's not what I am thinking of. I prefer to provide a way
that programmer could specify a different db rather than a different
collection where the model could be mapped into. Anyway let me check your
code and see how it goes.


Reply to this email directly or view it on GitHub:
#57 (comment)

@greenlaw110
Copy link
Collaborator

That's an interesting point. Probably providing multi-tenant solution cater
for both db and collection, and let user to choose their option is a good
idea

On Tue, Jan 10, 2012 at 6:38 PM, anttip <
[email protected]

wrote:

Hi,

the reason I went with using collections/customer instead of
databases/customer was how mongodb saves it data files. Mongodb
preallocates the files so you will end up having quite a bit of unused
diskspace allocated but unused. Here's a more detailed explanation:

http://blog.boxedice.com/2010/02/28/notes-from-a-production-mongodb-deployment/#comment-818

But I think these approaches are not mutually exclusive. For example Grails
has a mongodb-multitenant plugin that does both schemes. It puts 500
customers in a single database with renaming collections and if you have
more it will allocate a new db for every set of 500 customers.
http://grails.org/plugin/mongodb-multitenant

2012/1/10 Green Luo <
[email protected]

Hi, sorry for the late response. Just come back from holiday.

So it looks like it's not what I am thinking of. I prefer to provide a
way
that programmer could specify a different db rather than a different
collection where the model could be mapped into. Anyway let me check
your
code and see how it goes.


Reply to this email directly or view it on GitHub:
#57 (comment)


Reply to this email directly or view it on GitHub:
#57 (comment)

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

Successfully merging this pull request may close these issues.

3 participants