Re: Integration of Psycopg with XTA

Поиск
Список
Период
Сортировка
От Federico Di Gregorio
Тема Re: Integration of Psycopg with XTA
Дата
Msg-id e4d58a4a-ad55-1fba-53bf-5d301882a397@dndg.it
обсуждение исходный текст
Ответ на Integration of Psycopg with XTA  (Christian Ferrari <camauz@yahoo.com>)
Список psycopg
Hi Christian,

first of all I don't like SWIG at all (having used it myself to create 
Python bindings to the Ogre3D library). It makes too easy to depend on 
the internal state of the C library instead of abstracting it. A Python 
function that expects a C pointer (PQconn*) as its argument is... 
ridiculous?

Anyway, I think that if Python has a way to encapsulate a C a pointer 
and pass it unmodified from psycopg2 to XTA we'd have no problems 
exposing it on the connection. Something like connection._raw_pgconn, 
with a name horrible enough to make sure nobody tries to use it without 
knowing what she is doing. I don't think that exposing it just as an 
integer is enough, but I can be wrong here.

federico


On 09/25/2018 10:57 PM, Christian Ferrari wrote:
> Dear All,
> XTA (XA Transaction API, http://www.tiian.org/lixa/XTA.html) is a new 
> API that has been developed inside the LIXA project to support two phase 
> commit transactions in the context of FaaS (Function as a Service) and 
> microservice oriented, polyglot applications.
> 
> The API already supports C and C++ languages; it aims to support many 
> more, at the bare minimum Python, PHP and Java.
> I'm currently working on supporting Python with PostgreSQL and MySQL, 
> this mail thread is related to Python/PostgreSQL.
> 
> XTA is implemented in C language and XTA for Python is generated using 
> SWIG: I would like to repeat the approach for all the languages that 
> provides drivers derived from libpq-fe.h
> 
> Now the request for help: XTA needs to enlist all the resource managers 
> (here PostgreSQL) to manage them using 2 phase commit, basically it 
> requires a pointer (PGconn *) that must be passed to 
> PostgresqlXaResource constructor 
> (http://www.tiian.org/lixa/manuals/xta/CPP/classxta_1_1PostgresqlXaResource.html) 
> to create an XTA object associated to an already opened PostgreSQL 
> connection.
> 
> Here are the basic steps of a Python example program 
> (https://github.com/tiian/lixa/blob/master/doc/examples/xta/python/example_xta_sa21.py):
> 
> # initialize XTA environment
> Xta_Init()
> 
> # create a new PostgreSQL connection
> # Note: using PostgreSQL Psycopg2 functions
> rm1 = psycopg2.connect("dbname=testdb")
> 
> # create a new MySQL connection
> # Note: using MySQLdb functions
> rm2 = MySQLdb.connect("localhost", "lixa", "", "lixa")
> 
> # create a new XTA Transaction Manager object
> tm = TransactionManager()
> 
> # create an XA resource for PostgreSQL
> # second parameter "PostgreSQL" is descriptive
> # third parameter "dbname=testdb" identifies the specific database
> #
> # how to retrieve PGconn * from rm1?!
> xar1 = PostgresqlXaResource(rm1.conn, "PostgreSQL", "dbname=testdb")
> 
> Looking at the last statement, the stack is:
> - XTA native C library expects "PGconn *" to register the connection handler
> - XTA C++ wrapper expects "PGconn *" as the first parameter to construct 
> the object
> - XTA Python (SWIG generated) wrapper expects a "SWIG generated" PGconn 
> * pointer
> - psycopg2.connect does not provide me something equivalent to PGconn *, 
> at least it seems so to me.
> 
> Stated that replacing "PGconn *" with "void *" in the API stack would 
> not be an issue, the question is: what's the best way to retrieve 
> something thatcan be transformed in a C pointer that could be passed to 
> XTA constructor?
> 
>  From my point of view, this new API layout should solve most of the 
> issues presented by the old style TX API that I explored some years ago: 
> https://grokbase.com/t/postgresql/psycopg/122b1re71w/psycopg2-and-lixa
> 
> Thanks in advance for your help.
> Regards,
> Ch.F.
> 
> 


-- 
Federico Di Gregorio                         federico.digregorio@dndg.it
DNDG srl                                                  http://dndg.it
    I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M.


В списке psycopg по дате отправления:

Предыдущее
От: Christian Ferrari
Дата:
Сообщение: Integration of Psycopg with XTA
Следующее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Integration of Psycopg with XTA