internal static WatermarkMap Parse(string rawstring) { WatermarkMap empty = WatermarkMap.Empty; string[] array = rawstring.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { string[] array3 = text.Split(new string[] { ":" }, StringSplitOptions.None); if (array3.Length != 2) { throw new FormatException(); } Guid key = new Guid(array3[0]); long value = long.Parse(array3[1]); if (!empty.ContainsKey(key)) { empty.Add(key, value); } } return(empty); }
private bool TrySelectDomainController(ITopologyConfigurationSession session, string domainControllerFqdn, PartitionId partitionId, bool checkSuitability, out Guid resultInvocationId) { ExTraceGlobals.ActiveDirectoryTracer.TraceDebug <string>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.TrySelectDomainController dc {0}", domainControllerFqdn); resultInvocationId = Guid.Empty; string text; LocalizedString localizedString; if (checkSuitability && !SuitabilityVerifier.IsServerSuitableIgnoreExceptions(domainControllerFqdn, false, null, out text, out localizedString)) { ExTraceGlobals.ActiveDirectoryTracer.TraceWarning <string, string>((long)base.TenantExternalDirectoryId.GetHashCode(), "DC {0} is not available for Tenant Full Backsync, error {1}", domainControllerFqdn, localizedString.ToString()); return(false); } ITopologyConfigurationSession configSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(domainControllerFqdn, true, ConsistencyMode.IgnoreInvalid, null, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 461, "TrySelectDomainController", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\BackSync\\MergePageToken.cs"); WatermarkMap replicationCursors = SyncConfiguration.GetReplicationCursors(configSession, false, true); if (replicationCursors.ContainsAllChanges(base.Watermarks)) { Guid invocationIdByFqdn = session.GetInvocationIdByFqdn(domainControllerFqdn); long num; if (base.Watermarks.TryGetValue(invocationIdByFqdn, out num)) { base.ObjectUpdateSequenceNumber = num + 1L; base.TombstoneUpdateSequenceNumber = num + 1L; base.InvocationId = invocationIdByFqdn; if (base.UseContainerizedUsnChangedIndex) { base.SoftDeletedObjectUpdateSequenceNumber = num + 1L; } ExTraceGlobals.ActiveDirectoryTracer.TraceDebug((long)base.TenantExternalDirectoryId.GetHashCode(), "DC {0}({1})has all changes reported by the Tenant Full Sync Watermarks for {2} and CAN be used. \r\nFull sync watermarks: \r\n{3}\r\nDC replication cursors: \r\n{4}", new object[] { domainControllerFqdn, base.InvocationId, base.TenantExternalDirectoryId, base.Watermarks.SerializeToString(), replicationCursors.SerializeToString() }); resultInvocationId = invocationIdByFqdn; return(true); } ExTraceGlobals.ActiveDirectoryTracer.TraceDebug((long)base.TenantExternalDirectoryId.GetHashCode(), "DC {0}({1})has all changes reported by the Tenant Full Sync Watermarks for {2} but cannot be used since its invocationId is not part of the TFS watermarks. \r\nFull sync watermarks: \r\n{3}\r\n", new object[] { domainControllerFqdn, base.InvocationId, base.TenantExternalDirectoryId, base.Watermarks.SerializeToString() }); } else { ExTraceGlobals.ActiveDirectoryTracer.TraceDebug((long)base.TenantExternalDirectoryId.GetHashCode(), "DC {0} does not have all changes reported by the Tenant Full Sync Watermarks for {1} and cannot be used. \r\nFull sync watermarks: \r\n{2}\r\nDC replication cursors: \r\n{3}", new object[] { domainControllerFqdn, base.TenantExternalDirectoryId, base.Watermarks.SerializeToString(), replicationCursors.SerializeToString() }); } return(false); }
private bool IsMergeNeeded(PartitionId partitionId) { ADReplicationCursorCollection cursors = this.dirSyncCookie.Cursors; ExTraceGlobals.MergeTracer.TraceDebug <ADReplicationCursorCollection>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.IsMergeNeeded original cursors from dirsync cookie = {0}", cursors); WatermarkMap watermarkMap = this.FilterOutNotExistingDCs(cursors, partitionId); ExTraceGlobals.MergeTracer.TraceDebug <string>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.IsMergeNeeded cursors from dirsync cookie filtered only for live DCs = {0}", watermarkMap.SerializeToString()); ExTraceGlobals.MergeTracer.TraceDebug <string>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.IsMergeNeeded watermarks from token = {0}", base.Watermarks.SerializeToString()); bool flag = watermarkMap.Any((KeyValuePair <Guid, long> dcw) => !base.Watermarks.ContainsKey(dcw.Key) || base.Watermarks[dcw.Key] < dcw.Value); ExTraceGlobals.MergeTracer.TraceDebug <bool>((long)base.TenantExternalDirectoryId.GetHashCode(), "MergePageToken.IsMergeNeeded isMergeNeeded = {0}", flag); return(flag); }
internal bool ContainsAllChanges(WatermarkMap source) { foreach (KeyValuePair <Guid, long> keyValuePair in source) { long num; if (!base.TryGetValue(keyValuePair.Key, out num)) { return(false); } if (num < keyValuePair.Value) { return(false); } } return(true); }
private WatermarkMap FilterOutNotExistingDCs(IEnumerable <ReplicationCursor> adReplicationCursorCollection, PartitionId partitionId) { WatermarkMap watermarkMap = new WatermarkMap(); ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 336, "FilterOutNotExistingDCs", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\BackSync\\MergePageToken.cs"); WatermarkMap watermarkMap2 = null; ADServer adserver = topologyConfigurationSession.FindDCByInvocationId(base.WatermarksInvocationId); if (adserver != null) { topologyConfigurationSession.DomainController = adserver.DnsHostName; watermarkMap2 = SyncConfiguration.GetReplicationCursors(topologyConfigurationSession); } foreach (ReplicationCursor replicationCursor in adReplicationCursorCollection) { if (watermarkMap2 == null || watermarkMap2.ContainsKey(replicationCursor.SourceInvocationId)) { watermarkMap[replicationCursor.SourceInvocationId] = replicationCursor.UpToDatenessUsn; } } return(watermarkMap); }
internal static WatermarkMap GetReplicationCursors(ITopologyConfigurationSession configSession, bool useConfigNC = false, bool includeRetiredDCs = false) { WatermarkMap empty = WatermarkMap.Empty; bool useConfigNC2 = configSession.UseConfigNC; ADObjectId id = useConfigNC ? configSession.GetConfigurationNamingContext() : configSession.GetDomainNamingContext(); try { configSession.UseConfigNC = useConfigNC; MultiValuedProperty <ReplicationCursor> multiValuedProperty = configSession.ReadReplicationCursors(id); foreach (ReplicationCursor replicationCursor in multiValuedProperty) { if (includeRetiredDCs || replicationCursor.SourceDsa != null) { empty.Add(replicationCursor.SourceInvocationId, replicationCursor.UpToDatenessUsn); } } } finally { configSession.UseConfigNC = useConfigNC2; } return(empty); }
public override IEnumerable <ADRawEntry> GetDataPage() { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration GetDataPage ..."); WatermarkMap watermarks = SyncConfiguration.GetReplicationCursors(base.RootOrgConfigurationSession); string dcName = base.RootOrgConfigurationSession.DomainController; ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration dcName {0}", dcName); Guid watermarksInvocationId = base.RootOrgConfigurationSession.GetInvocationIdByFqdn(dcName); ExTraceGlobals.BackSyncTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration watermarksInvocationId {0}", watermarksInvocationId); long maxUsn = watermarks[watermarksInvocationId]; ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration maxUsn {0}", maxUsn); if (this.PageToken.InvocationId == Guid.Empty) { this.PageToken.InvocationId = watermarksInvocationId; ExTraceGlobals.BackSyncTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.InvocationId to {0}", this.PageToken.InvocationId); } while (this.ShouldReadMoreData()) { ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration this.PageToken.State = {0}", this.PageToken.State.ToString()); switch (this.PageToken.State) { case TenantFullSyncState.EnumerateLiveObjects: foreach (ADRawEntry entry in this.ReadLiveObjects()) { ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration EnumerateLiveObjects yield {0}", entry.Id); yield return(entry); } this.PageToken.PendingWatermarksInvocationId = watermarksInvocationId; ExTraceGlobals.BackSyncTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration EnumerateLiveObjects set this.PageToken.PendingWatermarksInvocationId to {0}", this.PageToken.PendingWatermarksInvocationId); this.PageToken.PendingWatermarks = watermarks; continue; case TenantFullSyncState.EnumerateLinksInPage: foreach (ADRawEntry entry2 in this.ReadLinks()) { ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration EnumerateLinksInPage yield {0}", entry2.Id); yield return(entry2); } continue; case TenantFullSyncState.EnumerateDeletedObjects: foreach (ADRawEntry entry3 in this.ReadDeletedObjects()) { ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration EnumerateDeletedObjects yield {0}", entry3.Id); yield return(entry3); } continue; case TenantFullSyncState.EnumerateSoftDeletedObjects: foreach (ADRawEntry entry4 in this.ReadSoftDeletedObjects()) { ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration EnumerateSoftDeletedObjects yield {0}", entry4.Id); yield return(entry4); } continue; } ExTraceGlobals.BackSyncTracer.TraceError <string>((long)SyncConfiguration.TraceId, "Invalid PageToken stat {0}", this.PageToken.State.ToString()); throw new ArgumentException(this.PageToken.State.ToString()); } ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration this.PageToken.ObjectUpdateSequenceNumber = {0}", this.PageToken.ObjectUpdateSequenceNumber); if (this.PageToken.ObjectUpdateSequenceNumber > maxUsn + 1L) { this.PageToken.ObjectUpdateSequenceNumber = maxUsn + 1L; ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.ObjectUpdateSequenceNumber to {0}", this.PageToken.ObjectUpdateSequenceNumber); } ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration this.PageToken.TombstoneUpdateSequenceNumber = {0}", this.PageToken.TombstoneUpdateSequenceNumber); if (this.PageToken.TombstoneUpdateSequenceNumber > maxUsn + 1L) { this.PageToken.TombstoneUpdateSequenceNumber = maxUsn + 1L; ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.TombstoneUpdateSequenceNumber to {0}", this.PageToken.TombstoneUpdateSequenceNumber); } ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration this.PageToken.SoftDeletedObjectUpdateSequenceNumber = {0}", this.PageToken.SoftDeletedObjectUpdateSequenceNumber); if (this.PageToken.SoftDeletedObjectUpdateSequenceNumber > maxUsn + 1L) { this.PageToken.SoftDeletedObjectUpdateSequenceNumber = maxUsn + 1L; ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.SoftDeletedObjectUpdateSequenceNumber to {0}", this.PageToken.SoftDeletedObjectUpdateSequenceNumber); } this.PageToken.LastReadFailureStartTime = DateTime.MinValue; ExTraceGlobals.BackSyncTracer.TraceDebug <DateTime>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.LastReadFailureStartTime to {0}", this.PageToken.LastReadFailureStartTime); this.PageToken.Timestamp = DateTime.UtcNow; ExTraceGlobals.BackSyncTracer.TraceDebug <DateTime>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration set this.PageToken.Timestamp to {0}", this.PageToken.Timestamp); yield break; }
public TenantRelocationSyncPageToken(byte[] tokenBytes) { Exception ex = null; try { using (BackSyncCookieReader backSyncCookieReader = BackSyncCookieReader.Create(tokenBytes, typeof(TenantRelocationSyncPageToken))) { this.Version = (int)backSyncCookieReader.GetNextAttributeValue(); backSyncCookieReader.GetNextAttributeValue(); this.Timestamp = DateTime.FromBinary((long)backSyncCookieReader.GetNextAttributeValue()); this.LastReadFailureStartTime = DateTime.FromBinary((long)backSyncCookieReader.GetNextAttributeValue()); this.InvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.TenantConfigUnitObjectGuid = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.TenantOrganizationalUnitObjectGuid = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.IsTenantConfigUnitInConfigNc = (bool)backSyncCookieReader.GetNextAttributeValue(); byte[] array = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array != null) { this.PartitionHint = TenantPartitionHint.Deserialize(array); } this.State = (TenantRelocationSyncState)backSyncCookieReader.GetNextAttributeValue(); this.ConfigUnitObjectUSN = (long)backSyncCookieReader.GetNextAttributeValue(); this.ConfigUnitTombstoneUSN = (long)backSyncCookieReader.GetNextAttributeValue(); this.OrganizationalUnitObjectUSN = (long)backSyncCookieReader.GetNextAttributeValue(); this.OrganizationalUnitTombstoneUSN = (long)backSyncCookieReader.GetNextAttributeValue(); this.SpecialObjectsUSN = (long)backSyncCookieReader.GetNextAttributeValue(); byte[] array2 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array2 != null) { this.ConfigNcWatermarks = WatermarkMap.Parse(array2); } byte[] array3 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array3 != null) { this.PendingConfigNcWatermarks = WatermarkMap.Parse(array3); } byte[] array4 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array4 != null) { this.Watermarks = WatermarkMap.Parse(array4); } this.WatermarksInvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.PendingWatermarksInvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); byte[] array5 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array5 != null) { this.PendingWatermarks = WatermarkMap.Parse(array5); } this.LinkPageStart = (long)backSyncCookieReader.GetNextAttributeValue(); this.LinkPageEnd = (long)backSyncCookieReader.GetNextAttributeValue(); this.LinkRangeStart = (int)backSyncCookieReader.GetNextAttributeValue(); this.ObjectsInLinkPage = (int)backSyncCookieReader.GetNextAttributeValue(); this.AffinityDcFqdn = (string)backSyncCookieReader.GetNextAttributeValue(); this.AffinityTargetDcFqdn = (string)backSyncCookieReader.GetNextAttributeValue(); this.PreSyncLdapPagingCookie = (byte[])backSyncCookieReader.GetNextAttributeValue(); } } catch (ArgumentException ex2) { ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)this.TenantConfigUnitObjectGuid.GetHashCode(), "TenantRelocationSyncPageToken ArgumentException {0}", ex2.ToString()); ex = ex2; } catch (IOException ex3) { ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)this.TenantConfigUnitObjectGuid.GetHashCode(), "TenantRelocationSyncPageToken IOException {0}", ex3.ToString()); ex = ex3; } catch (FormatException ex4) { ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)this.TenantConfigUnitObjectGuid.GetHashCode(), "TenantRelocationSyncPageToken FormatException {0}", ex4.ToString()); ex = ex4; } catch (InvalidCookieException ex5) { ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)this.TenantConfigUnitObjectGuid.GetHashCode(), "TenantRelocationSyncPageToken InvalidCookieException {0}", ex5.ToString()); ex = ex5; } if (ex != null) { ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)this.TenantConfigUnitObjectGuid.GetHashCode(), "TenantRelocationSyncPageToken throw InvalidCookieException {0}", ex.ToString()); throw new InvalidCookieException(ex); } }
internal static WatermarkMap Parse(byte[] rawBytes) { string @string = Encoding.UTF8.GetString(rawBytes); return(WatermarkMap.Parse(@string)); }
protected TenantFullSyncPageToken(byte[] tokenBytes) { Exception ex = null; try { using (BackSyncCookieReader backSyncCookieReader = BackSyncCookieReader.Create(tokenBytes, typeof(TenantFullSyncPageToken))) { this.Version = (int)backSyncCookieReader.GetNextAttributeValue(); this.ServiceInstanceId = new ServiceInstanceId((string)backSyncCookieReader.GetNextAttributeValue()); this.Timestamp = DateTime.FromBinary((long)backSyncCookieReader.GetNextAttributeValue()); this.LastReadFailureStartTime = DateTime.FromBinary((long)backSyncCookieReader.GetNextAttributeValue()); this.InvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.TenantExternalDirectoryId = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.TenantObjectGuid = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.State = (TenantFullSyncState)backSyncCookieReader.GetNextAttributeValue(); this.ObjectUpdateSequenceNumber = (long)backSyncCookieReader.GetNextAttributeValue(); this.TombstoneUpdateSequenceNumber = (long)backSyncCookieReader.GetNextAttributeValue(); byte[] array = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array != null) { this.PendingWatermarks = WatermarkMap.Parse(array); } this.PendingWatermarksInvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); byte[] array2 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array2 != null) { this.Watermarks = WatermarkMap.Parse(array2); } this.WatermarksInvocationId = (Guid)backSyncCookieReader.GetNextAttributeValue(); this.LinkPageStart = (long)backSyncCookieReader.GetNextAttributeValue(); this.LinkPageEnd = (long)backSyncCookieReader.GetNextAttributeValue(); this.LinkRangeStart = (int)backSyncCookieReader.GetNextAttributeValue(); this.ObjectsInLinkPage = (int)backSyncCookieReader.GetNextAttributeValue(); string[] array3 = (string[])backSyncCookieReader.GetNextAttributeValue(); this.ErrorObjectsAndFailureCounts = ((array3 != null) ? BackSyncCookie.ParseErrorObjectsAndFailureCounts(array3) : new Dictionary <string, int>()); this.SequenceStartTimestamp = DateTime.FromBinary((long)backSyncCookieReader.GetNextAttributeValue()); this.SequenceId = (Guid)backSyncCookieReader.GetNextAttributeValue(); byte[] array4 = (byte[])backSyncCookieReader.GetNextAttributeValue(); if (array4 != null) { this.TenantScopedBackSyncCookie = BackSyncCookie.Parse(array4); this.InvocationId = this.TenantScopedBackSyncCookie.InvocationId; } this.UseContainerizedUsnChangedIndex = (bool)backSyncCookieReader.GetNextAttributeValue(); this.SoftDeletedObjectUpdateSequenceNumber = (long)backSyncCookieReader.GetNextAttributeValue(); this.PreviousState = (TenantFullSyncState)backSyncCookieReader.GetNextAttributeValue(); } } catch (ArgumentException ex2) { ExTraceGlobals.TenantFullSyncTracer.TraceError <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken ArgumentException {0}", ex2.ToString()); ex = ex2; } catch (IOException ex3) { ExTraceGlobals.TenantFullSyncTracer.TraceError <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken IOException {0}", ex3.ToString()); ex = ex3; } catch (FormatException ex4) { ExTraceGlobals.TenantFullSyncTracer.TraceError <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken FormatException {0}", ex4.ToString()); ex = ex4; } catch (InvalidCookieException ex5) { ExTraceGlobals.TenantFullSyncTracer.TraceError <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken InvalidCookieException {0}", ex5.ToString()); ex = ex5; } if (ex != null) { ExTraceGlobals.TenantFullSyncTracer.TraceError <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken throw InvalidCookieException {0}", ex.ToString()); throw new InvalidCookieException(ex); } }