Exemplo n.º 1
0
        public async Task UpdateDirectoryResult(string databaseName, string error)
        {
            var drivesInfo    = PlatformDetails.RunningOnPosix ? DriveInfo.GetDrives() : null;
            var driveInfo     = DiskSpaceChecker.GetDriveInfo(_path, drivesInfo, out var realPath);
            var diskSpaceInfo = DiskSpaceChecker.GetDiskSpaceInfo(driveInfo.DriveName);

            if (CanAccessPath(_path, out var pathAccessError) == false)
            {
                error = pathAccessError;
            }

            var currentNodeInfo = new SingleNodeDataDirectoryResult
            {
                NodeTag           = _serverStore.NodeTag,
                FullPath          = realPath,
                FreeSpaceInBytes  = diskSpaceInfo?.TotalFreeSpace.GetValue(SizeUnit.Bytes) ?? 0,
                FreeSpaceHumane   = diskSpaceInfo?.TotalFreeSpace.ToString(),
                TotalSpaceInBytes = diskSpaceInfo?.TotalSize.GetValue(SizeUnit.Bytes) ?? 0,
                TotalSpaceHumane  = diskSpaceInfo?.TotalSize.ToString(),
                Error             = error
            };



            if (_getNodesInfo == false)
            {
                // write info of a single node
                using (_serverStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                    using (var writer = new BlittableJsonTextWriter(context, _responseBodyStream))
                    {
                        context.Write(writer, currentNodeInfo.ToJson());
                    }

                return;
            }

            var clusterTopology = _serverStore.GetClusterTopology();
            var relevantNodes   = GetRelevantNodes(databaseName, clusterTopology);

            var dataDirectoryResult = new DataDirectoryResult();

            dataDirectoryResult.List.Add(currentNodeInfo);

            if (relevantNodes.Count > 1)
            {
                await UpdateNodesDirectoryResult(relevantNodes, clusterTopology, dataDirectoryResult);
            }

            using (_serverStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, _responseBodyStream))
                {
                    context.Write(writer, dataDirectoryResult.ToJson());
                }
        }
Exemplo n.º 2
0
        private async Task UpdateNodesDirectoryResult(IEnumerable <string> nodes, ClusterTopology clusterTopology, DataDirectoryResult dataDirectoryResult)
        {
            var tasks = new List <Task <SingleNodeDataDirectoryResult> >();

            foreach (var nodeTag in nodes)
            {
                _serverStore.ServerShutdown.ThrowIfCancellationRequested();

                if (nodeTag.Equals(_serverStore.NodeTag, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var serverUrl = clusterTopology.GetUrlFromTag(nodeTag);
                if (serverUrl == null)
                {
                    continue;
                }

                tasks.Add(Task.Run(async() =>
                {
                    var singleNodeResult = await GetSingleNodeDataDirectoryInfo(serverUrl);
                    return(singleNodeResult);
                }, _serverStore.ServerShutdown));
            }

            await Task.WhenAll(tasks);

            foreach (var task in tasks)
            {
                if (task.IsCompletedSuccessfully == false)
                {
                    continue;
                }

                var singleNodeResult = await task;
                if (singleNodeResult == null)
                {
                    continue;
                }

                dataDirectoryResult.List.Add(singleNodeResult);
            }
        }