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.

370 lines
9.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: IDXTAB.HXX
  7. //
  8. // Contents: Index Manager
  9. //
  10. // Classes: CIndexTable
  11. //
  12. // History: 22-Mar-91 BartoszM Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <pidxtbl.hxx>
  17. #include <rcstxact.hxx>
  18. #include <rcstrmit.hxx>
  19. #include <cistore.hxx>
  20. class CiStorage;
  21. class CIndex;
  22. class CPersIndex;
  23. class CTransaction;
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Class: CIndexFile
  27. //
  28. // Purpose: A file of index records
  29. //
  30. // History: 01-jul-93 BartoszM Created.
  31. // 03-mar-94 DwightKr Changed to user persistent streams
  32. //
  33. //----------------------------------------------------------------------------
  34. class CIndexFile
  35. {
  36. public:
  37. virtual ~CIndexFile(){}
  38. virtual void Rewind() = 0;
  39. virtual void BackUp() = 0;
  40. virtual BOOL ReadRecord(CIndexRecord* pRecord) = 0;
  41. };
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Class: CIndexTableUsrHdr
  45. //
  46. // Purpose: User specific header in the index table. This will track the
  47. // master merge sequence number.
  48. //
  49. // History: 3-19-97 srikants Created
  50. //
  51. //----------------------------------------------------------------------------
  52. class CIndexTableUsrHdr
  53. {
  54. public:
  55. CIndexTableUsrHdr();
  56. unsigned GetMMergeSeqNum() const { return _iMMergeSeqNum; }
  57. void IncrMMergeSeqNum()
  58. {
  59. _iMMergeSeqNum++;
  60. }
  61. BOOL IsFullSave() const { return _fFullSave; }
  62. void SetFullSave() { _fFullSave = TRUE; }
  63. void ClearFullSave() { _fFullSave = FALSE; }
  64. private:
  65. unsigned _iReserved;
  66. //
  67. // Master Merge sequence number. This has the number of times
  68. // a master merge has been performed in this catalog.
  69. //
  70. unsigned _iMMergeSeqNum;
  71. //
  72. // This field is used when the index table is transpored. At the
  73. // destination, it will be used to ensure that for an incremental
  74. // load, the master merge sequence numbers are same.
  75. //
  76. BOOL _fFullSave;
  77. };
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Class: CWriteIndexFile
  81. //
  82. // Purpose: A file of index records
  83. //
  84. // History: 01-jul-93 BartoszM Created.
  85. // 03-mar-94 DwightKr Changed to user persistent streams
  86. //
  87. //----------------------------------------------------------------------------
  88. class CWriteIndexFile : INHERIT_VIRTUAL_UNWIND, public CIndexFile
  89. {
  90. DECLARE_UNWIND
  91. public:
  92. CWriteIndexFile ( PRcovStorageObj & rcovObj );
  93. virtual ~CWriteIndexFile() {}
  94. void Rewind() { _xact.Seek(0); _xactPtr = 0; }
  95. void BackUp();
  96. BOOL ReadRecord ( CIndexRecord* pRecord );
  97. void WriteRecord ( CIndexRecord* pRecord );
  98. void Commit() { _xact.Commit(); }
  99. ULONG GetStorageVersion() { return _rcovObj.GetVersion(); }
  100. void IncrMMergeSeqNum();
  101. private:
  102. PRcovStorageObj & _rcovObj;
  103. CRcovStrmWriteTrans _xact;
  104. CRcovStrmWriteIter _iter;
  105. ULONG _xactPtr;
  106. };
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Class: CReadIndexFile
  110. //
  111. // Purpose: A file of index records
  112. //
  113. // History: 01-jul-93 BartoszM Created.
  114. // 03-mar-94 DwightKr Changed to user persistent streams
  115. //
  116. //----------------------------------------------------------------------------
  117. class CReadIndexFile : INHERIT_VIRTUAL_UNWIND, public CIndexFile
  118. {
  119. DECLARE_UNWIND
  120. public:
  121. CReadIndexFile ( PRcovStorageObj & rcovObj );
  122. virtual ~CReadIndexFile() {}
  123. void Rewind() { _xact.Seek(0); _xactPtr = 0; }
  124. void BackUp();
  125. BOOL ReadRecord ( CIndexRecord* pRecord );
  126. private:
  127. PRcovStorageObj & _rcovObj;
  128. CRcovStrmReadTrans _xact;
  129. CRcovStrmReadIter _iter;
  130. ULONG _xactPtr;
  131. };
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Class: CNextIndexRecord
  135. //
  136. // Purpose: Reads in records from file. Only contains
  137. // non-empty records (determined by INDEXID)-- doesn't contain
  138. // anything useful if Found() returns false.
  139. //
  140. // History: 16-Mar-92 AmyA Created.
  141. //
  142. //----------------------------------------------------------------------------
  143. class CNextIndexRecord: public CIndexRecord
  144. {
  145. public:
  146. inline CNextIndexRecord( CIndexFile & indFile );
  147. inline BOOL Found() { return _found; }
  148. private:
  149. BOOL _found;
  150. };
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Member: CNextIndexRecord::CNextIndexRecord, public
  154. //
  155. // Synopsis: Reads IndexRecords in from the file indicated by indFile in a loop,
  156. // stopping when either a non-empty record or EOF are reached.
  157. //
  158. // Notes: Whether or not a non-empty record was found can be determined
  159. // by a call to Found().
  160. //
  161. // History: 16-Mar-92 AmyA Created.
  162. //
  163. //----------------------------------------------------------------------------
  164. inline CNextIndexRecord::CNextIndexRecord( CIndexFile & indFile )
  165. {
  166. INDEXID iidNotValid = CIndexId( iidInvalid, partidInvalid );
  167. do
  168. {
  169. _found = indFile.ReadRecord( this );
  170. } while ( _found && ( Iid() == iidNotValid || Iid() == iidInvalid ) );
  171. }
  172. //+---------------------------------------------------------------------------
  173. //
  174. // Class: CAddReplaceIndexRecord
  175. //
  176. // Purpose: Reads and writes records from file. Only contains
  177. // a useful record if Found() returns true.
  178. //
  179. // History: 16-Mar-92 AmyA Created.
  180. // 29-Feb-95 DwightKr Created WriteRecord() method,
  181. // and moved code from destructor there,
  182. // since the destructor chould THROW().
  183. // Also changed name to reflect what this
  184. // class really does.
  185. //
  186. //----------------------------------------------------------------------------
  187. class CAddReplaceIndexRecord : public CIndexRecord
  188. {
  189. public:
  190. CAddReplaceIndexRecord( CWriteIndexFile & indFile, INDEXID iid );
  191. void SetIid( INDEXID iid ) { _iid = iid; }
  192. void SetType( ULONG type ) { _type = type | _indFile.GetStorageVersion(); }
  193. void SetWid( WORKID maxWorkId ) { _maxWorkId = maxWorkId; }
  194. void SetObjectId ( WORKID objectId )
  195. {
  196. _objectId = objectId;
  197. }
  198. inline BOOL Found() { return _found; }
  199. void WriteRecord();
  200. private:
  201. BOOL _found;
  202. CWriteIndexFile & _indFile;
  203. };
  204. //+---------------------------------------------------------------------------
  205. //
  206. // Class: CIndexTable
  207. //
  208. // Purpose: Manages Indexes.
  209. // Contains the table of persistent indexes
  210. // and partitions.
  211. //
  212. // History: 22-Mar-91 BartoszM Created.
  213. // 07-Mar-92 AmyA -> FAT
  214. //
  215. //----------------------------------------------------------------------------
  216. class CIndexTable : public PIndexTable
  217. {
  218. friend class CIndexTabIter;
  219. public:
  220. CIndexTable ( CiStorage& storage, CTransaction& xact );
  221. ~CIndexTable();
  222. void AddObject( PARTITIONID partid, IndexType it, WORKID wid );
  223. void AddMMergeObjects( PARTITIONID partid,
  224. CIndexRecord & recNewMaster,
  225. WORKID widMMLog,
  226. WORKID widMMKeyList,
  227. INDEXID iidDelOld,
  228. INDEXID iidDelNew );
  229. void DeleteObject( PARTITIONID partid, IndexType it, WORKID wid );
  230. virtual void SwapIndexes ( CShadowMergeSwapInfo & info );
  231. virtual void SwapIndexes ( CMasterMergeSwapInfo & info );
  232. PIndexTabIter* QueryIterator();
  233. PStorage& GetStorage();
  234. void RemoveIndex ( INDEXID iid );
  235. void AddIndex( INDEXID iid, IndexType it, WORKID maxWid, WORKID objId);
  236. void LokEmpty();
  237. virtual void LokMakeBackupCopy( PStorage & storage,
  238. BOOL fFullSave,
  239. PSaveProgressTracker & tracker );
  240. void GetUserHdrInfo( unsigned & mMergeSeqNum, BOOL & fFullSave );
  241. private:
  242. void AddRecord( CWriteIndexFile & indFile,
  243. INDEXID iid,
  244. ULONG type,
  245. WORKID maxWorkId,
  246. WORKID objectId );
  247. void DeleteRecord ( CWriteIndexFile & indFile, INDEXID iid );
  248. void DeleteObject ( CWriteIndexFile & indFile, PARTITIONID partid,
  249. IndexType it, WORKID wid );
  250. PRcovStorageObj & GetIndexTableObj()
  251. {
  252. return *_pRcovObj;
  253. }
  254. CiStorage& _storage;
  255. PRcovStorageObj * _pRcovObj;
  256. };
  257. //
  258. // This has to be an unwindable object it has CReadIndexFile
  259. // as an embedded object which is unwindable.
  260. //
  261. class CIndexTabIter: public PIndexTabIter
  262. {
  263. public:
  264. CIndexTabIter ( CIndexTable& idxTable );
  265. virtual ~CIndexTabIter();
  266. BOOL Begin();
  267. BOOL NextRecord ( CIndexRecord& record );
  268. private:
  269. PStorage & GetStorage() { return _idxTable._storage; }
  270. CIndexTable& _idxTable;
  271. CReadIndexFile _indFile;
  272. };
  273. //+---------------------------------------------------------------------------
  274. //
  275. // Member: CIndexTable::DeleteRecord, private
  276. //
  277. // Synopsis: Marks current record as deleted
  278. //
  279. // History: 12-Mar-92 AmyA Created.
  280. //
  281. //----------------------------------------------------------------------------
  282. inline void CIndexTable::DeleteRecord ( CWriteIndexFile & indFile, INDEXID iid )
  283. {
  284. CAddReplaceIndexRecord rec( indFile, iid );
  285. if ( rec.Found() )
  286. {
  287. rec.SetIid( CIndexId(iidInvalid, partidInvalid) );
  288. rec.WriteRecord();
  289. }
  290. }