示例#1
0
        private static void InitInternal(JObject jsonConfig)
        {
            string[] szTrackerServers;
            string[] parts;

            g_connect_timeout = jsonConfig.Value <int?>("connect_timeout") ?? DEFAULT_CONNECT_TIMEOUT;
            if (g_connect_timeout < 0)
            {
                g_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
            }

            g_connect_timeout *= 1000; //millisecond

            g_network_timeout = jsonConfig.Value <int?>("network_timeout") ?? DEFAULT_NETWORK_TIMEOUT;
            if (g_network_timeout < 0)
            {
                g_network_timeout = DEFAULT_NETWORK_TIMEOUT;
            }

            g_network_timeout *= 1000; //millisecond

            g_charset = jsonConfig.Value <string>("charset") ?? DEFAULT_CHARSET;

            szTrackerServers = jsonConfig["tracker_servers"].Select(s => (string)s).ToArray();
            if (szTrackerServers == null)
            {
                throw new FastDfsException($"item \"tracker_server\" in config file not found");
            }

            var tracker_servers = new IPEndPoint[szTrackerServers.Length];

            for (int i = 0; i < szTrackerServers.Length; i++)
            {
                parts = szTrackerServers[i].Split(':');
                if (parts.Length != 2)
                {
                    throw new FastDfsException(
                              "the value of item \"tracker_server\" is invalid, the correct format is host:port");
                }

                var address = Dns.GetHostAddresses(parts[0]).First();
                tracker_servers[i] = new IPEndPoint(address, int.Parse(parts[1]));
            }

            g_tracker_group = new TrackerGroup(tracker_servers);

            g_tracker_http_port = jsonConfig.Value <int?>("http.tracker_http_port") ?? 80;
            g_anti_steal_token  = jsonConfig.Value <bool?>("http.anti_steal_token") ?? false;
            if (g_anti_steal_token)
            {
                g_secret_key = jsonConfig.Value <string>("http.secret_key") ?? DEFAULT_HTTP_SECRET_KEY;
            }
        }
示例#2
0
        public static void initByTrackers(string trackerServers)
        {
            var list = new List <IPEndPoint>();
            var spr1 = ',';
            var spr2 = ':';
            var arr1 = trackerServers.Trim().Split(spr1);

            foreach (var addrStr in arr1)
            {
                var arr2 = addrStr.Trim().Split(spr2);
                var host = arr2[0].Trim();
                var port = int.Parse(arr2[1].Trim());
                list.Add(new IPEndPoint(IPAddress.Parse(host), port));
            }

            g_tracker_group = new TrackerGroup(list);
        }
示例#3
0
        /**
         * delete a storage server from the FastDFS cluster
         *
         * @param trackerGroup  the tracker server group
         * @param groupName     the group name of storage server
         * @param storageIpAddr the storage server ip address
         * @return true for success, false for fail
         */
        public bool deleteStorage(TrackerGroup trackerGroup,
                                  String groupName, String storageIpAddr)
        {
            int           serverIndex;
            int           notFoundCount;
            TrackerServer trackerServer;

            notFoundCount = 0;
            for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.Count; serverIndex++)
            {
                try
                {
                    trackerServer = trackerGroup.getConnection(serverIndex);
                }
                catch (IOException ex)
                {
                    this.errno = ProtoCommon.ECONNREFUSED;
                    return(false);
                }

                try
                {
                    StructStorageStat[] storageStats = listStorages(trackerServer, groupName, storageIpAddr);
                    if (storageStats == null)
                    {
                        if (this.errno == ProtoCommon.ERR_NO_ENOENT)
                        {
                            notFoundCount++;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (storageStats.Length == 0)
                    {
                        notFoundCount++;
                    }
                    else if (storageStats[0].getStatus() == ProtoCommon.FDFS_STORAGE_STATUS_ONLINE ||
                             storageStats[0].getStatus() == ProtoCommon.FDFS_STORAGE_STATUS_ACTIVE)
                    {
                        this.errno = ProtoCommon.ERR_NO_EBUSY;
                        return(false);
                    }
                }
                finally
                {
                    try
                    {
                        trackerServer.close();
                    }
                    catch (IOException ex1)
                    {
                    }
                }
            }

            if (notFoundCount == trackerGroup.tracker_servers.Count)
            {
                this.errno = ProtoCommon.ERR_NO_ENOENT;
                return(false);
            }

            notFoundCount = 0;
            for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.Count; serverIndex++)
            {
                try
                {
                    trackerServer = trackerGroup.getConnection(serverIndex);
                }
                catch (IOException ex)
                {
                    //System.err.println("connect to server " +
                    //                   trackerGroup.tracker_servers[serverIndex].getAddress().getHostAddress() + ":" +
                    //                   trackerGroup.tracker_servers[serverIndex].getPort() + " fail");
                    //ex.printStackTrace(System.err);
                    this.errno = ProtoCommon.ECONNREFUSED;
                    return(false);
                }

                try
                {
                    if (!this.deleteStorage(trackerServer, groupName, storageIpAddr))
                    {
                        if (this.errno != 0)
                        {
                            if (this.errno == ProtoCommon.ERR_NO_ENOENT)
                            {
                                notFoundCount++;
                            }
                            else if (this.errno != ProtoCommon.ERR_NO_EALREADY)
                            {
                                return(false);
                            }
                        }
                    }
                }
                finally
                {
                    try
                    {
                        trackerServer.close();
                    }
                    catch (IOException ex1)
                    {
                    }
                }
            }

            if (notFoundCount == trackerGroup.tracker_servers.Count)
            {
                this.errno = ProtoCommon.ERR_NO_ENOENT;
                return(false);
            }

            if (this.errno == ProtoCommon.ERR_NO_ENOENT)
            {
                this.errno = 0;
            }

            return(this.errno == 0);
        }
示例#4
0
 /**
  * constructor with specified tracker group
  *
  * @param tracker_group the tracker group object
  */
 public TrackerClient(TrackerGroup tracker_group)
 {
     this.tracker_group = tracker_group;
 }
示例#5
0
 /**
  * constructor with global tracker group
  */
 public TrackerClient()
 {
     this.tracker_group = ClientGlobal.g_tracker_group;
 }
示例#6
0
 public static void setG_tracker_group(TrackerGroup tracker_group)
 {
     ClientGlobal.g_tracker_group = tracker_group;
 }