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.

415 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: PARTN.HXX
  7. //
  8. // Contents: Content Index Partition
  9. //
  10. // Classes: CPartition
  11. //
  12. // History: 22-Mar-91 BartoszM Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CPartition (part)
  19. //
  20. // Purpose: To partition the content index into manageable pieces
  21. //
  22. // History: 22-Mar-91 BartoszM Created.
  23. //
  24. //----------------------------------------------------------------------------
  25. #include <prcstob.hxx>
  26. #include <rwex.hxx>
  27. #include <doclist.hxx>
  28. #include "idxlst.hxx"
  29. #include "set.hxx"
  30. #include "merge.hxx"
  31. #include "changes.hxx"
  32. class CIndexId;
  33. class CContentIndex;
  34. class CCursor;
  35. class CKey;
  36. class CQParse;
  37. class CTransaction;
  38. class CMergeTrans;
  39. class PStorage;
  40. class CFresh;
  41. class CChangeTrans;
  42. class CResManager;
  43. class CPersIndex;
  44. class CIndexSnapshot;
  45. class CNotificationTransaction;
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Class: CPartition
  49. //
  50. // Purpose: Encapsulates information in a partition
  51. //
  52. // History: 21-Nov-94 DwightKr Added this header
  53. //
  54. //----------------------------------------------------------------------------
  55. const LONGLONG eSigPartition = 0x4e4f495454524150i64; // "PARTTION"
  56. class CPartition
  57. {
  58. public:
  59. CPartition ( WORKID wid, PARTITIONID partID,
  60. PStorage& storage, CCiFrameworkParams & frmwrkParams );
  61. ~CPartition ();
  62. // Methods involving _changes
  63. void LokEmpty();
  64. NTSTATUS LokDismount( CChangeTrans & xact )
  65. {
  66. return _changes.LokDismount( xact );
  67. }
  68. unsigned LokCountUpdates() const { return _changes.LokCount(); }
  69. unsigned LokCountSecUpdates() const { return _changes.LokCountSec(); }
  70. void LokQueryPendingUpdates (
  71. CChangeTrans & xact,
  72. unsigned max,
  73. CDocList& docList )
  74. {
  75. _changes.LokQueryPendingUpdates( xact, max, docList );
  76. }
  77. BOOL LokGetPendingUpdates( WORKID * aWid, unsigned & cWid )
  78. {
  79. return( _changes.LokGetPendingUpdates( aWid, cWid ) );
  80. }
  81. void LokRefileDocs( const CDocList & docList )
  82. {
  83. _changes.LokRefileDocs( docList );
  84. }
  85. void LokAppendRefiledDocs( CChangeTrans & xact )
  86. {
  87. _changes.LokAppendRefiledDocs( xact );
  88. }
  89. SCODE LokUpdateDocument( CChangeTrans & xact,
  90. WORKID wid,
  91. USN usn,
  92. VOLUMEID volumeId,
  93. ULONG flags,
  94. ULONG retries,
  95. ULONG cSecQRetries )
  96. {
  97. return _changes.LokUpdateDocument ( xact, wid, usn, volumeId, flags, retries, cSecQRetries );
  98. }
  99. void LokFlushUpdates()
  100. {
  101. _changes.LokFlushUpdates();
  102. }
  103. void LokAddToSecQueue( CChangeTrans & xact, WORKID wid, VOLUMEID volumeId, ULONG cSecQRetries )
  104. {
  105. _changes.LokAddToSecQueue( xact, wid, volumeId, cSecQRetries );
  106. }
  107. void LokRefileSecQueue( CChangeTrans & xact )
  108. {
  109. _changes.LokRefileSecQueue( xact );
  110. }
  111. void LokDisableUpdates()
  112. {
  113. _changes.LokDisableUpdates();
  114. }
  115. void LokEnableUpdates( BOOL fFirstTimeUpdatesAreEnabled )
  116. {
  117. _changes.LokEnableUpdates( fFirstTimeUpdatesAreEnabled );
  118. }
  119. // log creation of new wordlist
  120. void LokDone ( CChangeTrans & xact,
  121. INDEXID iid,
  122. CDocList& docList )
  123. {
  124. _changes.LokDone ( xact, iid , docList );
  125. }
  126. void LokCompact() { _changes.LokCompact(); }
  127. // methods involving indexes
  128. unsigned LokIndexCount() const;
  129. unsigned WordListCount() const;
  130. unsigned LokIndexSize() const;
  131. unsigned LokGetIndexes ( CIndex** apIndex );
  132. PARTITIONID GetId() const;
  133. INDEXID LokMakeWlstId ();
  134. INDEXID LokMakePersId ();
  135. void RegisterId ( CIndexId iid );
  136. void FreeIndexId ( CIndexId iid );
  137. void AddIndex ( CIndex* ind );
  138. CIndex* LokRemoveIndex ( INDEXID iid );
  139. BOOL LokIsPersIndexValid( CIndexId iid ) const
  140. {
  141. Win4Assert( iid.IsPersistent() );
  142. return( !_setPersIid.Contains( iid.PersId() ) );
  143. }
  144. void Swap (
  145. CMergeTrans& xact,
  146. CIndex * new_index,
  147. unsigned cInd,
  148. INDEXID old_indexes[] );
  149. CIndex** LokQueryMergeIndexes ( unsigned & count, MergeType mt );
  150. CIndex** LokQueryIndexesForBackup ( unsigned & count, BOOL fFull );
  151. BOOL LokCheckMerge(MergeType mt);
  152. BOOL LokCheckLowMemoryMerge() { return (WordListCount() > 0); }
  153. BOOL LokCheckWordlistMerge();
  154. void LokDeleteWIDsInPersistentIndexes( CChangeTrans & xact,
  155. CFreshTest & freshTestLatest,
  156. CFreshTest & freshTestAtMerge,
  157. CDocList & docList,
  158. CNotificationTransaction & notifTrans )
  159. {
  160. _changes.LokDeleteWIDsInPersistentIndexes( xact,
  161. freshTestLatest,
  162. freshTestAtMerge,
  163. docList,
  164. notifTrans );
  165. }
  166. void SetMMergeObjectIds( WORKID widMasterLog,
  167. WORKID widNewMaster,
  168. WORKID widCurrentMaster
  169. )
  170. {
  171. _widMasterLog = widMasterLog;
  172. _widNewMaster = widNewMaster;
  173. _widCurrentMaster = widCurrentMaster;
  174. }
  175. void GetMMergeObjectIds( WORKID & widMasterLog,
  176. WORKID & widNewMaster,
  177. WORKID & widCurrentMaster
  178. )
  179. {
  180. widMasterLog = _widMasterLog;
  181. widNewMaster = _widNewMaster;
  182. widCurrentMaster = _widCurrentMaster;
  183. }
  184. WORKID GetChangeLogObjectId()
  185. {
  186. return _widChangeLog;
  187. }
  188. BOOL InMasterMerge() { return _widMasterLog != widInvalid; }
  189. CIndex** LokQueryMMergeIndexes ( unsigned & count,
  190. PRcovStorageObj & objMMLog );
  191. void SerializeMMergeIndexes( unsigned count,
  192. const CIndex * aIndexes[], PRcovStorageObj & objMMLog );
  193. CPersIndex * CPartition::GetCurrentMasterIndex();
  194. void SetOldMasterIndex(CPersIndex *pIndex)
  195. { _pOldMasterIndex = pIndex; }
  196. CPersIndex * CPartition::GetOldMasterIndex() { return _pOldMasterIndex; }
  197. void SetNewMasterIid( INDEXID iid) { _iidNewMasterIndex = iid; }
  198. INDEXID GetNewMasterIid() { return _iidNewMasterIndex; }
  199. void TakeMMergeIndSnap( CIndexSnapshot * pMMergeIndSnap )
  200. {
  201. Win4Assert( 0 == _pMMergeIndSnap );
  202. _pMMergeIndSnap = pMMergeIndSnap;
  203. }
  204. CIndexSnapshot * GetMMergeIndSnap() { return _pMMergeIndSnap; }
  205. CIndexSnapshot * AcquireMMergeIndSnap()
  206. {
  207. CIndexSnapshot * pTemp = _pMMergeIndSnap;
  208. _pMMergeIndSnap = 0;
  209. return(pTemp);
  210. }
  211. CRWStore * RetrieveRelevantWords(BOOL fAcquire)
  212. {
  213. CRWStore *p = _pRWStore;
  214. if (fAcquire)
  215. _pRWStore = 0;
  216. return p;
  217. }
  218. void SetRelevantWords(CRWStore *pRWStore)
  219. { delete _pRWStore; _pRWStore = pRWStore; }
  220. CIndex ** LokZombify(unsigned & cInd);
  221. void LokEmptyChangeLog()
  222. {
  223. _changes.LokEmpty();
  224. }
  225. void SetResMan( CResManager * pResMan, BOOL fPushFiltering )
  226. {
  227. _changes.SetResMan( pResMan, fPushFiltering );
  228. }
  229. //
  230. // Lok not necessary for setting and checking the cleaning up
  231. // status.
  232. //
  233. void PrepareForCleanup() { _fCleaningUp = TRUE; }
  234. BOOL IsCleaningUp() const { return _fCleaningUp; }
  235. #ifdef CIEXTMODE
  236. void CiExtDump(void *ciExtSelf);
  237. #endif
  238. private:
  239. #if CIDBG==1
  240. CIndex * LokGetIndex( CIndexId iid );
  241. #endif // CIDBG==1
  242. const LONGLONG _sigPartition;
  243. CSet _setPersIid;
  244. ULONG _wlid;
  245. CCiFrameworkParams & _frmwrkParams;
  246. PARTITIONID _id;
  247. ULONG _queryCount;
  248. CChange _changes; // log of pending changes
  249. CIndexList _idxlst;
  250. WORKID _widMasterLog;
  251. WORKID _widNewMaster;
  252. WORKID _widCurrentMaster;
  253. WORKID _widChangeLog;
  254. INDEXID _iidNewMasterIndex;
  255. CPersIndex * _pOldMasterIndex;
  256. CRWStore * _pRWStore;
  257. CIndexSnapshot * _pMMergeIndSnap; // Snap-shot belonging to an
  258. // on going master merge (if any)
  259. PStorage & _storage;
  260. BOOL _fCleaningUp; // Flag set to true if we are
  261. // cleaning up for a shutdown or
  262. // dimsount. One way flag. Once
  263. // turned on, it will not be turned
  264. // off.
  265. };
  266. //+---------------------------------------------------------------------------
  267. //
  268. // Member: CPartition::LokIndexCount, public
  269. //
  270. // History: 08-Oct-91 BartoszM Created.
  271. //
  272. //----------------------------------------------------------------------------
  273. inline unsigned CPartition::LokIndexCount() const
  274. {
  275. return _idxlst.Count();
  276. }
  277. //+---------------------------------------------------------------------------
  278. //
  279. // Member: CPartition::WordListCount, public
  280. //
  281. // History: 10-May-93 AmyA Created.
  282. //
  283. //----------------------------------------------------------------------------
  284. inline unsigned CPartition::WordListCount() const
  285. {
  286. return _idxlst.CountWlist();
  287. }
  288. //+---------------------------------------------------------------------------
  289. //
  290. // Member: CPartition::LokIndexSize, public
  291. //
  292. // History: 15-Apr-94 t-joshh Created.
  293. //
  294. //----------------------------------------------------------------------------
  295. inline unsigned CPartition::LokIndexSize() const
  296. {
  297. return _idxlst.IndexSize();
  298. }
  299. //+---------------------------------------------------------------------------
  300. //
  301. // Member: CPartition::GetId, public
  302. //
  303. // History: 08-Oct-91 BartoszM Created.
  304. //
  305. //----------------------------------------------------------------------------
  306. inline PARTITIONID CPartition::GetId() const
  307. {
  308. return _id;
  309. }
  310. //+---------------------------------------------------------------------------
  311. //
  312. // Member: CPartition::LokRemoveIndex, public
  313. //
  314. // Arguments: [iid] -- index id
  315. //
  316. // History: 13-Nov-91 BartoszM Created.
  317. //
  318. //----------------------------------------------------------------------------
  319. inline CIndex* CPartition::LokRemoveIndex( INDEXID iid )
  320. {
  321. return _idxlst.Remove(iid);
  322. }