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.

883 lines
24 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: RESMAN.HXX
  7. //
  8. // Contents: Resource Manager
  9. //
  10. // Classes: CResManager
  11. //
  12. // History: 4-Apr-91 BartoszM Created.
  13. // 4-Jan-95 BartoszM Separated Filter Manager
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Class: CResManager
  20. //
  21. // Purpose: Manages resources (threads, memory, disk)
  22. //
  23. // Interface: CResManager
  24. //
  25. // History: 4-Apr-91 BartoszM Created
  26. //
  27. //----------------------------------------------------------------------------
  28. #include <pidxtbl.hxx>
  29. #include <lang.hxx>
  30. #include <ciintf.h>
  31. #include <frmutils.hxx>
  32. #include <workman.hxx>
  33. #include <idxnotif.hxx>
  34. #include "cibackup.hxx"
  35. #include "flushnot.hxx"
  36. #include "afwwork.hxx"
  37. #include "abortwid.hxx"
  38. #include "fresh.hxx"
  39. #include "partlst.hxx"
  40. #include "index.hxx"
  41. #include "merge.hxx"
  42. #include "wordlist.hxx"
  43. #include "keylist.hxx"
  44. #include "pqueue.hxx"
  45. #include "rmstate.hxx"
  46. class CContentIndex;
  47. class CPartition;
  48. class CDocList;
  49. class CEntryBuffer;
  50. class CPersIndex;
  51. class CMasterMergeIndex;
  52. class CGetFilterDocsState;
  53. class CFilterAgent;
  54. class PStorage;
  55. class CPidMapper;
  56. class CSimplePidRemapper;
  57. class CResManager;
  58. class PSaveProgressTracker;
  59. BOOL LokCheckIfDiskLow( CResManager & resman,
  60. PStorage & storage,
  61. BOOL fIsCurrentFull,
  62. ICiCAdviseStatus & adviseStatus );
  63. typedef CDynStackInPlace<PARTITIONID> CPartIdStack;
  64. const LONGLONG eSigResman = 0x20204e414d534552i64; // "RESMAN"
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Class: CMergeThreadKiller
  68. //
  69. // Purpose: An object to kill the merge thread should the constructor of
  70. // CResManager fail.
  71. //
  72. // History: 3-06-95 srikants Created
  73. //
  74. // Notes:
  75. //
  76. //----------------------------------------------------------------------------
  77. class CMergeThreadKiller
  78. {
  79. public:
  80. CMergeThreadKiller( CResManager & resman );
  81. ~CMergeThreadKiller();
  82. void Defuse()
  83. {
  84. _fKill = FALSE;
  85. }
  86. private:
  87. CResManager & _resman;
  88. BOOL _fKill; // If set to TRUE, the merge thread must be
  89. // killed by this object.
  90. };
  91. class CDeletedIIDTrans;
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Class: CWorkIdToDocName
  95. //
  96. // Purpose: Converts a objectId (workId) to its corresponding docname
  97. //
  98. // History: 20-Oct-94 DwightKr Created
  99. // 22-Jan-97 SrikantS Changed to generating un-interpreted
  100. // BYTES for framework support.
  101. //
  102. //----------------------------------------------------------------------------
  103. class CWorkIdToDocName
  104. {
  105. public:
  106. CWorkIdToDocName( ICiCDocNameToWorkidTranslator * pITranslator,
  107. ICiCDocNameToWorkidTranslatorEx * pITranslator2 )
  108. {
  109. Win4Assert( 0 != pITranslator );
  110. ICiCDocName * pIDocName = 0;
  111. SCODE sc = pITranslator->QueryDocName( &pIDocName );
  112. if ( S_OK != sc )
  113. THROW( CException( sc ) );
  114. _docName.Set( pIDocName );
  115. pITranslator->AddRef();
  116. _translator.Set( pITranslator );
  117. if ( 0 != pITranslator2 )
  118. {
  119. pITranslator2->AddRef();
  120. _translator2.Set( pITranslator2 );
  121. }
  122. }
  123. const BYTE * GetDocName( WORKID objectId, ULONG & cbDocName, BOOL fAccurate )
  124. {
  125. _docName->Clear();
  126. BYTE const * pbBuffer = 0;
  127. cbDocName = 0;
  128. SCODE sc;
  129. if ( fAccurate && !_translator2.IsNull() )
  130. {
  131. sc = _translator2->WorkIdToAccurateDocName( objectId,
  132. _docName.GetPointer() );
  133. }
  134. else
  135. sc = _translator->WorkIdToDocName( objectId,
  136. _docName.GetPointer() );
  137. if ( S_OK == sc )
  138. {
  139. sc = _docName->GetNameBuffer( &pbBuffer, &cbDocName );
  140. Win4Assert( S_OK == sc );
  141. }
  142. return pbBuffer;
  143. }
  144. private:
  145. XInterface<ICiCDocNameToWorkidTranslator> _translator;
  146. XInterface<ICiCDocNameToWorkidTranslatorEx> _translator2;
  147. XInterface<ICiCDocName> _docName;
  148. };
  149. //+---------------------------------------------------------------------------
  150. //
  151. // Class: CResManager
  152. //
  153. // History: 08-Apr-91 BartoszM Created
  154. //
  155. //----------------------------------------------------------------------------
  156. class CResManager
  157. {
  158. friend class CFilterManager;
  159. friend class CFilterAgent;
  160. friend class CMerge;
  161. friend class CMasterMerge;
  162. friend class CIndexSnapshot;
  163. friend class CReleaseMMergeIndex;
  164. friend class CIndexTrans;
  165. friend class CMasterMergeTrans;
  166. friend class CMergeThreadKiller;
  167. friend class CDeletedIIDTrans;
  168. friend class CNotificationTransaction;
  169. friend class CBackupCiPersData;
  170. public:
  171. CResManager( PStorage& storage,
  172. CCiFrameworkParams & params,
  173. ICiCDocStore * pICiCDocStore,
  174. CI_STARTUP_INFO const & startupInfo,
  175. IPropertyMapper * pIPropertyMapper,
  176. CTransaction &xact,
  177. XInterface<CIndexNotificationTable> & xIndexNotifTable );
  178. ~CResManager();
  179. void RegisterFilterAgent ( CFilterAgent* pFilterAgent )
  180. {
  181. _pFilterAgent = pFilterAgent;
  182. }
  183. static DWORD WINAPI MergeThread( void* self );
  184. //
  185. // State Changes
  186. //
  187. NTSTATUS Dismount();
  188. void Empty();
  189. NTSTATUS ForceMerge ( PARTITIONID partid, CI_MERGE_TYPE mt );
  190. NTSTATUS StopCurrentMerge();
  191. void DisableUpdates( PARTITIONID partid );
  192. void EnableUpdates( PARTITIONID partid );
  193. //
  194. // Global Resources
  195. //
  196. BOOL IsLowOnDiskSpace() const { return _isLowOnDiskSpace; }
  197. BOOL VerifyIfLowOnDiskSpace()
  198. {
  199. CPriLock lock(_mutex);
  200. return LokCheckLowOnDiskSpace();
  201. }
  202. BOOL LokCheckLowOnDiskSpace ()
  203. {
  204. _isLowOnDiskSpace = LokCheckIfDiskLow(*this,
  205. _storage,
  206. _isLowOnDiskSpace,
  207. _adviseStatus.GetReference() );
  208. return _isLowOnDiskSpace;
  209. }
  210. BOOL LokCheckWordlistQuotas();
  211. NTSTATUS MarkCorruptIndex();
  212. void NoFailFreeResources();
  213. BOOL IsMemoryLow();
  214. BOOL IsIoHigh();
  215. BOOL IsBatteryLow();
  216. BOOL IsOnBatteryPower();
  217. BOOL IsUserActive( BOOL fCheckLongTermActivity );
  218. void SampleUserActivity();
  219. void IndexSize( ULONG & mbIndex );
  220. //
  221. // Statistics and State
  222. //
  223. BOOL IsEmpty() const { return _isBeingEmptied; }
  224. unsigned CountPendingUpdates(unsigned& secCount);
  225. inline unsigned CountPendingUpdates()
  226. {
  227. unsigned temp;
  228. return CountPendingUpdates( temp );
  229. }
  230. void LokUpdateCounters(); // performance meter
  231. void ReferenceQuery();
  232. void DereferenceQuery();
  233. LONG GetQueryCount() const { return _cQuery; }
  234. //
  235. // Updates and queries
  236. //
  237. unsigned ReserveUpdate( WORKID wid );
  238. SCODE UpdateDocument( unsigned iHint,
  239. WORKID wid,
  240. PARTITIONID partid,
  241. USN usn,
  242. VOLUMEID volumeId,
  243. ULONG action);
  244. void FlushUpdates();
  245. void MarkUnReachable( WORKID wid )
  246. {
  247. _docStore->MarkDocUnReachable( wid );
  248. }
  249. CIndex** QueryIndexes ( unsigned cPartitions,
  250. PARTITIONID aPartID[],
  251. CFreshTest** freshTest,
  252. unsigned& cInd,
  253. ULONG cPendingUpdates,
  254. CCurStack * pcurPending,
  255. ULONG* pFlags );
  256. void ReleaseIndexes (
  257. unsigned cInd,
  258. CIndex** apIndex,
  259. CFreshTest* fresh );
  260. SCODE ClearNonStoragePropertiesForWid( WORKID wid );
  261. //
  262. // Backup of Content Index Data.
  263. //
  264. SCODE BackupCIData( PStorage & storage,
  265. BOOL & fFull,
  266. XInterface<ICiEnumWorkids> & xEnumWorkids,
  267. PSaveProgressTracker & progressTracker );
  268. //
  269. // Feedback from downlevel scan
  270. //
  271. inline void MarkOutOfDate();
  272. inline void MarkUpToDate();
  273. //
  274. // Scanning
  275. //
  276. void SetUpdatesLost( PARTITIONID partId );
  277. //
  278. // Notification of ChangeLog flushes support.
  279. //
  280. void NotifyFlush( FILETIME const & ft,
  281. ULONG cEntries,
  282. USN_FLUSH_INFO ** aInfo );
  283. void ProcessFlushNotifies();
  284. // KeyIndex specific Methods
  285. ULONG KeyToId( CKey const * pkey );
  286. void IdToKey( ULONG ulKid, CKey & rkey );
  287. // Relevant Words
  288. CRWStore * ComputeRelevantWords(ULONG cRows,ULONG cRW,
  289. WORKID *pwid,PARTITIONID partid);
  290. CRWStore * RetrieveRelevantWords(BOOL fAcquire,PARTITIONID partid);
  291. NTSTATUS CiState(CIF_STATE & state);
  292. void IncrementFilteredDocumentCount()
  293. {
  294. InterlockedIncrement(&_cFilteredDocuments);
  295. }
  296. ULONG GetFilteredDocumentCount() const { return _cFilteredDocuments; }
  297. CCiFrameworkParams & GetRegParams() { return _frmwrkParams; }
  298. SCODE FPSToPROPID( CFullPropSpec const & fps, PROPID & pid );
  299. BOOL FPushFiltering()
  300. {
  301. Win4Assert( _fPushFiltering == !_xIndexNotifTable.IsNull() );
  302. return _fPushFiltering;
  303. }
  304. void NoFailAbortWidsInDocList();
  305. void NoFailAbortWid( WORKID wid, USN usn );
  306. BOOL LokIsWidAborted( WORKID wid, USN usn )
  307. {
  308. return _aAbortedWids.LokIsWidAborted( wid, usn );
  309. }
  310. void LokRemoveAbortedWid( WORKID wid, USN usn )
  311. {
  312. _aAbortedWids.LokRemoveWid( wid, usn );
  313. }
  314. BOOL IsCiCorrupt() { return _isCorrupt; }
  315. # ifdef CIEXTMODE
  316. void CiExtDump(void *ciExtSelf);
  317. # endif
  318. private:
  319. // Allow Fiter Manager to lock ResManager
  320. CMutexSem& GetMutex () { return _mutex; }
  321. void CompactResources();
  322. unsigned LokGetFreshCount()
  323. {
  324. return _fresh.LokCount();
  325. }
  326. inline void LokCommitFresh ( CFreshTest* freshTest );
  327. CPartition* LokGetPartition ( PARTITIONID partid )
  328. { return _partList.LokGetPartition(partid); }
  329. // Merges
  330. void DoMerges();
  331. void StopMerges();
  332. void CheckAndDoMerge( MergeType mt, CPartIdStack & partitionIds );
  333. BOOL CheckDeleteMerge( BOOL fForce );
  334. void Merge ( MergeType mt, PARTITIONID partid );
  335. void MasterMerge ( PARTITIONID partid );
  336. void LokClearForceMerge() { _partidToMerge = partidInvalid; }
  337. void LokReleaseIndex ( CIndex* pIndex );
  338. void LokReplaceMasterIndex( CMasterMergeIndex * pMMergeIndex );
  339. #ifdef KEYLIST_ENABLED
  340. CKeyList * _AddRefKeyList();
  341. void _ReleaseKeyList();
  342. #endif // KEYLIST_ENABLED
  343. void RollBackDeletedIIDChange( CDeletedIIDTrans & xact );
  344. // Filter related methods
  345. CDocList & GetDocList() { return _docList; }
  346. BOOL GetFilterDocs ( ULONG cMaxDocs,
  347. ULONG & cDocs,
  348. CGetFilterDocsState & state );
  349. BOOL LokGetFilterDocs( ULONG cMaxDocs,
  350. ULONG & cDocs,
  351. CGetFilterDocsState & state );
  352. void FillDocBuffer ( BYTE * docBuffer,
  353. ULONG & cb,
  354. ULONG & cDocs,
  355. CGetFilterDocsState & state );
  356. BOOL NoFailReFile ( CDocList& docList );
  357. BOOL ReFileCommit ( CDocList& docList );
  358. void NoFailReFileChanges( CDocList& docList );
  359. void LokNoFailReFileChanges( CDocList& docList );
  360. void LokReFileDocument ( PARTITIONID partid,
  361. WORKID wid,
  362. USN usn,
  363. VOLUMEID volumeId,
  364. ULONG retries,
  365. ULONG cSecQRetries );
  366. void LokAddToSecQueue( PARTITIONID partid, WORKID wid, VOLUMEID volumeId, ULONG cSecQRetries );
  367. void LokRefileSecQueueDocs();
  368. BOOL LokTransferWordlist ( PWordList& pWordlist );
  369. void LokNoFailRemoveWordlist( CPartition * pPart );
  370. INDEXID LokMakeWordlistId (PARTITIONID partid);
  371. void ReportFilterFailure (WORKID wid);
  372. SCODE StoreValue( WORKID wid, CFullPropSpec const & ps, CStorageVariant const & var, BOOL & fInSchema );
  373. BOOL StoreSecurity( WORKID wid, PSECURITY_DESCRIPTOR pSD, ULONG cbSD);
  374. void ReportFilteringState( DWORD dwState )
  375. {
  376. CPriLock lock( _mutex );
  377. _dwFilteringState = dwState;
  378. }
  379. //
  380. // Scan and Recovery support
  381. //
  382. void LokCleanupForFullCiScan();
  383. //
  384. // Misc utility methods.
  385. //
  386. static BOOL IsDiskFull( NTSTATUS status )
  387. {
  388. return STATUS_DISK_FULL == status ||
  389. ERROR_DISK_FULL == status ||
  390. HRESULT_FROM_WIN32(ERROR_DISK_FULL) == status ||
  391. CI_E_CONFIG_DISK_FULL == status;
  392. }
  393. static BOOL IsCorrupt( NTSTATUS status )
  394. {
  395. return CI_CORRUPT_DATABASE == status ||
  396. STATUS_INTEGER_DIVIDE_BY_ZERO == status ||
  397. STATUS_ACCESS_VIOLATION == status ||
  398. STATUS_DATATYPE_MISALIGNMENT == status ||
  399. STATUS_IN_PAGE_ERROR == status;
  400. }
  401. static void LogMMergeStartFailure( BOOL fReStart,
  402. PStorage & storage,
  403. DWORD dwError,
  404. ICiCAdviseStatus & adviseStatus );
  405. static void LogMMergePaused( PStorage & storage,
  406. DWORD dwError,
  407. ICiCAdviseStatus & adviseStatus);
  408. //
  409. // Interfacing with the framework client
  410. //
  411. BOOL WorkidToDocName ( WORKID wid, BYTE * pbBuf, unsigned & cb, BOOL fAccurate );
  412. void GetClientState( ULONG & cDocuments );
  413. void LokNotifyCorruptionToClient();
  414. void LokNotifyDisableUpdatesToClient();
  415. void LokNotifyEnableUpdatesToClient();
  416. BOOL LokIsScanNeeded() const { return _isCorrupt
  417. || _state.LokGetState() == eUpdatesToBeDisabled
  418. || _state.LokGetState() == eUpdatesDisabled
  419. || _state.LokGetState() == eUpdatesToBeEnabled; }
  420. void LokWakeupMergeThread()
  421. {
  422. _eventMerge.Set();
  423. }
  424. void LokDeleteFlushWorkItems();
  425. BOOL IsIndexMigrationEnabled() const
  426. {
  427. return _configFlags & CI_CONFIG_ENABLE_INDEX_MIGRATION;
  428. }
  429. BOOL IsIndexingEnabled() const
  430. {
  431. return _configFlags & CI_CONFIG_ENABLE_INDEXING;
  432. }
  433. BOOL IsQueryingEnabled() const
  434. {
  435. return _configFlags & CI_CONFIG_ENABLE_QUERYING;
  436. }
  437. CFresh & GetFresh() { return _fresh; }
  438. PIndexTable & GetIndexTable()
  439. {
  440. return *_idxTab;
  441. }
  442. BOOL LokIsMasterMergeInProgress( PARTITIONID partId = partidDefault )
  443. {
  444. CPartition *pPartition =
  445. _partList.LokGetPartition ( partId );
  446. return pPartition->InMasterMerge();
  447. }
  448. BOOL LokIsMasterIndexPresent( PARTITIONID partId = partidDefault )
  449. {
  450. CPartition *pPartition =
  451. _partList.LokGetPartition ( partId );
  452. return 0 != pPartition->GetCurrentMasterIndex();
  453. }
  454. void BackupContentIndexData();
  455. void LokUpdateBackupMergeProgress();
  456. ULONG GetStorageVersion() { return _storage.GetStorageVersion(); }
  457. //-----------------------------------------------
  458. // This MUST be the first variable in this class.
  459. //-----------------------------------------------
  460. const LONGLONG _sigResman;
  461. PStorage& _storage;
  462. CMutexSem _mutex;
  463. ULONGLONG _mergeTime; // Time to next master merge
  464. XInterface<ICiCResourceMonitor> _xLowRes; // Monitors resource conditions
  465. XInterface<ICiCResourceMonitor> _xLowResDefault; // Monitors resource conditions
  466. //ULONG _ulPagesPerMeg; // System pages per Meg (varies with system page size)
  467. //ULONG _ulPageSize; // System page size
  468. //
  469. // Performance Object
  470. // Note : Must be initialized before CFilterDaemon
  471. // and destroyed after the partition list.
  472. //
  473. CCiFrameworkParams & _frmwrkParams;
  474. XPtr<CKeyList> _sKeyList; // Safe pointer to the keylist object
  475. SIndexTable _idxTab; // index table
  476. CPartList _partList; // list of partitions
  477. CFresh _fresh; // table of fresh indexes
  478. // MUST BE after _partList.
  479. CPartIter _partIter; // partition iterator
  480. CEventSem _eventMerge;
  481. PARTITIONID _partidToMerge; // force merge of this partition
  482. CI_MERGE_TYPE _mtForceMerge; // type of merge
  483. CMerge * _pMerge;
  484. BOOL _fStopMerge;
  485. long _cQuery;
  486. long _cFilteredDocuments; // # filtered documents since boot
  487. CFilterAgent* _pFilterAgent;
  488. //
  489. // Queue used to properly order notifications coming from Cleanup.
  490. //
  491. CPendingQueue _pendQueue;
  492. //
  493. // Documents that are currently being filtered by the daemon.
  494. //
  495. CDocList _docList;
  496. //
  497. // In-progress backup operation.
  498. //
  499. CBackupCiWorkItem * _pBackupWorkItem;
  500. BOOL _isBeingEmptied;
  501. BOOL _isLowOnDiskSpace;
  502. BOOL _isDismounted;
  503. BOOL _isOutOfDate;
  504. BOOL _isCorrupt;
  505. BOOL _fFirstTimeUpdatesAreEnabled; // Is this the first time that
  506. // updates have been enabled after
  507. // startup ? This is used in push
  508. // filtering to initialize in-memory
  509. // part of changelog.
  510. BOOL _fPushFiltering; // Push model of filtering ?
  511. const CI_STARTUP_FLAGS _configFlags; // Content Index flags
  512. CResManState _state;
  513. DWORD _dwFilteringState; // State of the Filter Manager (for ::CiState)
  514. //
  515. // Framework interfacing.
  516. //
  517. XInterface<ICiCDocStore> _docStore;
  518. XInterface<ICiCDocNameToWorkidTranslator> _translator;
  519. XInterface<ICiCDocNameToWorkidTranslatorEx> _translator2;
  520. XInterface<ICiCAdviseStatus> _adviseStatus;
  521. XInterface<ICiCPropertyStorage> _propStore;
  522. XInterface<IPropertyMapper> _mapper;
  523. XInterface<CIndexNotificationTable> _xIndexNotifTable; // Table of notifications
  524. CAbortedWids _aAbortedWids; // List of aborted wids
  525. //
  526. // Mutex to guard the flush notify list and the flush notify list.
  527. //
  528. BOOL _fFlushWorkerActive;
  529. CMutexSem _mtxChangeFlush;
  530. CChangesNotifyFlushList _flushList;
  531. //
  532. // WorkQueue manager for the async work items.
  533. //
  534. CWorkManager _workMan; // Work Queue Manager
  535. //
  536. // This mutex is for the workIdToDocName only. It is too expensive
  537. // to hold resman lock while doing the wid->docname conversion.
  538. //
  539. CMutexSem _workidToDocNameMutex;
  540. XPtr<CWorkIdToDocName> _xWorkidToDocName;
  541. CCiFrmPerfCounter _prfCounter;
  542. //
  543. // Be sure the threads are created *after* any resources they use.
  544. //
  545. CThread _thrMerge;
  546. CMergeThreadKiller _mergeKiller;
  547. CDeletedIndex _activeDeletedIndex;
  548. };
  549. inline void CResManager::NoFailReFileChanges ( CDocList& docList )
  550. {
  551. CPriLock lock(_mutex);
  552. LokNoFailReFileChanges(docList);
  553. }
  554. inline BOOL CResManager::GetFilterDocs ( ULONG cMaxDocs,
  555. ULONG & cDocs,
  556. CGetFilterDocsState & state )
  557. {
  558. CPriLock lock (_mutex);
  559. return LokGetFilterDocs ( cMaxDocs, cDocs, state );
  560. }
  561. inline void CResManager::MarkOutOfDate()
  562. {
  563. CPriLock lock (_mutex);
  564. _isOutOfDate = TRUE;
  565. }
  566. inline void CResManager::MarkUpToDate()
  567. {
  568. CPriLock lock (_mutex);
  569. _isOutOfDate = FALSE;
  570. }
  571. inline void CResManager::ReferenceQuery()
  572. {
  573. InterlockedIncrement(&_cQuery);
  574. }
  575. inline void CResManager::DereferenceQuery()
  576. {
  577. Win4Assert( _cQuery > 0 );
  578. InterlockedDecrement(&_cQuery);
  579. }
  580. //+---------------------------------------------------------------------------
  581. //
  582. // Function: ForceMerge, public
  583. //
  584. // Synopsis: Forces a master merge on the partition specified
  585. //
  586. // Arguments: [partid] -- partition ID to merge
  587. // [mt] -- merge type (master, shadow, etc.)
  588. //
  589. // History: 16-Nov-94 DwightKr Added this header
  590. //
  591. //----------------------------------------------------------------------------
  592. inline NTSTATUS CResManager::ForceMerge ( PARTITIONID partid,
  593. CI_MERGE_TYPE mt )
  594. {
  595. _partidToMerge = partid;
  596. _mtForceMerge = mt;
  597. _eventMerge.Set(); // wake up
  598. return STATUS_SUCCESS;
  599. }
  600. //+---------------------------------------------------------------------------
  601. //
  602. // Member: CResManager::LokCommitFresh, public
  603. //
  604. // Arguments: [pFreshTest] -- fresh test to be committed
  605. //
  606. // History: 08-Oct-91 BartoszM Created
  607. //
  608. // Notes: Commits a new fresh test, All transactions are under resman lock
  609. //
  610. //----------------------------------------------------------------------------
  611. inline void CResManager::LokCommitFresh( CFreshTest* pFreshTest )
  612. {
  613. _fresh.LokCommitMaster(pFreshTest);
  614. }
  615. //+---------------------------------------------------------------------------
  616. //
  617. // Class: CMasterMergePolicy
  618. //
  619. // Purpose: Encapsulates all rules used to determine if it is time to
  620. // automatically trigger a master merge.
  621. //
  622. // History: 03-Aug-94 DwightKr Created
  623. //
  624. //----------------------------------------------------------------------------
  625. class CMasterMergePolicy
  626. {
  627. public :
  628. CMasterMergePolicy( PStorage & storage,
  629. __int64 & shadowIndexSize,
  630. unsigned freshCount,
  631. ULONGLONG & mergeTime,
  632. CCiFrameworkParams & regParams,
  633. ICiCAdviseStatus & adviseStatus) :
  634. _frmwrkParams( regParams ),
  635. _storage(storage),
  636. _shadowIndexSize(shadowIndexSize),
  637. _freshCount(freshCount),
  638. _mergeTime(mergeTime),
  639. _adviseStatus(adviseStatus)
  640. {}
  641. BOOL IsTimeToMasterMerge() const;
  642. BOOL IsMidNightMergeTime();
  643. static ULONGLONG ComputeMidNightMergeTime( LONG mergeTime );
  644. private:
  645. BOOL IsMinDiskFreeForceMerge() const;
  646. BOOL IsMaxShadowIndexSize() const;
  647. BOOL IsMaxFreshListCount() const;
  648. PStorage & _storage;
  649. __int64 & _shadowIndexSize;
  650. unsigned _freshCount;
  651. ULONGLONG & _mergeTime;
  652. CCiFrameworkParams & _frmwrkParams;
  653. ICiCAdviseStatus & _adviseStatus;
  654. };