README.providers.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
  5. <TITLE></TITLE>
  6. <META NAME="GENERATOR" CONTENT="OpenOffice 4.1.1 (Unix)">
  7. <META NAME="CREATED" CONTENT="0;0">
  8. <META NAME="CHANGEDBY" CONTENT="Alex Peshkoff">
  9. <META NAME="CHANGED" CONTENT="20141113;13283500">
  10. <STYLE TYPE="text/css">
  11. <!--
  12. @page { margin: 0.79in }
  13. P { margin-bottom: 0.08in }
  14. -->
  15. </STYLE>
  16. </HEAD>
  17. <BODY LANG="en-US" DIR="LTR">
  18. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>Providers.</FONT></P>
  19. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><BR>
  20. </P>
  21. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>Providers
  22. architecture is definitely one of key features of Firebird 3. But to
  23. be precise this is far not new feature - providers existed in
  24. Firebird's predecessors long ago, and in 'deeply hidden' form are
  25. present in any Firebird version. Initially providers were introduced
  26. to deal with a task which is currently well known to be performed by
  27. ODBC, ADO, BDE, etc. They were needed to make it possible to access
  28. different database engines using single external interface. But later
  29. providers architecture (known that time as OSRI - Open Systems
  30. Relational Interface) also showed itself as very efficient for
  31. supporting mix of old and new database formats (different major ODS)
  32. at single server and having mixed connections to local and remote
  33. databases. Implemented in Firebird 3 providers make it possible to
  34. support all this modes (remote connections, different ODS databases,
  35. foreign engines) and also providers chaining (when some provider is
  36. using callback to standard API when performig an operation on
  37. database).</FONT></P>
  38. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>Main
  39. element of providers architecture is YValve. On initial attach (or
  40. create) database call it scans the list of known providers and calls
  41. them one by one until tried provider completes requested operation
  42. successfully. For already established connection appropriate provider
  43. is called at once with almost zero overhead. Lets take a look at some
  44. samples of YValve operation when it selects appropriate provider at
  45. attach stage.</FONT></P>
  46. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><BR>
  47. </P>
  48. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>Next
  49. samples are with default configuration, which contains 3 providers:
  50. <B>Remote</B> (establish network connection), <B>Engine14</B> (main
  51. database engine) and <B>Loopback</B> (force network connection to
  52. local server for database name without explicitly given network
  53. protocol).</FONT></P>
  54. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>When
  55. one attaches to database called <I>RemoteHost:dbname</I> (TCP syntax)
  56. or <I>\\RemoteHost\dbname</I> (NetBios) <B>Remote</B> provider
  57. detects explicit network protocol syntax and (being the first
  58. provider in the list) at once redirects such call to <I>RemoteHost</I>.
  59. That's how typical client configuration works.</FONT></P>
  60. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>When
  61. database name does not contain network protocol (just <I>dbname</I>)
  62. <B>Remote</B> provider rejects it and <B>Engine14</B> provider comes
  63. to stage. It tries to open <I>dbname</I> &ndash; and in case of
  64. success we get embedded connection to the database. Pay attention &ndash;
  65. we do not need special embedded library to have embedded connection,
  66. standard client loads appropriate provider and becomes embedded
  67. server.</FONT></P>
  68. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>But
  69. what happens if engine returned an error on an attempt to attach to
  70. database? Certainly, if file for database to be attached does not
  71. exist there is no interest at all, but embedded connection may also
  72. be impossible when user, attaching to it, does not have enough rights
  73. to open database file. This is normal case if database was not
  74. created by that user in embedded mode or if he was not explicitly
  75. given OS rights for embedded access to databases on given box.
  76. Moreover, setting access rights in such a manner is a requirement for
  77. correct superserver operation. So after failure of <B>Engine14</B> to
  78. access database <B>Loopback</B> provider is attempted for an attach.
  79. It does not differ much from <B>Remote</B>, but tries to access
  80. database <I>dbname</I> on a server running on local host. On windows
  81. XNET protocol (also known as local connection) is used for it, posix
  82. systems prepend <I>dbname</I> with <I>localhost:</I> and use TCP
  83. connection. In case of success remote-like connection is established
  84. with database no matter that it's located on a local machine.</FONT></P>
  85. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><BR>
  86. </P>
  87. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>Certainly
  88. use of providers is not limited with this 3 standard ones. Firebird 3
  89. does not support pre-ODS 12 databases. But in FB 3 &ndash; not in
  90. alpha1 &ndash; we plan to have additional provider to access old (ODS
  91. from 8 to 11) format databases. Removing old ODS support from engine
  92. helps to make it's code simpler and a bit faster. Taking into an
  93. account that this faster sometimes takes place in performance
  94. critical places (like search of a key in an index block) avoiding old
  95. code and related branches makes Firebird work really faster.
  96. Providers architecture at the same time makes it possible to access
  97. old databases when changing Firebird version.</FONT></P>
  98. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><FONT SIZE=4>The
  99. strong feature of providers architecture is ability for user to add
  100. his own providers to server and/or client. You may be surprised &ndash;
  101. what else except remote connection is needed on client? But do not
  102. forget about providers chaining. Imagine a case when database is
  103. accessed via very slow network connection &ndash; something like 3G
  104. or even worse GPRS. A strong desire to cache rarely changed but
  105. rather big tables on a client is first that comes on my mind to make
  106. it work faster. Such systems were really implemented, but to do it
  107. one had to rename fbclient to something arbitrary and load it into
  108. own library called fbclient. This makes it possible to use standard
  109. tools to access the database at the same time caching required
  110. tables. Works, but solution is obviously far from ideal. With
  111. providers architecture instead libraries renaming one just adds local
  112. caching provider which can use any method to detect connections to it
  113. (something like <I>cache@</I> prefix in the beginning of database
  114. name or whatever else you choose). In this sample when database name
  115. <I>cache@RemoteHost:dbname </I><SPAN STYLE="font-style: normal">is
  116. used caching provider accepts such connection and invokes YValve once
  117. again with traditional database name </SPAN><I>RemoteHost:dbname</I><SPAN STYLE="font-style: normal">.
  118. But when user later performs any call to his database caching
  119. provider gets control on it before </SPAN><SPAN STYLE="font-style: normal"><B>Remote</B></SPAN>
  120. <SPAN STYLE="font-style: normal">one and for locally cached table can
  121. avoid calls to remote server.</SPAN></FONT></P>
  122. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  123. <FONT SIZE=4>Using chaining one can implement a lot of other useful
  124. things like database replication without need in triggers - just
  125. repeat same calls for replication host when (for example) transaction
  126. is commited. In this case chaining provider is installed on server,
  127. not on client, and no modification of command line is needed at all.
  128. To avoid cycling when performing callback to YValve at attach time
  129. such provider can modify list of providers using isc_dpb_config
  130. parameter in DPB &ndash; for details please see README.configuration.
  131. BTW, same technique may be used at client too.</FONT></P>
  132. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  133. <FONT SIZE=4>And certainly we should not forget about ability to
  134. access foreign DB engines using providers. This looks strange at the
  135. first glance when a lot of other tools performing this task already
  136. exist. But let's take into an account ability to access other
  137. Firebird databases using EXECUTE STATEMENT. With provider to ODBC or
  138. other common tool to access various data sources it's getting
  139. possible to directly access from procedures and triggers (using
  140. mentioned EXECUTE STATEMENT) data from almost any database, at least
  141. any, having a driver in chosen access tool. Certainly it's possible
  142. to have a provider to access some particular type of foreign database
  143. engine if one wants to avoid ODBC layer for some reason. </FONT>
  144. </P>
  145. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  146. <FONT SIZE=4>Description of how to access databases using providers
  147. API is present in the interfaces part of Firebird examples and
  148. therefore there is no need repeating it here. Moreover, except
  149. IStatement (interface used for execution of SQL operators) and
  150. IEvents (works with Firebird events) all functions in interfaces are
  151. similar to old API.</FONT></P>
  152. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><BR>
  153. </P>
  154. <P STYLE="margin-bottom: 0in"><FONT SIZE=4>Questions and answers.</FONT></P>
  155. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  156. <FONT SIZE=4>Q. Interfaces and providers are probably very good, but
  157. I have old task written using plain functions API and for a lot of
  158. reasons I can't rewrite it in the nearest future. Does it mean I have
  159. problem migrating to Firebird 3?</FONT></P>
  160. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  161. <FONT SIZE=4>A. Definitely no problems. Old API is supported for
  162. backward compatibility in Firebird 3 and will be supported in future
  163. versions as long as people need it. Moreover, since Firebird 3 one
  164. can access from XSQLDA API records longer than 64Kbytes.</FONT></P>
  165. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  166. <FONT SIZE=4>Q. And what about performance when using old API?</FONT></P>
  167. <P STYLE="text-indent: 0.39in; margin-bottom: 0in; font-style: normal">
  168. <FONT SIZE=4>A. Functional API is implemented as a very thin layer
  169. over interfaces. Code in most case is trivial &ndash; convert passed
  170. handles to pointers to interfaces (this step was always present but
  171. called 'handles validation') and invoke appropriate function from
  172. interface. The only a bit more complex place are functions that
  173. execute SQL operator and fetch data from it. But SQLDA and related to
  174. it data moves has never been the most fast place of functional API,
  175. it was one the reasons to have new API and logic between new and old
  176. API does not add much to that old overhead.</FONT></P>
  177. <P STYLE="text-indent: 0.39in; margin-bottom: 0in"><BR>
  178. </P>
  179. </BODY>
  180. </HTML>