{"action":"opened","issue":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/513","labels_url":"https://api.github.com/repos/npgsql/npgsql/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/npgsql/issues/513/comments","events_url":"https://api.github.com/repos/npgsql/npgsql/issues/513/events","html_url":"https://github.com/npgsql/npgsql/issues/513","id":59456077,"number":513,"title":"Some design problems in current TransactionScope implemention","user":{"login":"skykiker","id":5112196,"avatar_url":"https://avatars.githubusercontent.com/u/5112196?v=3","gravatar_id":"","url":"https://api.github.com/users/skykiker","html_url":"https://github.com/skykiker","followers_url":"https://api.github.com/users/skykiker/followers","following_url":"https://api.github.com/users/skykiker/following{/other_user}","gists_url":"https://api.github.com/users/skykiker/gists{/gist_id}","starred_url":"https://api.github.com/users/skykiker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skykiker/subscriptions","organizations_url":"https://api.github.com/users/skykiker/orgs","repos_url":"https://api.github.com/users/skykiker/repos","events_url":"https://api.github.com/users/skykiker/events{/privacy}","received_events_url":"https://api.github.com/users/skykiker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-02T09:21:40Z","updated_at":"2015-03-02T09:21:40Z","closed_at":null,"body":"Hi,all\r\n\r\nIn my view there's some design problems in current TransactionScope implemention.\r\nI wish these problems will not appear in the future Npgsql V3.1 .\r\n\r\n1)it's not needed to implement the IPromotableSinglePhaseNotification interface\r\n\r\nPromotable Single Phase Enlistment(PSPE) is used to optimize performance for an \"remote\" durable resource.\r\n\r\nhttps://msdn.microsoft.com/en-us/library/ms229980.aspx\r\n--------------------------------------------\r\nTo optimize performance, the System.Transactions infrastructure provides the Promotable Single Phase Enlistment (PSPE) that allows a single remote durable resource, located in a different application domain, process or machine, to participate in a System.Transactions transaction without causing it to be escalated to an MSDTC transaction. This resource manager (RM) can host and \"own\" a transaction that can later be escalated to a distributed transaction (or MSDTC transaction) if necessary. This reduces the chance of using the MSDTC.\r\n------------------------------------------\r\n\r\nBut Npgsql is not a \"remote\" durable resource,and not need to to implement the PSPE.\r\nIn other words,the class NpgsqlPromotableSinglePhaseNotification is not useful(except making code more complex).\r\n\r\n\r\n2)it's not necessity to implement a \"Durable Resource Manager\"\r\n\r\nAaccording to MSDN \"The durability (or conversely the volatility) of a resource manager refers to whether the resource manager supports failure recovery\".\r\n\r\nhttps://msdn.microsoft.com/en-us/library/ms172153.aspx\r\n-----------------------------------------------------------\r\nEnlisting Resources in a Transaction\r\nIn order for a resource to participate in a transaction, it must enlist in the transaction. The Transaction class defines a set of methods whose names begin with Enlist that provide this functionality. The different Enlist methods correspond to the different types of enlistment that a resource manager may have. Specifically, you use the EnlistVolatile methods for volatile resources, and the EnlistDurable method for durable resources. The durability (or conversely the volatility) of a resource manager refers to whether the resource manager supports failure recovery. If a resource manager supports failure recovery, it persists data to durable storage during Phase1 (prepare) such that if the resource manager goes down, it can re-enlist in the transaction upon recovery and perform the proper actions based on the notifications received from the TM. In general, volatile resource managers manage volatile resources such as an in-memory data structure (for example, an in-memory transacted-hashtable), and durable resource managers manage resources that have a more persistent backing store (for example, a database whose backing store is disk).\r\n-----------------------------------------------------------\r\n\r\nNpsql currently does not support failure recovery,and so is not a durable resource indead.\r\nSo Npsql should use the EnlistVolatile method to enlist in the transaction, but now Npgsql use the EnlistDurable method.\r\nUsing of the EnlistDurable method means more tend to use MSDTC other than System.Transactions,and performance is poor.\r\n\r\nhttps://msdn.microsoft.com/en-us/library/ms229980.aspx\r\n-------------------------------------------\r\nPromotable Single Phase Enlistment\r\nThe System.Transactions infrastructure administrates a transaction inside a single application domain that involves at most a single durable resource or multiple volatile resources. Since the System.Transactions infrastructure uses only intra-application domain calls, it yields the best throughput and performance.\r\n-------------------------------------------\r\n\r\nAnd you will find some .NET Data Providers(Firebird,Mysql?) which do not support \"failure recovery\" just implement TransactionScope as an  \"Volatile Resource\"(call EnlistVolatile method to enlist in the transaction).I think that maybe the correct strategy to implementing TransactionScope.\r\n\r\n3)Consideration of mutithread is not sufficient\r\nThe member methods from the IEnlistmentNotification interface(or other interfaces for TransactionScope) will be called by a backgroud thread but not the main thread.But the current TransactionScope implementation does not careful to deal with that.\r\nSuch as should use \"cancle\" but not \"rollback\" to deal with timeout(a bug report by #495) ,\r\n,should not throw execption in these interface's methods directly(the backgroud thread can not deal with the excption correctly),and so on.\r\n\r\nIf your agree with me about these problems,i propose create a new TransactionScope implementation.\r\nBecause the current TransactionScope implementation is too complex for supporting of PSPE.\r\n\r\nbest regarts,\r\nChen Huajun"}}