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.

371 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: INDSNAP.CXX
  7. //
  8. // Contents: Array of Indexes
  9. //
  10. // Classes: CIndexSnapshot
  11. //
  12. // History: 28-Apr-92 BartoszM Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <orcursor.hxx>
  18. #include "indsnap.hxx"
  19. #include "partn.hxx"
  20. #include "resman.hxx"
  21. #include "mcursor.hxx"
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Member: CIndexSnapshot::CIndexSnapshot, public
  25. //
  26. // Synopsis: Constructor
  27. //
  28. // Arguments: [resman] -- reference to the resource manager
  29. //
  30. // History: 28-Apr-92 BartoszM Created.
  31. //
  32. //----------------------------------------------------------------------------
  33. CIndexSnapshot::CIndexSnapshot (CResManager& resman)
  34. :_resman(resman), _cInd(0), _apIndex(0), _pFreshTest(0)
  35. {
  36. _resman.ReferenceQuery();
  37. }
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Member: CIndexSnapshot::CIndexSnapshot, public
  41. //
  42. // Synopsis: Copy Constructor
  43. //
  44. // Arguments: [src] -- reference to the src CIndexSnapshot to be copied
  45. //
  46. // History: 28-Apr-92 BartoszM Created.
  47. //
  48. //----------------------------------------------------------------------------
  49. CIndexSnapshot::CIndexSnapshot (CIndexSnapshot& src )
  50. :_resman(src._resman), _cInd(src._cInd), _apIndex(src._apIndex),
  51. _pFreshTest(src._pFreshTest)
  52. {
  53. _resman.ReferenceQuery();
  54. // transfer ownership
  55. src._cInd = 0;
  56. src._apIndex = 0;
  57. src._pFreshTest = 0;
  58. }
  59. //+---------------------------------------------------------------------------
  60. //
  61. // Member: CIndexSnapshot::LokInit, public
  62. //
  63. // Synopsis: Initializes _pFreshTest and _apIndex (one partition)
  64. // Used for merges.
  65. //
  66. // Arguments: [part] -- partition to retrieve array of indexes from
  67. // [mt] -- merge type for retrieving array of indexes
  68. //
  69. // History: 28-Apr-92 BartoszM Created.
  70. //
  71. //----------------------------------------------------------------------------
  72. // ResMan LOCKED
  73. void CIndexSnapshot::LokInit ( CPartition& part, MergeType mt )
  74. {
  75. // initialize fresh test
  76. _pFreshTest = _resman._fresh.LokGetFreshTest();
  77. _apIndex = part.LokQueryMergeIndexes( _cInd, mt );
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Member: CIndexSnapshot::LokInitForBackup
  82. //
  83. // Synopsis: Initializes the _apIndex (one partition) for backing up the
  84. // indexes.
  85. //
  86. // Arguments: [part] - Partition
  87. // [fFull] - Set to TRUE if full backup of indexes is required.
  88. //
  89. // History: 3-18-97 srikants Created
  90. //
  91. //----------------------------------------------------------------------------
  92. void CIndexSnapshot::LokInitForBackup ( CPartition& part, BOOL fFull )
  93. {
  94. // initialize the indexes
  95. _apIndex = part.LokQueryIndexesForBackup( _cInd, fFull );
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Function: LokInitFreshTest
  100. //
  101. // Synopsis: Initializes _pFreshTest by getting the current fresh test
  102. // from resman.
  103. //
  104. // Arguments: (none)
  105. //
  106. // History: 9-29-94 srikants Created
  107. //
  108. // Notes:
  109. //
  110. //----------------------------------------------------------------------------
  111. void CIndexSnapshot::LokInitFreshTest()
  112. {
  113. _pFreshTest = _resman._fresh.LokGetFreshTest();
  114. }
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Member: CIndexSnapshot::Init, public
  118. //
  119. // Synopsis: Initializes _pFreshTest and _apIndex (more than one partition)
  120. // Used for queries.
  121. //
  122. // Arguments: [cPart] -- number of partitions to retrieve indexes from
  123. // [aPartId] -- array of partitions to retrieve indexes from
  124. // [cPendingUpdates] -- Look for this many pending changes
  125. // per partition.
  126. // [pFlags] -- (ret arg) flag for status of indexes
  127. //
  128. // Modifies: pFlags to reflect status of indexes
  129. //
  130. // History: 28-Apr-92 BartoszM Created.
  131. // 08-Sep-92 AmyA Added pFlags
  132. // 18-Nov-94 KyleP Add search for pending changes
  133. //
  134. //----------------------------------------------------------------------------
  135. void CIndexSnapshot::Init ( unsigned cPart,
  136. PARTITIONID* aPartId,
  137. ULONG cPendingUpdates,
  138. ULONG* pFlags )
  139. {
  140. // uses resman lock
  141. _apIndex = _resman.QueryIndexes ( cPart,
  142. aPartId,
  143. &_pFreshTest,
  144. _cInd,
  145. cPendingUpdates,
  146. &_curPending,
  147. pFlags );
  148. }
  149. //+---------------------------------------------------------------------------
  150. //
  151. // Member: CIndexSnapshot::LokRestart, public
  152. //
  153. // Synopsis: Initializes _apIndex (one partition) which constitute
  154. // the master merge set. It does NOT initialize the _pFreshTest
  155. // as _pFreshTest is initialized when the master merge is
  156. // restarted.
  157. //
  158. // Arguments: [part] -- partition to retrieve array of indexes from
  159. // [mMergeLog] -- master merge log, contains list of indexes
  160. // participating i the current master merge
  161. //
  162. // History: 08-Apr-94 DwightKr Created.
  163. //
  164. //----------------------------------------------------------------------------
  165. void CIndexSnapshot::LokRestart ( CPartition& part, PRcovStorageObj & mMergeLog )
  166. {
  167. _apIndex = part.LokQueryMMergeIndexes( _cInd, mMergeLog );
  168. }
  169. //+---------------------------------------------------------------------------
  170. //
  171. // Member: CIndexSnapshot::~CIndexSnapshot, public
  172. //
  173. // Synopsis: Destructor
  174. //
  175. // History: 28-Apr-92 BartoszM Created.
  176. //
  177. //----------------------------------------------------------------------------
  178. CIndexSnapshot::~CIndexSnapshot()
  179. {
  180. // release old indexes and fresh test (takes lock)
  181. _resman.ReleaseIndexes ( _cInd, _apIndex, _pFreshTest );
  182. delete _apIndex;
  183. _resman.DereferenceQuery();
  184. }
  185. //+---------------------------------------------------------------------------
  186. //
  187. // Member: CIndexSnapshot::MaxWorkId, public
  188. //
  189. // Synopsis: Returns the maximum work id for all indexes in snapshot
  190. //
  191. // History: 28-Apr-92 BartoszM Created.
  192. //
  193. //----------------------------------------------------------------------------
  194. WORKID CIndexSnapshot::MaxWorkId()
  195. {
  196. WORKID widMax = _apIndex[0]->MaxWorkId();
  197. for ( unsigned i = 1; i < _cInd; i++ )
  198. if ( _apIndex[i]->MaxWorkId() > widMax )
  199. widMax = _apIndex[i]->MaxWorkId();
  200. return(widMax);
  201. }
  202. //+---------------------------------------------------------------------------
  203. //
  204. // Member: CIndexSnapshot::TotalSizeInPages, public
  205. //
  206. // Synopsis: Returns the size estimate in CI_PAGE's
  207. //
  208. // History: 18-Mar-93 BartoszM Created.
  209. //
  210. //----------------------------------------------------------------------------
  211. unsigned CIndexSnapshot::TotalSizeInPages()
  212. {
  213. unsigned cpage = 0;
  214. for ( unsigned i = 0; i < _cInd; i++ )
  215. cpage += _apIndex[i]->Size();
  216. return cpage;
  217. }
  218. //+---------------------------------------------------------------------------
  219. //
  220. // Member: CIndexSnapshot::QueryMergeCursor, public
  221. //
  222. // Synopsis: Create source cursor for merge
  223. //
  224. // History: 20-Aug-91 BartoszM Created.
  225. // 28-Apr-92 BartoszM Moved from CPersIndex to CIndexSnapshot
  226. //
  227. //----------------------------------------------------------------------------
  228. CKeyCursor * CIndexSnapshot::QueryMergeCursor(const CKey * pKey)
  229. {
  230. XPtr<CKeyCursor> xRawCursor;
  231. if ( 1 == _cInd )
  232. {
  233. if (0 == pKey)
  234. xRawCursor.Set( _apIndex[0]->QueryCursor() );
  235. else
  236. xRawCursor.Set( _apIndex[0]->QueryKeyCursor( pKey ) );
  237. if ( !xRawCursor.IsNull() && xRawCursor->GetKey() == 0 )
  238. xRawCursor.Free();
  239. }
  240. else
  241. {
  242. CKeyCurStack stkCur;
  243. for ( UINT i = 0; i < _cInd; i++ )
  244. {
  245. XPtr<CKeyCursor> xCur;
  246. if (0 == pKey)
  247. xCur.Set( _apIndex[i]->QueryCursor() );
  248. else
  249. xCur.Set( _apIndex[i]->QueryKeyCursor( pKey ) );
  250. if ( !xCur.IsNull() && 0 != xCur->GetKey() )
  251. {
  252. stkCur.Push( xCur.GetPointer() );
  253. xCur.Acquire();
  254. }
  255. }
  256. if ( 0 != stkCur.Count() )
  257. xRawCursor.Set( new CMergeCursor ( stkCur ) );
  258. }
  259. return xRawCursor.Acquire();
  260. } //QueryMergeCursor
  261. //+---------------------------------------------------------------------------
  262. //
  263. // Member: CIndexSnapshot::AppendPendingUpdates, public
  264. //
  265. // Synopsis: Creates a cursor for pending documents
  266. //
  267. // History: 7-Oct-98 dlee Added header; author unknown
  268. //
  269. //----------------------------------------------------------------------------
  270. void CIndexSnapshot::AppendPendingUpdates( XCursor & cur )
  271. {
  272. if ( _curPending.Count() > 0 )
  273. {
  274. if ( !cur.IsNull() )
  275. _curPending.Push( cur.Acquire() );
  276. cur.Set( new COrCursor( _curPending.Count(), _curPending ) );
  277. }
  278. } //AppendPendingUpdates
  279. //+---------------------------------------------------------------------------
  280. //
  281. // Function: LokGiveIndexes
  282. //
  283. // Synopsis: Transfers the control of the array of indexes to the caller.
  284. //
  285. // Effects: _apIndex and _cInd will both be set to 0.
  286. //
  287. // Arguments: [cInd] -- On output, will have the count of the number of
  288. // valid indexes in the returned array of indexes.
  289. //
  290. // Returns: array of indexes which belonged to this snapshot.
  291. //
  292. // History: 9-29-94 srikants Created
  293. //
  294. // Notes:
  295. //
  296. //----------------------------------------------------------------------------
  297. CIndex ** CIndexSnapshot::LokGiveIndexes( unsigned & cInd )
  298. {
  299. cInd = _cInd;
  300. CIndex ** pTemp = _apIndex;
  301. _cInd = 0;
  302. _apIndex = 0;
  303. return( pTemp );
  304. }
  305. //+---------------------------------------------------------------------------
  306. //
  307. // Function: LokTakeIndexes
  308. //
  309. // Synopsis: Takes control of the indexes from the source snapshot.
  310. //
  311. // Arguments: [src] -- Source snapshot.
  312. //
  313. // History: 9-29-94 srikants Created
  314. //
  315. // Notes:
  316. //
  317. //----------------------------------------------------------------------------
  318. void CIndexSnapshot::LokTakeIndexes( CIndexSnapshot & src )
  319. {
  320. Win4Assert( 0 == _apIndex && 0 == _cInd );
  321. _apIndex = src.LokGiveIndexes( _cInd );
  322. }