示例#1
0
        /// <summary>
        /// PartitionerProc runs on the leader of each partition.
        /// </summary>
        private async Task PartitionerProc()
        {
            if (!m_namesvc.IsMaster)
            {
                return;
            }
            await Task.WhenAll(
                m_taskqueue.Wait(ReplicatorTask.Guid),
                m_taskqueue.Wait(ShrinkDataTask.Guid),
                m_taskqueue.Wait(PersistedSaveTask.Guid));

            var replica_chunks = m_idx.GetMyPartitionReplicaChunks().ToList();

            if (ClusterInitInProgress(replica_chunks))
            {
                Log.WriteLine($"{nameof(Partitioner)}: waiting for {m_minreplicas} ready replicas to conduct partitioning");
                return;
            }

            if (NeedRepartition(replica_chunks))
            {
                Log.WriteLine($"{nameof(Partitioner)}: Repartition initiated for partition #{m_namesvc.PartitionId}.");
                IEnumerable <ITask> plan = s_planners[m_repmode].Plan(m_minreplicas, replica_chunks);
                // Replication tasks can be done in parallel, and shrink tasks too.
                // However, together they form a multi-stage task -- no shrink task should happen
                // before all rep tasks are done.
                var rep_tasks = plan.OfType <ReplicatorTask>();
                var shr_tasks = plan.OfType <ShrinkDataTask>();
                var chain     = new List <ITask>();

                var repTasks = rep_tasks.ToList();

                if (repTasks.Any())
                {
                    chain.Add(new GroupedTask(repTasks, ReplicatorTask.Guid));
                }

                var shrinkDataTasks = shr_tasks.ToList();

                if (shrinkDataTasks.Any())
                {
                    chain.Add(new GroupedTask(shrinkDataTasks, ShrinkDataTask.Guid));
                }

                bool any = chain.Any();

                if (!any)
                {
                    return;
                }

                var ctask = new ChainedTasks(chain, ReplicatorTask.Guid);

                await m_taskqueue.PostTask(ctask);

                return;
            }

            //TODO load balance
        }
示例#2
0
        internal async Task RestoreCurrentPartition(Guid task_id, Guid version, EventArgs e)
        {
            var downloader = await m_pstore.Download(version, m_namesvc.PartitionId, 0, 0);

            await m_backupmgr.Restore(downloader, e);

            // After the backup manager finishes state restoration, chunk tables,
            // name service, pending tasks should be all restored. Thus we load
            // chunks into replicas as per described by the chunk table.

            List <PersistedLoadTask> passive_tasks = new List <PersistedLoadTask>();
            var cts = m_dmc.m_cloudidx.GetMyPartitionReplicaChunks();

            foreach (var(rep, cks) in cts)
            {
                passive_tasks.Add(new PersistedLoadTask(cks
                                                        .Select(ck => (rep, new PersistedSlice(version, ck.LowKey, ck.HighKey)))));
            }
            GroupedTask gt = new GroupedTask(passive_tasks, task_id);
            await m_taskqueue.PostTask(gt);

            await m_taskqueue.Wait(task_id);
        }