Source code of Windows XP (NT5)
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.

258 lines
6.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: INDXACT.CXX
  7. //
  8. // Contents: Index transactions
  9. //
  10. // Classes: CIndexTrans, CChangeTrans
  11. //
  12. // History: 15-Oct-91 BartoszM created
  13. //
  14. // Notes: All operations are done under ResMan LOCK
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <pch.cxx>
  18. #pragma hdrstop
  19. #include <pstore.hxx>
  20. #include "indxact.hxx"
  21. #include "fretest.hxx"
  22. #include "resman.hxx"
  23. #include "changes.hxx"
  24. #include "merge.hxx"
  25. #include "mindex.hxx"
  26. //+-------------------------------------------------------------------------
  27. //
  28. // Method: CIndexTrans::CIndexTrans, public
  29. //
  30. // Synopsis: Start transaction
  31. //
  32. // Arguments: [storage] -- physical storage
  33. // [resman] -- resource manager
  34. //
  35. // History: 15-Oct-91 BartoszM created
  36. //
  37. //--------------------------------------------------------------------------
  38. CIndexTrans::CIndexTrans ( CResManager& resman )
  39. : _resman(resman), _freshTest(0), _fCommit(FALSE)
  40. {
  41. ciDebugOut (( DEB_ITRACE, ">>>> BEGIN index<<<<" ));
  42. }
  43. void CIndexTrans::LokCommit()
  44. {
  45. Win4Assert( !_fCommit );
  46. ciDebugOut (( DEB_ITRACE, ">>>> COMMIT index<<<<" ));
  47. _resman.LokCommitFresh ( _freshTest );
  48. _freshTest = 0;
  49. _fCommit = TRUE;
  50. CTransaction::Commit();
  51. }
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Function: LokCommit
  55. //
  56. // Synopsis: COmmit procedure for a master merge.
  57. //
  58. // Arguments: [storage] -- Storage object
  59. // [widNewFreshLog] -- WorkId of the new fresh log
  60. //
  61. // History: 10-05-94 srikants Created
  62. //
  63. // Notes:
  64. //
  65. //----------------------------------------------------------------------------
  66. void CIndexTrans::LokCommit( PStorage & storage, WORKID widNewFreshLog )
  67. {
  68. Win4Assert( widInvalid != widNewFreshLog );
  69. _resman.LokCommitFresh( _freshTest );
  70. WORKID widOldFreshLog = storage.GetSpecialItObjectId( itFreshLog );
  71. Win4Assert( widInvalid != widOldFreshLog );
  72. storage.RemoveFreshLog( widOldFreshLog );
  73. storage.SetSpecialItObjectId( itFreshLog, widNewFreshLog );
  74. _freshTest = 0;
  75. _fCommit = TRUE;
  76. CTransaction::Commit();
  77. }
  78. //+-------------------------------------------------------------------------
  79. //
  80. // Method: CMergeTrans::CMergeTrans, public
  81. //
  82. // Synopsis: Start transaction
  83. //
  84. // Arguments: [storage] -- physical storage
  85. // [resman] -- resource manager
  86. // [merge] -- merge object
  87. //
  88. // History: 15-Oct-91 BartoszM created
  89. //
  90. //--------------------------------------------------------------------------
  91. CMergeTrans::CMergeTrans ( CResManager & resman,
  92. PStorage& storage,
  93. CMerge& merge )
  94. : CIndexTrans( resman ),
  95. _merge(merge),
  96. _swapped(0),
  97. _fCommit(FALSE),
  98. _storage(storage),
  99. _widNewFreshLog(widInvalid)
  100. {
  101. ciDebugOut (( DEB_ITRACE, ">>>> BEGIN merge trans <<<<" ));
  102. }
  103. //+-------------------------------------------------------------------------
  104. //--------------------------------------------------------------------------
  105. CMergeTrans::~CMergeTrans ()
  106. {
  107. if ( !_fCommit )
  108. {
  109. ciDebugOut (( DEB_ITRACE, ">>>> ABORT merge<<<<" ));
  110. _merge.LokRollBack(_swapped);
  111. if ( widInvalid != _widNewFreshLog )
  112. {
  113. _storage.RemoveFreshLog( _widNewFreshLog );
  114. }
  115. }
  116. }
  117. //+-------------------------------------------------------------------------
  118. //--------------------------------------------------------------------------
  119. void CMergeTrans::LokCommit()
  120. {
  121. Win4Assert( !_fCommit );
  122. ciDebugOut (( DEB_ITRACE, ">>>> COMMIT merge<<<<" ));
  123. _merge.LokZombify(); // old indexes
  124. _fCommit = TRUE;
  125. CIndexTrans::LokCommit( _storage, _widNewFreshLog );
  126. }
  127. IMPLEMENT_UNWIND( CMasterMergeTrans );
  128. //+-------------------------------------------------------------------------
  129. //--------------------------------------------------------------------------
  130. void CMasterMergeTrans::LokCommit()
  131. {
  132. Win4Assert( _pMasterMergeIndex );
  133. //
  134. // Commit the master merge by replacing the master merge index
  135. // with the new index.
  136. //
  137. //
  138. // Transfer the ownership of the MMerge IndexSnapshot to the merge
  139. // object from the master merge index.
  140. //
  141. _masterMerge.LokTakeIndexes( _pMasterMergeIndex );
  142. //
  143. // Replace the CMasterMergeIndex in the partition with the target index
  144. // as the new master in the partition.
  145. //
  146. _pMasterMergeIndex->Zombify();
  147. _resman.LokReplaceMasterIndex( _pMasterMergeIndex );
  148. _mergeTrans.LokCommit();
  149. }
  150. //+-------------------------------------------------------------------------
  151. //
  152. // Method: CChangeTrans::CChangeTrans, public
  153. //
  154. // Synopsis: Start transaction
  155. //
  156. // Arguments: [storage] -- physical storage
  157. // [resman] -- resource manager
  158. //
  159. // History: 15-Oct-91 BartoszM created
  160. //
  161. //--------------------------------------------------------------------------
  162. CChangeTrans::CChangeTrans ( CResManager & resman, CPartition* pPart )
  163. : _pPart(pPart), _resman(resman)
  164. {
  165. }
  166. //+-------------------------------------------------------------------------
  167. //
  168. // Method: CChangeTrans::~CChangeTrans, public
  169. //
  170. // Synopsis: Commit or Abort transaction
  171. //
  172. // History: 15-Oct-91 BartoszM created
  173. // 19-May-94 SrikantS Modified to disable updates in
  174. // case of failures.
  175. // 22-Nov-94 DwightKr Added content scan calls
  176. //
  177. //--------------------------------------------------------------------------
  178. CChangeTrans::~CChangeTrans()
  179. {
  180. if ( GetStatus() != CTransaction::XActCommit )
  181. {
  182. //
  183. // The change log commit failed, requiring either an incremental
  184. // update or a full update. This code is executed when an
  185. // internal corruption is detected or during a low disk situation
  186. // or if a memory allocation failed. Disable updates in changelog.
  187. //
  188. _pPart->LokDisableUpdates();
  189. //
  190. // Tell Resman that a scan is needed.
  191. //
  192. _resman.SetUpdatesLost( _pPart->GetId() );
  193. }
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: CDeletedIIDTrans
  198. //
  199. // Synopsis: ~dtor of the CDeletedIIDTrans. If change to deleted iid is
  200. // logged and the transaction is not committed, it will roll
  201. // back the change to the deleted iid.
  202. //
  203. // History: 7-17-95 srikants Created
  204. //
  205. // Notes:
  206. //
  207. //----------------------------------------------------------------------------
  208. CDeletedIIDTrans::~CDeletedIIDTrans()
  209. {
  210. if ( IsRollBackTrans() )
  211. {
  212. _resman.RollBackDeletedIIDChange( *this );
  213. }
  214. }