protected virtual SoftDeleteMailboxRemovalCheckRemoval GetMailboxRemovalReadiness(NonConnectedMailbox mailbox) { DirectoryIdentity directoryIdentity = DirectoryIdentity.CreateMailboxIdentity(mailbox.Guid, mailbox.OrganizationId, DirectoryObjectType.Mailbox); DirectoryIdentity identity = this.database.Identity; DirectoryDatabase databaseForMailbox; try { databaseForMailbox = this.context.Directory.GetDatabaseForMailbox(directoryIdentity); } catch (RecipientNotFoundException) { return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval("Recipient for mailbox '{0}' and organizationId '{1}' could not be found so removal can not take place", new object[] { directoryIdentity, mailbox.Identity.OrganizationId })); } if (databaseForMailbox == null) { return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval("Could not identify a database for mailbox '{0}' and organizationId '{1}'", new object[] { directoryIdentity, mailbox.Identity.OrganizationId })); } SoftDeletedRemovalData data = new SoftDeletedRemovalData(identity, databaseForMailbox.Identity, directoryIdentity, mailbox.ItemCount, mailbox.DisconnectDate); SoftDeleteMailboxRemovalCheckRemoval result; using (ILoadBalanceService loadBalanceClientForDatabase = this.context.ClientFactory.GetLoadBalanceClientForDatabase(databaseForMailbox)) { result = loadBalanceClientForDatabase.CheckSoftDeletedMailboxRemoval(data); } return(result); }
protected override SoftDeleteMailboxRemovalCheckRemoval CheckRemoval() { SoftDeletedMoveHistory softDeletedMoveHistory = this.context.RetrieveSoftDeletedMailboxMoveHistory(base.Data.MailboxIdentity.Guid, base.Data.TargetDatabase.Guid, base.Data.SourceDatabase.Guid); if (softDeletedMoveHistory == null) { string reasonMessage = "Cannot remove soft deleted mailbox {0} because its Movehistory for source database '{1}' and target database '{2}' could not be found"; return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval(reasonMessage, new object[] { base.Data.MailboxIdentity.Guid, base.Data.SourceDatabase.Name, base.Data.TargetDatabase.Name })); } if (softDeletedMoveHistory.BadItemsEncountered > 0 || softDeletedMoveHistory.LargeItemsEncountered > 0 || softDeletedMoveHistory.MissingItemsEncountered > 0) { string reasonMessage2 = "Cannot remove soft deleted mailbox {0} because its MoveHistory from '{1}' to '{2}' has BadItemCount: {3} LargeItemCount: {4} MissingItemCount: {5}."; return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval(reasonMessage2, new object[] { base.Data.MailboxIdentity.Guid, base.Data.SourceDatabase.Name, base.Data.TargetDatabase.Name, softDeletedMoveHistory.BadItemsEncountered, softDeletedMoveHistory.LargeItemsEncountered, softDeletedMoveHistory.MissingItemsEncountered })); } return(null); }
protected override SoftDeleteMailboxRemovalCheckRemoval CheckRemoval() { DirectoryIdentity targetDatabase = base.Data.TargetDatabase; DirectoryMailbox mailbox = base.TargetDatabase.GetMailbox(base.Data.MailboxIdentity); IPhysicalMailbox physicalMailbox = mailbox.PhysicalMailboxes.FirstOrDefault((IPhysicalMailbox mbx) => mbx.Guid == base.Data.MailboxIdentity.Guid); if (physicalMailbox == null) { return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval("An active mailbox for {0} could not be found.", new object[] { base.Data.MailboxIdentity })); } if (base.Data.ItemCount > (long)physicalMailbox.ItemCount) { string reasonMessage = "Cannot remove soft deleted mailbox {0} because its ItemCount is {1} which is greater than the active copy's ItemCount of {2} on database '{3}'."; return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval(reasonMessage, new object[] { base.Data.MailboxIdentity.Guid, base.Data.ItemCount, physicalMailbox.ItemCount, targetDatabase.Name })); } return(null); }
private SoftDeleteMailboxRemovalCheckRemoval CheckNext() { if (this.Next == null) { return(SoftDeleteMailboxRemovalCheckRemoval.AllowRemoval()); } return(this.Next.GetRemovalResult()); }
protected override SoftDeleteMailboxRemovalCheckRemoval CheckRemoval() { if (base.Data.DisconnectDate == null) { return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval("Cannot remove soft deleted mailbox {0} because it does not have a disconnect date.", new object[] { base.Data.MailboxIdentity })); } if (base.Data.DisconnectDate > this.removalCutoffDate) { string reasonMessage = "Cannot remove soft deleted mailbox {0} because its DisconnectDate is {1} and the minimum date for removal is {2}."; return(SoftDeleteMailboxRemovalCheckRemoval.DisallowRemoval(reasonMessage, new object[] { base.Data.MailboxIdentity, base.Data.DisconnectDate, this.removalCutoffDate })); } return(null); }
public void RemoveFromDatabase() { ByteQuantifiedSize currentSize = this.database.GetSize().CurrentPhysicalSize; ByteQuantifiedSize currentSize2 = currentSize; List <NonConnectedMailbox> source = this.database.GetDisconnectedMailboxes().ToList <NonConnectedMailbox>(); this.context.Logger.LogInformation("Beginning soft-deleted mailbox cleanup on database '{0}'", new object[] { this.database.Name }); this.context.Logger.LogInformation("Current size of database '{0}' is {1}, with a target size of {2}", new object[] { this.database.Name, currentSize, this.targetDatabaseSize }); int totalCountRemoved = 0; ByteQuantifiedSize totalSizeRemoved = default(ByteQuantifiedSize); IOperationRetryManager operationRetryManager = LoadBalanceOperationRetryManager.Create(1, TimeSpan.Zero, this.context.Logger); using (IEnumerator <NonConnectedMailbox> enumerator = (from o in source orderby o.DisconnectDate select o).GetEnumerator()) { while (enumerator.MoveNext()) { NonConnectedMailbox softDeletedMailbox = enumerator.Current; if (currentSize < this.targetDatabaseSize) { this.context.Logger.LogInformation("Current size of database '{0}' is below max size allowed by soft deleted threshold. Done deleting soft deleted mailboxes", new object[] { this.database.Name }); break; } if (softDeletedMailbox.IsSoftDeleted) { Exception exception = null; bool success = false; SoftDeletedMailboxRemovalLogEntry entry = new SoftDeletedMailboxRemovalLogEntry(); entry[SoftDeletedMailboxRemovalLogEntrySchema.MailboxGuid] = softDeletedMailbox.Guid; entry[SoftDeletedMailboxRemovalLogEntrySchema.DatabaseName] = this.database.Name; entry[SoftDeletedMailboxRemovalLogEntrySchema.TargetDatabaseSize] = this.targetDatabaseSize; entry[SoftDeletedMailboxRemovalLogEntrySchema.CurrentDatabaseSize] = currentSize; entry[SoftDeletedMailboxRemovalLogEntrySchema.OriginalDatabaseSize] = currentSize2; entry[SoftDeletedMailboxRemovalLogEntrySchema.MailboxSize] = softDeletedMailbox.PhysicalSize; OperationRetryManagerResult operationRetryManagerResult = operationRetryManager.TryRun(delegate { this.context.Logger.LogVerbose("Removing SoftDeleted Mailbox from database '{0}'. MailboxGuid: {1} MailboxSize: {2}", new object[] { this.database.Name, softDeletedMailbox.Guid, softDeletedMailbox.PhysicalSize }); SoftDeleteMailboxRemovalCheckRemoval mailboxRemovalReadiness = this.GetMailboxRemovalReadiness(softDeletedMailbox); entry[SoftDeletedMailboxRemovalLogEntrySchema.RemovalAllowed] = mailboxRemovalReadiness.CanRemove; entry[SoftDeletedMailboxRemovalLogEntrySchema.RemovalDisallowedReason] = mailboxRemovalReadiness.Reason; if (mailboxRemovalReadiness.CanRemove) { success = this.context.TryRemoveSoftDeletedMailbox(softDeletedMailbox.Guid, this.database.Guid, out exception); if (success) { currentSize -= softDeletedMailbox.PhysicalSize; totalCountRemoved++; totalSizeRemoved += softDeletedMailbox.PhysicalSize; this.context.Logger.LogVerbose("Mailbox '{0}' removed", new object[] { softDeletedMailbox.Guid }); } } }); if (!operationRetryManagerResult.Succeeded) { exception = operationRetryManagerResult.Exception; } entry[SoftDeletedMailboxRemovalLogEntrySchema.Removed] = success; entry[SoftDeletedMailboxRemovalLogEntrySchema.Error] = exception; this.logCollector.LogObject <SoftDeletedMailboxRemovalLogEntry>(entry); } } } this.context.Logger.LogInformation("Approximate final size of database '{0}' is {1}. Target size was {2}. {3} total mailboxes with total size of {4} deleted.", new object[] { this.database.Name, currentSize, this.targetDatabaseSize, totalCountRemoved, totalSizeRemoved }); this.context.Logger.LogInformation("Finished soft-deleted mailbox cleanup on database '{0}'", new object[] { this.database.Name }); }