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.

191 lines
4.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: MERGE.HXX
  7. //
  8. // Contents: Merge object
  9. //
  10. // Classes: CMerge, CMasterMerge
  11. //
  12. // History: 13-Nov-91 BartoszM Created
  13. // 23-Aug-94 SrikantS Split up into CMerge and CMasterMerge.
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include "dindex.hxx"
  18. #include "indsnap.hxx"
  19. #include "keylist.hxx"
  20. class CResManager;
  21. class CPartition;
  22. class CFreshTest;
  23. class PStorage;
  24. class CMasterMergeIndex;
  25. class CDeletedIIDTrans;
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Class: CMerge
  29. //
  30. // Purpose: Encapsulated resources needed for merge of indexes
  31. // This is used for shadow merges. For master merge, use
  32. // CMasterMerge.
  33. //
  34. // History: 13-Nov-91 BartoszM Created.
  35. // 23-Aug-94 SrikantS Split up into CMerge and CMasterMerge.
  36. //
  37. //----------------------------------------------------------------------------
  38. class CMerge
  39. {
  40. public:
  41. //
  42. // These methods do not require locking:
  43. //
  44. CMerge ( CResManager & resman, PARTITIONID partid, MergeType mt );
  45. virtual ~CMerge ();
  46. // Main worker: no lock should be held!
  47. virtual void Do (CCiFrmPerfCounter & mergeProgress);
  48. unsigned LokCountOld() const { return _cIidOld; }
  49. INDEXID* LokGetIidList() { return _aIidOld; }
  50. CDiskIndex* LokGetNewIndex() { return _pIndexNew; }
  51. //
  52. // These methods require LOCKING
  53. //
  54. virtual void LokGrabResources();
  55. virtual void LokRollBack ( unsigned swapped = 0 );
  56. void LokZombify();
  57. void LokAbort();
  58. inline CFreshTest * GetFresh() { return _indSnap.GetFresh(); }
  59. MergeType GetMergeType() { return _mt; }
  60. void ReleaseNewIndex() { _pIndexNew = 0; }
  61. protected:
  62. void LokSetup( BOOL fIsMasterMerge );
  63. PARTITIONID _partid;
  64. CResManager& _resman;
  65. CPartition* _pPart;
  66. INDEXID _iidNew;
  67. WORKID _widNewIndex; // New index, shadow or master
  68. MergeType _mt; // Master vs. shadow merge
  69. // Owned resources:
  70. CIndexSnapshot _indSnap;
  71. CDiskIndex * _pIndexNew;
  72. INDEXID* _aIidOld;
  73. unsigned _cIidOld;
  74. };
  75. //+-------------------------------------------------------------------------
  76. //
  77. // Member: CMerge::LokAbort, public
  78. //
  79. // Synopsis: Abort merge-in-progress
  80. //
  81. // History: 13-Aug-93 KyleP Created
  82. //
  83. //--------------------------------------------------------------------------
  84. inline void CMerge::LokAbort()
  85. {
  86. //
  87. // We know there's an index becuase:
  88. // a) This call is made only after GrabResouces()
  89. // b) Under lock
  90. //
  91. Win4Assert( _pIndexNew );
  92. _pIndexNew->AbortMerge();
  93. }
  94. class CMasterMerge : public CMerge
  95. {
  96. public:
  97. CMasterMerge ( CResManager & resman, PARTITIONID partid )
  98. : CMerge( resman, partid, mtMaster ),
  99. _widCurrentMaster(widInvalid),
  100. _widMasterLog(widInvalid),
  101. _fSoftAbort(0),
  102. _pNewKeyList(0),
  103. _widKeyList(widInvalid)
  104. {
  105. END_CONSTRUCTION( CMasterMerge );
  106. }
  107. ~CMasterMerge();
  108. CWKeyList * LokGetNewKeyList() { return _pNewKeyList; }
  109. void LokReleaseNewKeyList() { _pNewKeyList = 0; }
  110. // Main worker: no lock should be held!
  111. void Do(CCiFrmPerfCounter & mergeProgress);
  112. //
  113. // These methods require LOCKING
  114. //
  115. void LokGrabResources( CDeletedIIDTrans & trans );
  116. void LokRollBack ( unsigned swapped = 0 );
  117. void LokLoadRestartResources();
  118. CMasterMergeIndex * LokGetMasterMergeIndex()
  119. {
  120. return( (CMasterMergeIndex *) _pIndexNew );
  121. }
  122. void LokTakeIndexes( CMasterMergeIndex * pMaster );
  123. private:
  124. CMasterMergeIndex * LokCreateOrFindNewMaster();
  125. void LokStoreRestartResources( CDeletedIIDTrans & delIIDTrans );
  126. WORKID _widCurrentMaster; // Last master on this partition
  127. WORKID _widMasterLog; // Master log for this partition
  128. BOOL _fSoftAbort; // Flag set to TRUE if a soft
  129. // abort must be done.
  130. WORKID _widKeyList; // Keylist for this partition
  131. CWKeyList * _pNewKeyList;
  132. };