TFS源码解析五

10 篇文章 0 订阅

NameServer中ns_define.h

#ifndef TFS_NAMESERVER_DEFINE_H_

#define TFS_NAMESERVER_DEFINE_H_

 

#include <Mutex.h> //信号量头文件

#include <tbsys.h> //tfs依赖的tbsys头文件

#include "common/internal.h" //基础数据结构定义头文件

#include "common/func.h" //基础函数头文件

#include "common/lock.h" //封装后的读写锁头文件

#include "common/parameter.h" //定义各个Server参数头文件

#include "common/new_client.h" //客户端信息头文件

#include "common/array_helper.h" //封装数组操作头文件

 

namespace tfs

{

  namespace nameserver

  {

    enum NsRole //NameServer主备角色

    {

      NS_ROLE_NONE = 0x00,

      NS_ROLE_MASTER,

      NS_ROLE_SLAVE

    };

 

    enum NsStatus //NameServer初始化状态

    {

      NS_STATUS_NONE = -1,

      NS_STATUS_UNINITIALIZE = 0x00,

      NS_STATUS_INITIALIZED

    };

 

    enum NsSwitchFlag //NameServer主备切换标记

    {

      NS_SWITCH_FLAG_NO = 0x00,

      NS_SWITCH_FLAG_YES

    };

 

    enum ReportBlockStatus //NameServer处理Block的状态

    {

      REPORT_BLOCK_STATUS_NONE = 0x0,

      REPORT_BLOCK_STATUS_IN_REPORT_QUEUE,

      REPORT_BLOCK_STATUS_REPORTING,

      REPORT_BLOCK_STATUS_COMPLETE

    };

 

    enum HandleDeleteBlockFlag //删除Block数据和关系标记

    {

      HANDLE_DELETE_BLOCK_FLAG_BOTH = 1,

      HANDLE_DELETE_BLOCK_FLAG_ONLY_RELATION = 2

    };

 

    enum NsKeepAliveType //NameServer保活类型

    {

      NS_KEEPALIVE_TYPE_LOGIN = 0,

      NS_KEEPALIVE_TYPE_RENEW = 1,

      NS_KEEPALIVE_TYPE_LOGOUT = 2

    };

 

    enum BlockInReplicateQueueFlag //Block在复制队列标记

    {

      BLOCK_IN_REPLICATE_QUEUE_NO  = 0,

      BLOCK_IN_REPLICATE_QUEUE_YES = 1

    };

 

    enum FamilyInReinstateOrDissolveQueueFlag //Family在恢复队列标记

    {

      FAMILY_IN_REINSTATE_OR_DISSOLVE_QUEUE_NO = 0,

      FAMILY_IN_REINSTATE_OR_DISSOLVE_QUEUE_YES = 1

    };

 

    enum BlockCompareServerFlag //Block信息中比较Server使用的索引标记

    {

      BLOCK_COMPARE_SERVER_BY_ID = 0,

      BLOCK_COMPARE_SERVER_BY_POINTER = 1,

      BLOCK_COMPARE_SERVER_BY_ID_POINTER = 2

    };

 

    class LayoutManager;

    class GCObject //NameServer中数据的基类,定义最后更新的时间

    {

    public:

      explicit GCObject(const time_t now): //explicit显示的构造函数

        last_update_time_(now) {}

      virtual ~GCObject() {}

      virtual void callback(LayoutManager& ) {}

      inline void free(){ delete this;}

      inline time_t get_last_update_time() const { return last_update_time_;}

      inline void update_last_time(const time_t now = common::Func::get_monotonic_time()) { last_update_time_ = now;}

      inline bool can_be_clear(const time_t now) const

      {

        return now >= (last_update_time_ + common::SYSPARAM_NAMESERVER.object_clear_max_time_);

      }

      inline bool can_be_free(const time_t now) const

      {

        return now >= (last_update_time_ + common::SYSPARAM_NAMESERVER.object_dead_max_time_);

      }

    protected:

      time_t last_update_time_; //最后的更新时间

    };

    

    //NameServer统计信息

    struct NsGlobalStatisticsInfo : public common::RWLock

    {

      NsGlobalStatisticsInfo();

      NsGlobalStatisticsInfo(uint64_t use_capacity, uint64_t totoal_capacity, 

uint64_t total_block_count, int32_t total_load,

          int32_t max_load, int32_t max_block_count, 

int32_t alive_server_count);

      void update(const common::DataServerStatInfo& info, const bool is_new = true);

      void update(const NsGlobalStatisticsInfo& info);

      //全局唯一实例

      static NsGlobalStatisticsInfo& instance();

      void dump(int32_t level, const char* file = __FILE__, const int32_t line = __LINE__, const char* function = __FUNCTION__) const;

      volatile int64_t use_capacity_;

      volatile int64_t total_capacity_;

      volatile int64_t total_block_count_;

      int32_t total_load_;

      int32_t max_load_;

      int32_t max_block_count_;

      volatile int32_t alive_server_count_;

      static NsGlobalStatisticsInfo instance_;

    };

    //NameServer运行信息

    struct NsRuntimeGlobalInformation

    {

      uint64_t owner_ip_port_;

      uint64_t peer_ip_port_;

      int64_t switch_time_;

      int64_t discard_newblk_safe_mode_time_;

      int64_t lease_id_;

      int64_t lease_expired_time_;

      int64_t startup_time_;

      uint32_t vip_;

      bool destroy_flag_;

      int8_t owner_role_;

      int8_t peer_role_;

      int8_t owner_status_;

      int8_t peer_status_;

 

      bool is_destroyed() const;

      bool in_safe_mode_time(const int64_t now) const;

      bool in_discard_newblk_safe_mode_time(const int64_t now) const;

      bool is_master() const;

      bool peer_is_master() const;

      int keepalive(int64_t& lease_id, const uint64_t server,

                      const int8_t role, const int8_t status, 

const int8_t type, const time_t now);

      bool logout();

      bool has_valid_lease(const time_t now) const;

      bool renew(const int32_t step, const time_t now);

      bool renew(const int64_t lease_id, const int32_t step, const time_t now);

      void switch_role(const bool startup = false,

 const int64_t now = common::Func::get_monotonic_time());

      void update_peer_info(const uint64_t server, const int8_t role,

 const int8_t status);

      bool own_is_initialize_complete() const;

      void initialize();

      void destroy();

      void dump(const int32_t level, const char* file, const int32_t line,

                 const char* function, const char* format, ...);

      NsRuntimeGlobalInformation();

      static NsRuntimeGlobalInformation& instance();

      static NsRuntimeGlobalInformation instance_;

    };

 

    //相关最大值定义

static const int32_t THREAD_STATCK_SIZE = 16 * 1024 * 1024;

    static const int32_t MAX_SERVER_NUMS = 3000;

    static const int32_t MAX_PROCESS_NUMS = MAX_SERVER_NUMS * 12;

    //static const int32_t MAX_BLOCK_CHUNK_NUMS = 512;

    static const int32_t MAX_BLOCK_CHUNK_NUMS = 10240 * 4;

    static const int32_t MAX_REPLICATION = 64;

    static const int32_t MAX_WRITE_FILE_COUNT = 256;

 

    static const uint64_t GB = 1 * 1024 * 1024 * 1024;

    static const uint64_t MB = 1 * 1024 * 1024;

    static const double PERCENTAGE_MIN = 0.000001;

    static const double PERCENTAGE_MAX = 1.000000;

    static const double PERCENTAGE_MAGIC = 1000000.0;

double calc_capacity_percentage(const uint64_t capacity,

 const uint64_t total_capacity);

 

    static const int32_t MAX_POP_SERVER_FROM_DEAD_QUEUE_LIMIT = 5;

 

    static const int32_t MAX_RACK_NUM = 512;

    static const int32_t MAX_SINGLE_RACK_SERVER_NUM = 64;

    static const int32_t MAX_MARSHLLING_QUEUE_ELEMENT_SIZE = 128; //编组队列大小

    static const int32_t MAX_FAMILY_CHUNK_NUM = 1024;//

 

    static const int32_t MAX_TASK_RESERVE_TIME = 5;

 

    class BlockCollect;

    class ServerCollect;

 

    extern int ns_async_callback(common::NewClient* client);

extern std::string& print_servers(

const common::ArrayHelper<ServerCollect*>&servers,

              std::string& result);

    extern void print_servers(const common::ArrayHelper<uint64_t>&servers, std::string& result);

extern void print_servers(const std::vector<uint64_t>& servers, 

std::string& result);

extern void print_blocks(const std::vector<uint32_t>& blocks, 

std::string& result);

 }/** nameserver **/

}/** tfs **/

 

#endif


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值