internal void UpdateADData(ADUser user, TransactionalRequestJob requestJob, bool save) { if (save) { user.MailboxMoveStatus = RequestJobBase.GetVersionAppropriateStatus(requestJob.Status, user.ExchangeVersion); user.MailboxMoveFlags = RequestJobBase.GetVersionAppropriateFlags(requestJob.Flags, user.ExchangeVersion); user.MailboxMoveSourceMDB = requestJob.SourceDatabase; user.MailboxMoveTargetMDB = requestJob.TargetDatabase; user.MailboxMoveSourceArchiveMDB = requestJob.SourceArchiveDatabase; user.MailboxMoveTargetArchiveMDB = requestJob.TargetArchiveDatabase; user.MailboxMoveRemoteHostName = requestJob.RemoteHostName; user.MailboxMoveBatchName = requestJob.BatchName; return; } user.MailboxMoveStatus = RequestStatus.None; user.MailboxMoveFlags = RequestFlags.None; user.MailboxMoveSourceMDB = null; user.MailboxMoveTargetMDB = null; user.MailboxMoveSourceArchiveMDB = null; user.MailboxMoveTargetArchiveMDB = null; user.MailboxMoveRemoteHostName = null; user.MailboxMoveBatchName = null; }
private static void CleanADOrphanAndInconsistencyForMoves(IRecipientSession recipientSession, RequestJobProvider rjProvider, Guid dbGuid) { ADObjectId propertyValue = new ADObjectId(dbGuid); QueryFilter queryFilter = new AndFilter(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.NotEqual, ADUserSchema.MailboxMoveStatus, RequestStatus.None), new ExistsFilter(ADUserSchema.MailboxMoveStatus) }); QueryFilter queryFilter2 = QueryFilter.OrTogether(new QueryFilter[] { QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.MailboxMoveSourceMDB, propertyValue), new BitMaskAndFilter(ADUserSchema.MailboxMoveFlags, 4UL) }), QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADUserSchema.MailboxMoveTargetMDB, propertyValue), new BitMaskAndFilter(ADUserSchema.MailboxMoveFlags, 8UL) }) }); QueryFilter filter = new AndFilter(new QueryFilter[] { queryFilter, queryFilter2 }); ADRecipient[] array = recipientSession.Find(null, QueryScope.SubTree, filter, null, 1000); if (array == null || array.Length == 0) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves(): No move requests found for DB {0}", new object[] { dbGuid }); return; } bool needUpdateAD = false; ADRecipient[] array2 = array; for (int i = 0; i < array2.Length; i++) { ADRecipient request = array2[i]; CommonUtils.CatchKnownExceptions(delegate { needUpdateAD = false; ADUser aduser = request as ADUser; MoveRequestStatistics moveRequestStatistics = (MoveRequestStatistics)rjProvider.Read <MoveRequestStatistics>(new RequestJobObjectId(aduser.ExchangeGuid, dbGuid, null)); if (moveRequestStatistics == null || (!moveRequestStatistics.IsFake && moveRequestStatistics.Status == RequestStatus.None)) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD orphan {0} found for DB {1}", new object[] { aduser.ExchangeGuid, dbGuid }); CommonUtils.CleanupMoveRequestInAD(recipientSession, null, aduser); return; } if (moveRequestStatistics.IsFake) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():request {0} is uplevel/Fake, ignore it", new object[] { aduser.ExchangeGuid }); return; } if (moveRequestStatistics.User == null) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():request {0} has been deleted from AD, ignore it", new object[] { aduser.ExchangeGuid }); return; } if (moveRequestStatistics.TimeTracker.GetCurrentDurationChunk() > ADInconsistencyCheck.updateLatencyThreshhold) { RequestStatus versionAppropriateStatus = RequestJobBase.GetVersionAppropriateStatus(moveRequestStatistics.Status, aduser.ExchangeVersion); if (versionAppropriateStatus != moveRequestStatistics.User.MailboxMoveStatus) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD inconsistency {0} found for DB {1}, AD status is {2} but store status is {3} ({4})", new object[] { aduser.ExchangeGuid, dbGuid, aduser.MailboxMoveStatus, moveRequestStatistics.Status, versionAppropriateStatus }); aduser.MailboxMoveStatus = versionAppropriateStatus; needUpdateAD = true; } RequestFlags versionAppropriateFlags = RequestJobBase.GetVersionAppropriateFlags(moveRequestStatistics.Flags, aduser.ExchangeVersion); if (versionAppropriateFlags != moveRequestStatistics.User.MailboxMoveFlags) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForMoves():AD inconsistency {0} found for DB {1}, AD flags is {2} but store flags is {3} ({4})", new object[] { aduser.ExchangeGuid, dbGuid, aduser.MailboxMoveFlags, moveRequestStatistics.Flags, versionAppropriateFlags }); aduser.MailboxMoveFlags = versionAppropriateFlags; needUpdateAD = true; } if (needUpdateAD) { recipientSession.Save(request); } } }, delegate(Exception f) { MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForMoves() failed for DB {0}. move request {1} Error: {2}", new object[] { dbGuid, ((ADUser)request).ExchangeGuid, CommonUtils.FullExceptionMessage(f, true) }); MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[] { dbGuid, MRSRequestType.Move.ToString(), ((ADUser)request).ExchangeGuid, CommonUtils.FullExceptionMessage(f, true) }); }); } }