Ejemplo n.º 1
0
        public static void init(string conf_filename)
        {
            IniFileReader iniReader;

            string[] szTrackerServers;
            string[] parts;

            iniReader = new IniFileReader(conf_filename);

            g_connect_timeout = iniReader.getIntValue("connect_timeout", DEFAULT_CONNECT_TIMEOUT);
            if (g_connect_timeout < 0)
            {
                g_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
            }
            g_connect_timeout *= 1000; //millisecond

            g_network_timeout = iniReader.getIntValue("network_timeout", DEFAULT_NETWORK_TIMEOUT);
            if (g_network_timeout < 0)
            {
                g_network_timeout = DEFAULT_NETWORK_TIMEOUT;
            }
            g_network_timeout *= 1000; //millisecond

            g_charset = iniReader.getStrValue("charset");
            if (g_charset == null || g_charset.Length == 0)
            {
                g_charset = "ISO8859-1";
            }

            szTrackerServers = iniReader.getValues("tracker_server");
            if (szTrackerServers == null)
            {
                throw new MyException("item \"tracker_server\" in " + conf_filename + " not found");
            }

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

                tracker_servers[i] = new IPEndPoint(IPAddress.Parse(parts[0].Replace("\0", "").Trim()), int.Parse(parts[1].Replace("\0", "").Trim()));
            }
            g_tracker_group = new TrackerGroup(tracker_servers);

            g_tracker_http_port = iniReader.getIntValue("http.tracker_http_port", 80);
            g_anti_steal_token  = iniReader.getBoolValue("http.anti_steal_token", false);
            if (g_anti_steal_token)
            {
                g_secret_key = iniReader.getStrValue("http.secret_key");
            }
        }
Ejemplo n.º 2
0
 public static void setG_tracker_group(TrackerGroup tracker_group)
 {
     ClientGlobal.g_tracker_group = tracker_group;
 }
Ejemplo n.º 3
0
 public TrackerClient(TrackerGroup tracker_group)
 {
     this.tracker_group = tracker_group;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// delete a storage server from the FastDFS cluster
        /// </summary>
        /// <param name="trackerGroup">the tracker server group</param>
        /// <param name="groupName">the group name of storage server</param>
        /// <param name="storageIpAddr">the storage server ip address</param>
        /// <returns>true for success, false for fail</returns>
        public bool deleteStorage(TrackerGroup trackerGroup, string groupName, string storageIpAddr)
        {
            int           serverIndex;
            int           notFoundCount;
            TrackerServer trackerServer;

            notFoundCount = 0;
            for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.Length; 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].Status == ProtoCommon.FDFS_STORAGE_STATUS_ONLINE ||
                             storageStats[0].Status == 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.Length)
            {
                this.errno = ProtoCommon.ERR_NO_ENOENT;
                return(false);
            }

            notFoundCount = 0;
            for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.Length; serverIndex++)
            {
                try
                {
                    trackerServer = trackerGroup.getConnection(serverIndex);
                }
                catch (IOException ex)
                {
                    Console.WriteLine("connect to server " + trackerGroup.tracker_servers[serverIndex].Address + ":" + trackerGroup.tracker_servers[serverIndex].Port + " fail");
                    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.Length)
            {
                this.errno = ProtoCommon.ERR_NO_ENOENT;
                return(false);
            }

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

            return(this.errno == 0);
        }
Ejemplo n.º 5
0
 public TrackerClient()
 {
     this.tracker_group = ClientGlobal.g_tracker_group;
 }