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.

149 lines
3.7 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. //+-------------------------------------------------------------------------
  3. //
  4. // Microsoft Windows
  5. //
  6. // File: seqstg.cxx
  7. //
  8. // Contents: Refresh sequence number storage
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. //
  15. //
  16. // History: 03-Oct-97 BillMo Created
  17. //
  18. // Notes:
  19. //
  20. // Codework:
  21. //
  22. //--------------------------------------------------------------------------
  23. #include "pch.cxx"
  24. #pragma hdrstop
  25. #include "trksvr.hxx"
  26. class CLdapRefreshSeqDn
  27. {
  28. public:
  29. // specific volume
  30. CLdapRefreshSeqDn( const TCHAR * ptszBaseDn )
  31. {
  32. // Compose, the following DN:
  33. // "CN=RefreshSequence,CN=VolumeTable,CN=FileLinks,DC=TRKDOM"
  34. _tcscpy(_szDn, TEXT("CN=RefreshSequence,CN=VolumeTable,"));
  35. _tcscat(_szDn, ptszBaseDn );
  36. TrkAssert(_tcslen(_szDn) < ELEMENTS(_szDn));
  37. }
  38. inline operator TCHAR * () { return _szDn; }
  39. private:
  40. TCHAR _szDn[MAX_PATH];
  41. };
  42. //+----------------------------------------------------------------------------
  43. //
  44. // CRefreshSequenceStorage::GetSequenceNumber
  45. //
  46. // Get the current value of the sequence number. If the cached value is
  47. // old and we're not the designated DC, then re-read it from the DS. (Since
  48. // the designated DC is the only one that writes this value, it needn't
  49. // ever refresh its cache).
  50. //
  51. //+----------------------------------------------------------------------------
  52. SequenceNumber
  53. CRefreshSequenceStorage::GetSequenceNumber()
  54. {
  55. CVolumeId volidZero;
  56. CMachineId mcidZero(MCID_INVALID);
  57. CVolumeSecret secretZero;
  58. CFILETIME cft; // Initializes to current time
  59. _cs.Enter();
  60. __try
  61. {
  62. // See if our cached value is young enough.
  63. cft.DecrementSeconds( _psvrconfig->GetRefreshStorageTTL() );
  64. if ( _pQuotaTab->IsDesignatedDc() && _cftLastRead != 0
  65. ||
  66. _cftLastRead >= cft )
  67. {
  68. // Yes, we can just return _seq as is.
  69. //TrkLog(( TRKDBG_GARBAGE_COLLECT | TRKDBG_SVR,
  70. // TEXT("CRefreshSequenceStorage using cached value (%d)"), _seq ));
  71. __leave;
  72. }
  73. // We need to read the sequence number from the DS.
  74. if ( _pVolTab->GetVolumeInfo( volidZero, &mcidZero, &secretZero, &_seq, &cft ) ==
  75. TRK_S_VOLUME_NOT_FOUND )
  76. {
  77. // volidZero doesn't exist, so we'll assume the sequence number is zero.
  78. // If we're the designated DC, write this out.
  79. if( _pQuotaTab->IsDesignatedDc() )
  80. {
  81. TrkLog((TRKDBG_GARBAGE_COLLECT | TRKDBG_SVR,
  82. TEXT("CRefreshSequenceStorage::GetSequenceNumber - creating volume id 0")));
  83. _pVolTab->AddVolidToTable( volidZero, mcidZero, secretZero );
  84. }
  85. _seq = 0;
  86. }
  87. #if DBG
  88. else
  89. {
  90. // We read it successfully.
  91. TrkLog(( TRKDBG_GARBAGE_COLLECT | TRKDBG_SVR,
  92. TEXT("CRefreshSequenceStorage read %d"), _seq ));
  93. }
  94. #endif
  95. _cftLastRead = CFILETIME();
  96. }
  97. __finally
  98. {
  99. _cs.Leave();
  100. }
  101. return(_seq);
  102. }
  103. void
  104. CRefreshSequenceStorage::IncrementSequenceNumber()
  105. {
  106. SequenceNumber seq;
  107. CVolumeId volidZero;
  108. _cs.Enter();
  109. __try
  110. {
  111. TrkAssert( _pQuotaTab->IsDesignatedDc() );
  112. if( _cftLastRead == CFILETIME(0) )
  113. GetSequenceNumber();
  114. _pVolTab->SetSequenceNumber( volidZero, ++_seq );
  115. _cftLastRead = CFILETIME();
  116. }
  117. __finally
  118. {
  119. _cs.Leave();
  120. }
  121. }