[openstack-dev] [tricircle] DAL implementation

joehuang joehuang at huawei.com
Fri Jul 31 09:31:54 UTC 2015


Hi, Vega,

Thanks for your response.  I think we can include the session in the context.

Best Regards
Chaoyi Huang ( Joe Huang )

From: Vega Cai [mailto:luckyvega.g at gmail.com]
Sent: Friday, July 31, 2015 9:44 AM
To: OpenStack Development Mailing List (not for usage questions)
Subject: Re: [openstack-dev] [tricircle] DAL implementation

Hi Joe,

I think one independent job is finished in one session. The job is responsible to start  a session, query or modify database then end the session. Like port creating job in neutron, it starts a session, queries network, adds port, allocates ip address, then ends the session at the end.

BR
Zhiyuan

On 31 July 2015 at 09:05, joehuang <joehuang at huawei.com<mailto:joehuang at huawei.com>> wrote:
Hi, Vega,

Multiple DB access will be a use case for one session , especially for DB data insertion, multiple table will be involved. To embed the session in Context, it’s ok to start a session if the session is empty, but how to decide when to commit the data, end a session?

Best Regards
Chaoyi Huang ( Joe Huang )

From: Vega Cai [mailto:luckyvega.g at gmail.com<mailto:luckyvega.g at gmail.com>]
Sent: Thursday, July 30, 2015 3:03 PM
To: openstack-dev at lists.openstack.org<mailto:openstack-dev at lists.openstack.org>
Subject: [openstack-dev] [tricircle] DAL implementation

Hi folks,

In my current implementation, there are a core module and a models module. Core module handles all the database stuff, start a session, issue sql operation, then end a session. Models module invokes methods in core module to access database, as showed below:

model.py
def get_site(site_id):
    core.get_resource(Site, site_id)

core.py
def get_resource(model, pk_value):
    # code to access database

To add context, I am going to implement like this:

model.py
def get_site(context, site_id):
    policy_check(context)
    core.get_resource(Site, site_id)

core.py
def get_resource(model, pk_value):
    # code to access database

So there is no need to embed session into context.

One advantage of embedding session into context is that you can combine more than one method calls in one session, like:

model.py
def complex_operation(context):
    policy_check(context)
    with context.session.begin():
        core.operation1(context)
        core.operation2(context)

But this approach moves session handling from core module to models module and core module just provides some utility methods.

I'm not sure which one is better.

BR
Zhiyuan

__________________________________________________________________________
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe<http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe>
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150731/c2e015e0/attachment.html>


More information about the OpenStack-dev mailing list