Beispiel #1
0
        public ShardRecoveryJobState(string identifier, string shard, string node, string cluster, RecoveryJobType jobType)
        {
            if (!string.IsNullOrEmpty(identifier))
            {
                _identifier = identifier;
            }
            if (!string.IsNullOrEmpty(shard))
            {
                _shard = shard;
            }
            if (!string.IsNullOrEmpty(node))
            {
                _node = node;
            }
            if (!string.IsNullOrEmpty(cluster))
            {
                _cluster = cluster;
            }

            _jobType    = jobType;
            _entityList = new List <RecoveryJobStateBase>();
            _status     = RecoveryStatus.uninitiated;
            _message    = string.Empty;
            _percentage = 0;
        }
Beispiel #2
0
 private void HandleRecoveryStatus(RecoveryStatus status)
 {
     _log.Info("Received recovery status {0} from probe.", status);
     _journalLive       = status.JournalRecovered;
     _snapshotStoreLive = status.SnapshotRecovered;
     _currentStatus     = new LivenessStatus(_journalLive && _snapshotStoreLive, status.ToString());
     PublishStatusUpdates();
 }
Beispiel #3
0
        /// <summary>
        /// Restore log
        /// </summary>
        /// <param name="beginAddress"></param>
        /// <param name="headAddress"></param>
        /// <param name="fromAddress"></param>
        /// <param name="untilAddress"></param>
        /// <param name="numPagesToPreload">Number of pages to preload into memory after recovery</param>
        public void RestoreHybridLog(long beginAddress, long headAddress, long fromAddress, long untilAddress, int numPagesToPreload = -1)
        {
            if (numPagesToPreload != -1)
            {
                var head = (GetPage(untilAddress) - numPagesToPreload) << LogPageSizeBits;
                if (head > headAddress)
                {
                    headAddress = head;
                }
            }
            Debug.Assert(beginAddress <= headAddress);
            Debug.Assert(headAddress <= untilAddress);

            // Special cases: we do not load any records into memory
            if (
                (beginAddress == untilAddress) ||                                      // Empty log
                ((headAddress == untilAddress) && (GetOffsetInPage(headAddress) == 0)) // Empty in-memory page
                )
            {
                if (!IsAllocated(GetPageIndexForAddress(headAddress)))
                {
                    AllocatePage(GetPageIndexForAddress(headAddress));
                }
            }
            else
            {
                if (headAddress < fromAddress)
                {
                    var tailPage = GetPage(fromAddress);
                    var headPage = GetPage(headAddress);

                    var recoveryStatus = new RecoveryStatus(GetCapacityNumPages(), headPage, tailPage, untilAddress, 0);
                    for (int i = 0; i < recoveryStatus.capacity; i++)
                    {
                        recoveryStatus.readStatus[i] = ReadStatus.Done;
                    }

                    var numPages = 0;
                    for (var page = headPage; page <= tailPage; page++)
                    {
                        var pageIndex = GetPageIndexForPage(page);
                        recoveryStatus.readStatus[pageIndex] = ReadStatus.Pending;
                        numPages++;
                    }

                    AsyncReadPagesFromDevice(headPage, numPages, untilAddress, AsyncReadPagesCallbackForRecovery, recoveryStatus);

                    for (long page = headPage; page <= tailPage; page++)
                    {
                        recoveryStatus.WaitRead(GetPageIndexForPage(page));
                    }
                }
            }

            RecoveryReset(untilAddress, headAddress, beginAddress, untilAddress);
        }
Beispiel #4
0
        /// <summary>
        /// Restore log
        /// </summary>
        /// <param name="untilAddress"></param>
        /// <param name="headAddress"></param>
        /// <param name="beginAddress"></param>
        public void RestoreHybridLog(long untilAddress, long headAddress, long beginAddress)
        {
            Debug.Assert(beginAddress <= headAddress);
            Debug.Assert(headAddress <= untilAddress);

            // Special cases: we do not load any records into memory
            if (
                (beginAddress == untilAddress) ||                                      // Empty log
                ((headAddress == untilAddress) && (GetOffsetInPage(headAddress) == 0)) // Empty in-memory page
                )
            {
                if (!IsAllocated(GetPageIndexForAddress(headAddress)))
                {
                    AllocatePage(GetPageIndexForAddress(headAddress));
                }
            }
            else
            {
                var tailPage = GetPage(untilAddress);
                var headPage = GetPage(headAddress);

                var recoveryStatus = new RecoveryStatus(GetCapacityNumPages(), headPage, tailPage, untilAddress);
                for (int i = 0; i < recoveryStatus.capacity; i++)
                {
                    recoveryStatus.readStatus[i] = ReadStatus.Done;
                }

                var numPages = 0;
                for (var page = headPage; page <= tailPage; page++)
                {
                    var pageIndex = GetPageIndexForPage(page);
                    recoveryStatus.readStatus[pageIndex] = ReadStatus.Pending;
                    numPages++;
                }

                AsyncReadPagesFromDevice(headPage, numPages, untilAddress, AsyncReadPagesCallbackForRecovery, recoveryStatus);

                var done = false;
                while (!done)
                {
                    done = true;
                    for (long page = headPage; page <= tailPage; page++)
                    {
                        int pageIndex = GetPageIndexForPage(page);
                        if (recoveryStatus.readStatus[pageIndex] == ReadStatus.Pending)
                        {
                            done = false;
                            break;
                        }
                    }
                }
            }

            RecoveryReset(untilAddress, headAddress, beginAddress);
        }
Beispiel #5
0
 public ClusteredRecoveryJobState(string identifier)
 {
     if (!string.IsNullOrEmpty(identifier))
     {
         _identifier = identifier;
     }
     _jobList            = new List <ShardRecoveryJobState>();
     _status             = RecoveryStatus.uninitiated;
     _message            = string.Empty;
     _percentage         = 0;
     base.SubmissionTime = DateTime.Now;
 }
Beispiel #6
0
 public RecoveryJobStateBase(string identifier, string name)
 {
     if (!string.IsNullOrEmpty(identifier))
     {
         _submissionTime = DateTime.Now;
         _identifier     = identifier;
         _status         = RecoveryStatus.uninitiated;
         if (!string.IsNullOrEmpty(name))
         {
             _entityName = name;
         }
         else
         {
             throw new ArgumentNullException();
         }
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Beispiel #7
0
        public void SubmitConfigChanged(object changeConfig)
        {
            try
            {
                bool failed = true;;
                // get all clustered jobs working on given config
                foreach (ClusterRecoveryJob job in _runningClusteredJobMap.Values)
                {
                    if (job.ActiveConfig.JobType == RecoveryJobType.Restore || job.ActiveConfig.JobType == RecoveryJobType.ConfigRestore)
                    {
                        string db = string.Empty;
                        // check if exception or actual data
                        if (changeConfig is RecoveryOperationStatus)
                        {
                            RecoveryOperationStatus status = (RecoveryOperationStatus)changeConfig;
                            string[] splitString           = status.JobIdentifier.Split('_');
                            if (!string.IsNullOrEmpty(splitString[1]))
                            {
                                db = splitString[1];
                            }
                            else
                            {
                                db = splitString[0];
                            }
                        }

                        if (changeConfig is CsBackupableEntities)
                        {
                            CsBackupableEntities entity = (CsBackupableEntities)changeConfig;
                            db     = entity.Database.First().Key.ToLower();
                            failed = false;
                        }

                        KeyValuePair <string, string> dbMap = job.ActiveConfig.DatabaseMap.First();

                        bool valid = false;
                        if (!string.IsNullOrEmpty(dbMap.Value))
                        {
                            if (dbMap.Value.ToLower().Equals(db))
                            {
                                valid = true;
                            }
                        }
                        else
                        {
                            if (dbMap.Key.ToLower().Equals(db))
                            {
                                valid = true;
                            }
                        }

                        if (valid && !failed)
                        {
                            RecoveryConfiguration config = new RecoveryConfiguration();
                            config.Identifier = job.JobIdentifier;
                            RecoveryStatus state = (job.CurrentState(config) as ClusteredRecoveryJobState).Status;

                            if (state != RecoveryStatus.Failure || state != RecoveryStatus.Cancelled || state != RecoveryStatus.Completed)
                            {
                                if (changeConfig != null)
                                {
                                    job.SubmitConfigChanged(changeConfig);
                                }
                                else
                                {
                                    if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                                    {
                                        LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", "failing");
                                    }
                                    job.Cancel(config);// job has failed
                                    // remove job from active config
                                    RemoveRunningJob(config.Identifier);
                                    break;
                                }
                            }
                        }
                        else if (failed)
                        {
                            RecoveryConfiguration config = new RecoveryConfiguration();
                            config.Identifier = job.JobIdentifier;
                            if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                            {
                                LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", "overall failure");
                            }
                            job.Cancel(config);
                            // remove job from active config
                            RemoveRunningJob(config.Identifier);
                            break;
                        }
                        //job.
                    }
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", ex.ToString());
                }
            }
        }
 public RecoveryOperationStatus(RecoveryStatus status)
 {
     this._status = status;
 }