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.

253 lines
7.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: PIDXTBL.HXX
  7. //
  8. // Contents: Index Table
  9. //
  10. // Classes: PIndexTable
  11. //
  12. // History: 14-Jul-93 BartoszM Created.
  13. // 07-Feb-94 SrikantS Added ChangeLog and FreshLog support.
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. class PSaveProgressTracker;
  18. enum IndexType
  19. {
  20. itMaster, // master index
  21. itShadow, // shadow index
  22. itZombie, // deleted, but still in use by queries
  23. itDeleted, // special index id for deleted objects
  24. itPartition, // special type for partitions
  25. itChangeLog, // special type for change log
  26. itFreshLog , // special type for fresh log
  27. itPhraseLat, // Special type for phrase lattice object
  28. itKeyList, // special type for the keylist
  29. itMMLog, // Master Merge Log
  30. itNewMaster, // The new master index created during master merge
  31. itMMKeyList // Key list participating in a master merge.
  32. };
  33. //
  34. // Merge set flag. May not overlap with any IndexType
  35. // The old master index, shadow indexes,
  36. // and the old deleted index form a merge set
  37. //
  38. #define itMergeSet 0x8000
  39. #define IDX_TYPE_BITS 0xffff
  40. #define IDX_VERSION_BITS 0xff0000
  41. class PStorage;
  42. class CIndex;
  43. class CPersIndex;
  44. class CTransaction;
  45. class PIndexTabIter;
  46. class CPartInfoList;
  47. class SPartInfoList;
  48. class CPartInfo;
  49. class PRcovStorageObj;
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Class: CIndexRecord
  53. //
  54. // Purpose: Index record in a table
  55. //
  56. // History: 18-Mar-92 AmyA Created.
  57. // 14-Jul-93 Bartoszm Split from idxman.hxx
  58. //
  59. //----------------------------------------------------------------------------
  60. #include <pshpack4.h>
  61. class CIndexRecord
  62. {
  63. public:
  64. INDEXID Iid() const { return _iid; }
  65. ULONG Type() const { return (_type & IDX_TYPE_BITS); }
  66. void SetType( ULONG type ) { _type = type | CURRENT_VERSION_STAMP ; }
  67. ULONG VersionStamp() const { return _type & IDX_VERSION_BITS; }
  68. WORKID ObjectId () const { return _objectId; }
  69. BOOL IsMergeSet() const {
  70. return(_type & itMergeSet);
  71. }
  72. WORKID MaxWorkId() const { return _maxWorkId; }
  73. LONGLONG GetTimeStamp() const { return _timeStamp; }
  74. // USN Usn() const { return _usn; }
  75. public:
  76. WORKID _objectId;
  77. INDEXID _iid;
  78. ULONG _type;
  79. WORKID _maxWorkId;
  80. LONGLONG _timeStamp; // for debugging - tracking update order
  81. LONGLONG _reserved; // for future use - without forcing a
  82. // version change.
  83. };
  84. #include <poppack.h>
  85. const PARTITIONID partidDefault = 1;
  86. const PARTITIONID partidFresh1 = 0xfffd;
  87. const PARTITIONID partidFresh2 = 0xfffc;
  88. class CShadowMergeSwapInfo
  89. {
  90. public:
  91. CIndexRecord _recNewIndex; // Index record of the new index
  92. unsigned _cIndexOld; // Count of the old indexes
  93. INDEXID* _aIidOld; // Array of old iids to be swapped
  94. WORKID _widOldFreshLog; // WorkId of the old fresh log
  95. WORKID _widNewFreshLog; // WorkId of the new fresh log
  96. };
  97. class CMasterMergeSwapInfo
  98. {
  99. public:
  100. CIndexRecord _recNewIndex; // Index record of the new index
  101. unsigned _cIndexOld; // Count of the old indexes
  102. INDEXID* _aIidOld; // Array of old iids to be swapped
  103. WORKID _widOldFreshLog; // WorkId of the old fresh log
  104. WORKID _widNewFreshLog; // WorkId of the new fresh log
  105. PARTITIONID _partid; // Partition Id in which the master
  106. // merge completed.
  107. CIndexRecord _recNewKeyList; // Record for the new key list.
  108. INDEXID _iidOldKeyList; // IndexId of the old key list.
  109. WORKID _widMMLog; // WorkId of the master merge log.
  110. };
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Class: PIndexTable
  114. //
  115. // Purpose: Manages Indexes.
  116. // Contains the table of persistent indexes
  117. // and partitions.
  118. //
  119. // History: 22-Mar-91 BartoszM Created.
  120. // 07-Mar-92 AmyA -> FAT
  121. // 14-Jul-93 Bartoszm Split from idxman.hxx
  122. //
  123. //----------------------------------------------------------------------------
  124. class PIndexTable
  125. {
  126. public:
  127. PIndexTable() : _iidDeleted( iidInvalid ) {}
  128. virtual ~PIndexTable() {}
  129. void AddPartition ( PARTITIONID partid ){ AddObject( partid, itPartition, 0 ); }
  130. CPartInfoList * QueryBootStrapInfo();
  131. virtual void AddMMergeObjects( PARTITIONID partid,
  132. CIndexRecord & recNewMaster,
  133. WORKID widMMLog,
  134. WORKID widMMKeyList,
  135. INDEXID iidDelOld,
  136. INDEXID iidDelNew ) = 0;
  137. virtual void AddObject( PARTITIONID partid, IndexType it, WORKID wid ) = 0;
  138. virtual void DeleteObject( PARTITIONID partid, IndexType it,
  139. WORKID wid ) = 0;
  140. virtual void SwapIndexes ( CShadowMergeSwapInfo & info ) = 0;
  141. virtual void SwapIndexes ( CMasterMergeSwapInfo & info ) = 0;
  142. virtual void RemoveIndex ( INDEXID iid ) = 0;
  143. virtual PIndexTabIter* QueryIterator() = 0;
  144. virtual PStorage& GetStorage() = 0;
  145. virtual void AddIndex( INDEXID iid, IndexType it, WORKID maxWid,
  146. WORKID objId) = 0;
  147. const INDEXID GetDeletedIndex() const { return _iidDeleted; }
  148. void SetDeletedIndex( INDEXID iidDeleted )
  149. {
  150. AddIndex( iidDeleted, itDeleted, 0, widInvalid );
  151. _iidDeleted = iidDeleted;
  152. }
  153. virtual void LokEmpty() = 0;
  154. virtual void LokMakeBackupCopy( PStorage & storage,
  155. BOOL fFullSave,
  156. PSaveProgressTracker & tracker ) = 0;
  157. protected:
  158. INDEXID _iidDeleted;
  159. private:
  160. WORKID CreateAndAddIt( IndexType it, PARTITIONID partId );
  161. CPartInfo * CreateOrGet( SPartInfoList & pList, PARTITIONID partId );
  162. virtual PRcovStorageObj & GetIndexTableObj() = 0;
  163. };
  164. class SIndexTable
  165. {
  166. public:
  167. SIndexTable ( PIndexTable* pIdxTbl ): _pIdxTbl(pIdxTbl)
  168. { END_CONSTRUCTION ( SIndexTable); }
  169. ~SIndexTable () { delete _pIdxTbl; }
  170. PIndexTable* operator->() { return _pIdxTbl; }
  171. PIndexTable& operator * () { return *_pIdxTbl; }
  172. private:
  173. PIndexTable* _pIdxTbl;
  174. };
  175. class PIndexTabIter
  176. {
  177. public:
  178. virtual ~PIndexTabIter() {}
  179. virtual BOOL Begin() = 0;
  180. virtual BOOL NextRecord ( CIndexRecord& record ) = 0;
  181. };
  182. class SIndexTabIter
  183. {
  184. public:
  185. SIndexTabIter( PIndexTabIter * pIdxTabIter ) : _pIdxTabIter(pIdxTabIter)
  186. {
  187. END_CONSTRUCTION( SIndexTabIter );
  188. }
  189. ~SIndexTabIter() { delete _pIdxTabIter; }
  190. PIndexTabIter* operator->() { return _pIdxTabIter; }
  191. PIndexTabIter& operator*() { return *_pIdxTabIter; }
  192. private:
  193. PIndexTabIter * _pIdxTabIter;
  194. };