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.

261 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: PINDEX.HXX
  7. //
  8. // Contents: Persistent Index
  9. //
  10. // Classes: CPersIndex
  11. //
  12. // History: 3-Apr-91 BartoszM Created stub.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "dindex.hxx"
  17. class PStorage;
  18. class CFreshTest;
  19. class PDirectory;
  20. class COccCurStack;
  21. class CRSemiInfinitePage;
  22. class CIndexSnapshot;
  23. class CIndexRecord;
  24. class CWKeyList;
  25. class CKeyList;
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Class: CPersIndex (pi)
  29. //
  30. // Purpose: Encapsulate directory and give access to pages
  31. //
  32. // Interface:
  33. //
  34. // History: 20-Apr-91 KyleP Added Merge method
  35. // 03-Apr-91 BartoszM Created stub.
  36. //
  37. //----------------------------------------------------------------------------
  38. const LONGLONG eSigPersIndex = 0x58444e4953524550i64; // "PERSINDX"
  39. class CPersIndex : public CDiskIndex
  40. {
  41. friend class CMasterMergeIndex;
  42. friend class CMasterMergeIndex;
  43. public:
  44. // new index from scratch
  45. CPersIndex(
  46. PStorage & storage,
  47. WORKID objectId,
  48. INDEXID iid,
  49. unsigned c4KPages,
  50. CDiskIndex::EDiskIndexType idxType
  51. );
  52. CPersIndex(
  53. PStorage & storage,
  54. WORKID objectId,
  55. INDEXID iid,
  56. WORKID widMax,
  57. CDiskIndex::EDiskIndexType idxType,
  58. PStorage::EOpenMode mode,
  59. BOOL fReadDir );
  60. void Remove();
  61. void Merge( CIndexSnapshot& indSnap,
  62. const CPartition & partn,
  63. CCiFrmPerfCounter & mergeProgress,
  64. BOOL fGetRW );
  65. CKeyCursor * QueryCursor();
  66. CKeyCursor * QueryKeyCursor(const CKey * pKey);
  67. //
  68. // From CQueriable
  69. //
  70. COccCursor * QueryCursor( const CKey * pkey,
  71. BOOL isRange,
  72. ULONG & cMaxNodes );
  73. COccCursor * QueryRangeCursor( const CKey * pkey,
  74. const CKey * pkeyEnd,
  75. ULONG & cMaxNodes );
  76. COccCursor * QuerySynCursor( CKeyArray & keyArr,
  77. BOOL isRange,
  78. ULONG & cMaxNodes );
  79. unsigned Size () const;
  80. WORKID ObjectId() const
  81. { return _xPhysIndex->ObjectId(); }
  82. void FillRecord ( CIndexRecord& record );
  83. inline void AbortMerge();
  84. void ClearAbortMerge() { _fAbortMerge = FALSE; }
  85. #ifdef KEYLIST_ENABLED
  86. CRWStore * ComputeRelevantWords(ULONG cRows,ULONG cRW,WORKID *pwid,
  87. CKeyList *pkl);
  88. CRWStore * AcquireRelevantWords();
  89. #endif // KEYLIST_ENABLED
  90. CPhysIndex & GetIndex() { return _xPhysIndex.GetReference(); }
  91. #ifdef CIEXTMODE
  92. void CiExtDump(void *ciExtSelf);
  93. #endif
  94. virtual void MakeBackupCopy( PStorage & storage,
  95. WORKID wid,
  96. PSaveProgressTracker & tracker );
  97. protected:
  98. PDirectory & GetDirectory() { return _xDir.GetReference(); }
  99. SStorageObject & GetObj() { return _obj; }
  100. void CreateRange( COccCurStack & curStk,
  101. const CKey * pkey,
  102. const CKey * pkeyEnd,
  103. ULONG & cMaxNodes );
  104. ULONG ShrinkFromFront( ULONG ulFirstPage, ULONG ulNumPages )
  105. {
  106. if ( _storage.SupportsShrinkFromFront() )
  107. return _xPhysIndex->ShrinkFromFront( ulFirstPage, ulNumPages);
  108. return 0;
  109. }
  110. const LONGLONG _sigPersIndex;
  111. XPtr<PDirectory> _xDir;
  112. XPtr<CPhysIndex> _xPhysIndex;
  113. PStorage & _storage;
  114. SStorageObject _obj;
  115. BOOL _fAbortMerge;
  116. };
  117. //+-------------------------------------------------------------------------
  118. //
  119. // Member: CPersIndex::AbortMerge, public
  120. //
  121. // Synopsis: Sets flag to abort merge in 'reasonably short time'
  122. //
  123. // History: 13-Aug-93 KyleP Created
  124. //
  125. // Notes: Although the _fAbortMerge flag is accessed w/o lock
  126. // from multiple threads there's no contention problem. It's
  127. // a boolean flag and if we miss the set on one pass we'll
  128. // get it on the next.
  129. //
  130. //--------------------------------------------------------------------------
  131. inline void CPersIndex::AbortMerge()
  132. {
  133. _fAbortMerge = TRUE;
  134. }
  135. //+---------------------------------------------------------------------------
  136. //
  137. // Class: CMergeSourceCursor
  138. //
  139. // Purpose: Smart pointer to a merge cursor
  140. //
  141. // History: 29-Aug-92 BartoszM Created
  142. //
  143. //----------------------------------------------------------------------------
  144. class CMergeSourceCursor
  145. {
  146. public:
  147. CMergeSourceCursor ( CIndexSnapshot & indSnap, const CKeyBuf * pKey = 0 );
  148. CMergeSourceCursor ( CKeyCursor * pCurSrc ) : _pCurSrc(pCurSrc) {}
  149. ~CMergeSourceCursor ();
  150. BOOL IsEmpty() const { return 0 == _pCurSrc; }
  151. CKeyCursor* operator->() { return(_pCurSrc); }
  152. CKeyCursor* Acquire()
  153. { CKeyCursor * pTemp = _pCurSrc; _pCurSrc = 0; return pTemp; }
  154. private:
  155. CKeyCursor* _pCurSrc;
  156. };
  157. //+--------------------------------------------------------------------------
  158. //
  159. // Class: CPersIndexCursor
  160. //
  161. // Purpose: Smart pointer to a persistent index key cursor
  162. //
  163. // History: 17-Jun-94 dlee Created
  164. //
  165. //---------------------------------------------------------------------------
  166. class CPersIndexCursor
  167. {
  168. public:
  169. CPersIndexCursor(CPersIndex *pIndex) : _pCursor(0)
  170. {
  171. _pCursor = pIndex->QueryCursor();
  172. }
  173. ~CPersIndexCursor() { delete _pCursor; }
  174. CKeyCursor* operator->() { return(_pCursor); }
  175. private:
  176. CKeyCursor *_pCursor;
  177. };
  178. //+--------------------------------------------------------------------------
  179. //
  180. // Class: CSetReadAhead
  181. //
  182. // Purpose: Sets the hint in the storage object to favor read-ahead
  183. // when appropriate, then revert to the original state.
  184. //
  185. // History: 4-Nov-98 dlee Created
  186. //
  187. //---------------------------------------------------------------------------
  188. class CSetReadAhead
  189. {
  190. public:
  191. CSetReadAhead( PStorage & storage ) :
  192. _storage( storage ),
  193. _fOldValue( storage.FavorReadAhead() )
  194. {
  195. _storage.SetFavorReadAhead( TRUE );
  196. }
  197. ~CSetReadAhead()
  198. {
  199. _storage.SetFavorReadAhead( _fOldValue );
  200. }
  201. private:
  202. PStorage & _storage;
  203. BOOL _fOldValue;
  204. };