public override void QueryPartitionHealthHandler(ErrnoResponseWriter response)
 {
     if ((m_memorycloud as DynamicMemoryCloud).m_healthmon.IsPartitionHealthy())
     {
         response.errno = Errno.E_OK;
     }
     else
     {
         response.errno = Errno.E_FAIL;
     }
 }
        public override void PersistedUploadHandler(PersistedSliceReader request, ErrnoResponseWriter response)
        {
            var dmc      = DynamicMemoryCloud.Instance;
            var uploader = dmc.m_persistent_storage.Upload(request.version, dmc.MyPartitionId, request.lowkey, request.highkey).Result;
            var chunks   = new[] { new ChunkInformation {
                                       lowKey = request.lowkey, highKey = request.highkey, id = request.version
                                   } };
            var thres   = DynamicClusterConfig.Instance.PersistedChunkSizeThreshold;
            var tx_rsps = Global.LocalStorage
                          .Where(cell => _Covered(chunks, cell.CellId))
                          .Segment(thres, cell => cell.CellSize + sizeof(long) + sizeof(int) + sizeof(ushort))
                          .Select(_ => _Upload(_, uploader, thres));

            Task.WhenAll(tx_rsps).Wait();

            response.errno = Errno.E_OK;
        }
        public override void PersistedDownloadHandler(PersistedSliceReader request, ErrnoResponseWriter response)
        {
            var dmc        = DynamicMemoryCloud.Instance;
            var downloader = dmc.m_persistent_storage.Download(request.version, dmc.MyPartitionId, request.lowkey, request.highkey).Result;
            Task <IPersistentDataChunk> dtask = downloader.DownloadAsync();

            while (true)
            {
                var data = dtask?.Result;
                if (data == null)
                {
                    break;              //fetched null from a task, EOF
                }
                // start new download while we load it into memory storage
                var ndtask = downloader.DownloadAsync();
                foreach (var cell in data)
                {
                    Global.LocalStorage.SaveCell(cell.CellId, cell.Buffer, cell.Offset, cell.Length, cell.CellType);
                }
                dtask = ndtask;
            }

            response.errno = Errno.E_OK;
        }
        public override void ReplicationHandler(ReplicationTaskInformationReader request, ErrnoResponseWriter response)
        {
            var chunks = request.range.Cast <ChunkInformation>().ToList();

            chunks.Sort((x, y) => Math.Sign(x.lowKey - y.lowKey));
            var target_replica = (Guid)request.to.id;
            var task_id        = (Guid)request.task_id;
            var thres          = DynamicClusterConfig.Instance.BatchSaveSizeThreshold;
            var to_storage     = DynamicMemoryCloud.Instance.MyPartition.OfType <DynamicRemoteStorage>()
                                 .First(_ => _.ReplicaInformation.Id == target_replica);
            var signal_c = new SemaphoreSlim(4);
            var signal_t = new ManualResetEventSlim(false);

            //TODO timeout
            var batch_rsps = Global.LocalStorage
                             .Where(cell => _Covered(chunks, cell.CellId))
                             .Segment(thres, cell => cell.CellSize + sizeof(long) + sizeof(int) + sizeof(ushort))
                             .Select(_ => _BuildBatch(_, task_id))
                             .Select(_ => _SendBatch(_, to_storage, signal_c, signal_t));

            Task.WhenAll(batch_rsps).Wait();

            response.errno = Errno.E_OK;
        }
 public override void QueryReplicaHealthHandler(ErrnoResponseWriter response)
 {
     response.errno = Errno.E_OK;
 }
 public override void PersistedSavePartitionHandler(BackupTaskInformationReader request, ErrnoResponseWriter response)
 {
     try
     {
         (m_memorycloud as DynamicMemoryCloud).m_backupctl.BackupCurrentPartition(request.task_id, request.version, EventArgs.Empty).Wait();
         response.errno = Errno.E_OK;
     }
     catch
     {
         response.errno = Errno.E_FAIL;
     }
 }
 public override void AnnounceMasterHandler(StorageInformationReader request, ErrnoResponseWriter response)
 {
     (m_memorycloud as DynamicMemoryCloud).m_cloudidx.SetMaster(request.partition, request.id);
     response.errno = Errno.E_OK;
 }
        public override void ShrinkDataHandler(ShrinkDataTaskInformationReader request, ErrnoResponseWriter response)
        {
            var task_id    = (Guid)request.task_id;
            var remove_tgt = request.remove_target.Cast <ChunkInformation>().ToList();
            var to_remove  = Global.LocalStorage
                             .Where(cell => _Covered(remove_tgt, cell.CellId))
                             .Select(cell => cell.CellId).ToList();

            foreach (var cellId in to_remove)
            {
                Global.LocalStorage.RemoveCell(cellId);
            }

            response.errno = Errno.E_OK;
        }