Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
7.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: INDXACT.HXX
  7. //
  8. // Contents: Index transactions
  9. //
  10. // Classes: CIndexTrans, CMergeTrans, CChangeTrans
  11. //
  12. // History: 15-Oct-91 BartoszM created
  13. //
  14. // Notes: All these transactions occur under ResManager lock
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma once
  18. #include <xact.hxx>
  19. #include "ci.hxx" // CI_PRIORITIES
  20. class CFreshTest;
  21. class CResManager;
  22. class CPartition;
  23. class CMerge;
  24. class PStorage;
  25. class CPersFresh;
  26. //+-------------------------------------------------------------------------
  27. //
  28. // Class: CIndexTrans
  29. //
  30. // Purpose: Transact fresh list updates from wordlist creation and
  31. // index merges.
  32. //
  33. // Interface:
  34. //
  35. // History: 15-Oct-91 BartoszM created
  36. //
  37. //--------------------------------------------------------------------------
  38. class CIndexTrans: public CTransaction
  39. {
  40. DECLARE_UNWIND
  41. public:
  42. CIndexTrans ( CResManager& resman );
  43. ~CIndexTrans ()
  44. {
  45. if ( !_fCommit )
  46. {
  47. ciDebugOut (( DEB_ITRACE, ">>>> ABORT index<<<<" ));
  48. delete _freshTest;
  49. }
  50. }
  51. void LogFresh( CFreshTest * freshTest )
  52. {
  53. _freshTest = freshTest;
  54. }
  55. void LokCommit();
  56. void LokCommit( PStorage& storage, WORKID widNewFresh );
  57. protected:
  58. CResManager& _resman;
  59. private:
  60. CFreshTest* _freshTest;
  61. BOOL _fCommit;
  62. };
  63. //+-------------------------------------------------------------------------
  64. //
  65. // Class: CMergeTrans
  66. //
  67. // Purpose: Transact merge. Controls marking index(es) for deletion,
  68. // logging of storage changes, update of fresh list.
  69. //
  70. // Interface:
  71. //
  72. // History: 14-Nov-91 BartoszM created
  73. // 24-Jan-94 SrikantS Modified to derive from CIndexTrans
  74. // because the life of a Storage
  75. // transaction is very small.
  76. //
  77. //--------------------------------------------------------------------------
  78. class CMergeTrans: public CIndexTrans
  79. {
  80. DECLARE_UNWIND
  81. public:
  82. CMergeTrans ( CResManager & resman,
  83. PStorage& storage,
  84. CMerge& merge );
  85. ~CMergeTrans ();
  86. void LokCommit();
  87. void LogSwap () { _swapped++; }
  88. void LogNewFreshLog( CFreshTest * freTest, WORKID widNewFreshLog )
  89. {
  90. LogFresh( freTest );
  91. Win4Assert( widInvalid == _widNewFreshLog );
  92. Win4Assert( widInvalid != widNewFreshLog );
  93. _widNewFreshLog = widNewFreshLog;
  94. }
  95. protected:
  96. CMerge& _merge;
  97. unsigned _swapped;
  98. BOOL _fCommit;
  99. PStorage & _storage;
  100. WORKID _widNewFreshLog;
  101. };
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Class: CMasterMergeTrans
  105. //
  106. // Purpose: To abort a master merge transaction if there is a failure
  107. // before the commitment.
  108. //
  109. // A CPersIndex object is pre-allocated for the new master index
  110. // which will replace the CMasterMergeIndex because we do not
  111. // want to fail after we have committed the merge on disk.
  112. // However, if there is a failure before committing the merge,
  113. // the new PersIndex in the CMasterMergeIndex must be freed.
  114. //
  115. // This transaction object frees the new PersIndex if there
  116. // is a failure.
  117. //
  118. // History: 6-28-94 srikants Created
  119. //
  120. // Notes:
  121. //
  122. //----------------------------------------------------------------------------
  123. class CMasterMergeIndex;
  124. class CMasterMergeTrans: INHERIT_UNWIND
  125. {
  126. DECLARE_UNWIND
  127. public:
  128. CMasterMergeTrans( CResManager & resman,
  129. PStorage & storage,
  130. CMergeTrans & mergeTrans,
  131. CMasterMergeIndex * pMasterMergeIndex,
  132. CMasterMerge & masterMerge
  133. ) :
  134. _pMasterMergeIndex( pMasterMergeIndex ),
  135. _resman(resman),
  136. _mergeTrans(mergeTrans),
  137. _masterMerge(masterMerge)
  138. {
  139. Win4Assert( 0 != _pMasterMergeIndex );
  140. END_CONSTRUCTION( CMasterMergeTrans );
  141. }
  142. void LokCommit();
  143. private:
  144. CMasterMergeIndex * _pMasterMergeIndex;
  145. CResManager & _resman;
  146. CMergeTrans & _mergeTrans;
  147. CMasterMerge & _masterMerge;
  148. };
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Class: CChangeTrans
  152. //
  153. // Purpose: Supplement table transaction with Changes transactions
  154. //
  155. // Interface:
  156. //
  157. // History: 15-Oct-91 BartoszM created
  158. //
  159. //--------------------------------------------------------------------------
  160. class CChangeTrans: public CTransaction
  161. {
  162. DECLARE_UNWIND
  163. public:
  164. CChangeTrans ( CResManager & resman, CPartition* pPart );
  165. ~CChangeTrans ();
  166. void LokCommit() { CTransaction::Commit(); }
  167. private:
  168. CPartition * _pPart;
  169. CResManager & _resman;
  170. };
  171. //+---------------------------------------------------------------------------
  172. //
  173. // Class: CDeletedIIDTrans
  174. //
  175. // Purpose: A transaction to protect the change of the deleted iid during
  176. // a MasterMerge. When a new MasterMerge is started, we have to
  177. // start using a different deleted IID for all entries created
  178. // during the merge. This includes those created during the
  179. // initial ShadowMerge at the beginning of the MasterMerge.
  180. //
  181. // However, if there is a failure from the time the ShadowMerge
  182. // is started and before the master merge is committed, we have
  183. // to rollback the change to the deleted IID.
  184. //
  185. // This transaction object provides that functionality.
  186. //
  187. // History: 7-17-95 srikants Created
  188. //
  189. // Notes:
  190. //
  191. //----------------------------------------------------------------------------
  192. class CDeletedIIDTrans: public CTransaction
  193. {
  194. INLINE_UNWIND( CDeletedIIDTrans )
  195. public:
  196. CDeletedIIDTrans( CResManager & resman )
  197. : _resman(resman),
  198. _iidDelOld(iidInvalid),
  199. _iidDelNew(iidInvalid),
  200. _fTransLogged(FALSE)
  201. {
  202. END_CONSTRUCTION( CDeletedIIDTrans );
  203. }
  204. ~CDeletedIIDTrans();
  205. void LokLogNewDeletedIid( INDEXID iidDelOld, INDEXID iidDelNew )
  206. {
  207. Win4Assert( !_fTransLogged );
  208. Win4Assert( iidDeleted1 == iidDelOld && iidDeleted2 == iidDelNew ||
  209. iidDeleted2 == iidDelOld && iidDeleted1 == iidDelNew );
  210. _fTransLogged = TRUE;
  211. _iidDelOld = iidDelOld;
  212. _iidDelNew = iidDelNew;
  213. }
  214. INDEXID GetOldDelIID() const { return _iidDelOld; }
  215. INDEXID GetNewDelIID() const { return _iidDelNew; }
  216. BOOL IsTransLogged() const
  217. {
  218. return _fTransLogged;
  219. }
  220. BOOL IsRollBackTrans()
  221. {
  222. return GetStatus() != CTransaction::XActCommit && _fTransLogged;
  223. }
  224. private:
  225. CResManager & _resman;
  226. INDEXID _iidDelOld;
  227. INDEXID _iidDelNew;
  228. BOOL _fTransLogged;
  229. };