Hi David, Thanks for your response. Of course, the scenario that is sketch is a styled example to clearly illustrate what I want to achieve. Also, at least to my current understanding, I do not propose 3 XA transaction managers but 2 XA resources and 1 transaction managers.
I want build a plugin system (where a plugin could roughly correspond to a Karaf feature) in which the plugins are completely isolated meaning that they can not see each other, unless a specific service is exported. "Not seeing each other" also entails that they can not see each other data(bases). The reason for this is the plugins are provided by many different third parties who do not necessarily have to trust each other. Even more, the plugins are not aware of each other (loose coupling), except for the services that are exported. This means that the datasources have to be private to the plugin/feature. To try this out, I have developed two bundles, each with a XA resource. If however I do "service:list javax.sql.DataSource" it shows that each respective datasource is used by both plugins. This is not what I want. I have read quite a lot about XA/OSGI transactions the past few days but I can not find anything about: - branches of transactions as you mention - a good example with two or more datasources of different bundles, where updates are managed by a (global) transaction manager. I would be very happy if you/someone could point me to a few examples and/or documentation about this. With respect to idempotent messages: Just using that would not say anything about transactionality right? Thanks for your help again. Best, -- Jaap |-----Oorspronkelijk bericht----- |Van: David Jencks <[email protected]> |Verzonden: zondag 10 oktober 2021 22:48 |Aan: [email protected] |Onderwerp: Re: Data isolation between Karaf bundles/features: how to |achieve? | |As written, your proposal involves 3 XA transaction managers, two of which |are also packaged as XAResources. For this scenario, that’s ridiculous. | |If this is a toy problem for you to learn about XA, I think what you mean is: | |department bundle starts an XA transaction and removes the department in a |branch of this transaction | |something communicates the departmentId and transaction Xid to the person |bundle (normally the Xid is communicated via a thread local, i.e. it’s attached |to the current thread) | |Person bundle removes the relevant people in another branch of this same |transaction. | |Something (probably the department bundle) ends the XA transaction (commit |or rollback). | |I think there’s now an OSGI spec transaction coordinator that should help with |this, but I don’t remember the details or whether the implementation is in felix |or aries. | |If this is a real problem, it’s usually better to find a way to avoid XA, such as |sending idempotent messages. | |David Jencks | |> On Oct 10, 2021, at 11:37 AM, jgfrm <[email protected]> wrote: |> |> Suppose the following case: |> |> - there is a Person bundle, responsible of managing persons |> - there is a Department bundle, reponsible of managing departmens. |> |> - there is a constraint: A person always works for precisely one |> department; hence a person can not exist without the department s/he |works for. |> |> Hi |> |> I am interested to understand if Isolation of data (between bundles) |> is possible in Karaf. |> |> Suppose the following case: |> - there is a Person bundle, responsible of managing persons |> - there is a Department bundle, responsible of managing departments. |> - there is a constraint: A person always works for precisely one |> department; hence a person can not exist without the department s/he |works for. |> |> I have the following requirements: |> - The Person bundle can not use the data (departments) stored by the |> Department bundle (e.g. a table "Department") |> - The Department bundle can not use the data(persons) stored by the |> Person bundle (e.g. a table "Person") |> - If a department is deleted, all persons that work for that |> department would be deleted too (due to the formulated constraint). |> |> How to do this in Karaf/OSGI? |> My ideas: |> - each bundle (Department and Person) has an own persistence unit. The |> persistence unit refers to different databases with their own access |> control, or the different schemas in the same database with proper |> access control on the database level. Bundles can not see each other's |> persistence unit. Because these are effectively two separate |> databases, we can not use foreign keys to represent that an employee |> always works for precisely one department. |> Therefore: |> - there is a bundle that represents a transaction coordinator |> - the Person bundle tells the transaction coordinator that there is a |> constraint: namely that it want to informed if a person is deleted |> - in case a department is deleted the following happens: |> - the department bundle builds a XA transaction to delete the |> department |> - the department bundle informs the transaction coordinator that it |> created a transaction to delete the department, including the |> identifier of the department to be deleted |> - the transaction coordinator informs the person bundle that a |> department with a particular identifier is going to be deleted |> - the person bundle looks up all persons that work for the department, |> and creates a XA transaction to delete all these persons |> - the person bundle informs the transaction coordinator that it |> created a transaction to delete the persons, including a list with |> identifiers of the persons to be deleted |> - the transaction coordinator executes both transaction as one |> enclosing transaction using the 2-phase commit protocol. |> |> Questions: |> - is this a feasible scenario in Karaf? |> - if so, how should it be implemented? Specific tips? |> - are there any examples doing similar things? |> |> Best, |> |> -- Jaap |>
