TFS Source Resolution Eight

Source: Internet
Author: User
Tags nameserver

The Layout_manager.cpp in the nameserver


#include <time.h>//

#include <iostream>//

#include <functional>//

#include <numeric>//

#include <math.h>//

#include <tbsys.h>//

#include <memory.hpp>//

#include "ns_define.h"

#include "Nameserver.h"

#include "Layout_manager.h"

#include "global_factory.h"//

#include "Common/error_msg.h"

#include "Common/base_packet.h"

#include "common/base_service.h"

#include "common/status_message.h"

#include "Common/client_manager.h"

#include "Common/array_helper.h"

#include "message/block_info_message.h"//

#include "message/replicate_block_message.h"

#include "message/compact_block_message.h"

using namespace Tfs::common;

using namespace Tfs::message;

using namespace Tbsys;

Namespace TFS

{

namespace NameServer

{

Layoutmanager::layoutmanager (nameserver& Manager):

Build_plan_thread_ (0),

Run_plan_thread_ (0),

Check_dataserver_thread_ (0),

Add_block_in_all_server_thread_ (0),

Check_dataserver_report_block_thread_ (0),

Balance_thread_ (0),

Timeout_thread_ (0),

Redundant_thread_ (0),

Load_family_info_thread_ (0),

Last_rotate_log_time_ (0),

Plan_run_flag_ (Plan_run_flag_replicate),

Manager_ (manager),

Block_manager_ (*this),

Server_manager_ (*this),

Task_manager_ (*this),

Oplog_sync_mgr_ (*this),

Client_request_server_ (*this),

Gc_manager_ (*this),

Family_manager_ (*this)

{

Srand (Time (NULL));

Tzset ();

ZONESEC_ = 86400 + timezone;

last_rotate_log_time_ = 0;

Plan_run_flag_ |= Plan_run_flag_move;

Plan_run_flag_ |= plan_run_flag_compact;

Plan_run_flag_ |= plan_run_falg_marshalling;

Plan_run_flag_ |= plan_run_falg_reinstate;

Plan_run_flag_ |= Plan_run_falg_dissolve;

}

Layoutmanager::~layoutmanager ()

{

Build_plan_thread_ = 0;

Run_plan_thread_ = 0;

Check_dataserver_thread_ = 0;

Add_block_in_all_server_thread_ = 0;

Check_dataserver_report_block_thread_ = 0;

Balance_thread_ = 0;

Timeout_thread_ = 0;

Redundant_thread_ = 0;

Load_family_info_thread_ = 0;

}

int Layoutmanager::initialize ()

{

int32_t ret = oplog_sync_mgr_.initialize ();

if (tfs_success!= ret)

{

Tbsys_log (ERROR, "Initialize Oplog Sync Manager fail, must be exit, ret:%d", ret);

}

Else

{

Thread initialization

Build_plan_thread_ = new Buildplanthreadhelper (*this);

Check_dataserver_thread_ = new Checkdataserverthreadhelper (*this);

Run_plan_thread_ = new Runplanthreadhelper (*this);

Add_block_in_all_server_thread_ = new Addblockinallserverthreadhelper (*this);

Check_dataserver_report_block_thread_ = new Checkdataserverreportblockthreadhelper (*this);

Run_plan_thread_ = new Runplanthreadhelper (*this);

Balance_thread_ = new Buildbalancethreadhelper (*this);

Timeout_thread_ = new Timeoutthreadhelper (*this);

redundant_thread_= new Redundantthreadhelper (*this);

Load_family_info_thread_ = new Loadfamilyinfothreadhelper (*this);

}

return ret;

}

void Layoutmanager::wait_for_shut_down ()//thread exits join

{

if (build_plan_thread_!= 0)

{

Build_plan_thread_->join ();

}

if (check_dataserver_thread_!= 0)

{

Check_dataserver_thread_->join ();

}

if (run_plan_thread_!= 0)

{

Run_plan_thread_->join ();

}

if (add_block_in_all_server_thread_!= 0)

{

Add_block_in_all_server_thread_->join ();

}

if (check_dataserver_report_block_thread_!= 0)

{

Check_dataserver_report_block_thread_->join ();

}

if (balance_thread_!= 0)

{

Balance_thread_->join ();

}

if (timeout_thread_!= 0)

{

Timeout_thread_->join ();

}

if (redundant_thread_!= 0)

{

Redundant_thread_->join ();

}

if (load_family_info_thread_!= 0)

{

Load_family_info_thread_->join ();

}

Oplog_sync_mgr_.wait_for_shut_down ();

}

void LayoutManager::d Estroy ()

{

Oplog_sync_mgr_.destroy ();

}

/**

* Dsataserver start, send heartbeat message to nameserver.

* Update all relations of the blocks belongs to it

* @param [in] dsinfo:dataserver system info, like capacity, load, etc.

* @param [in] blocks:data blocks ' info which belongs to DataServer.

* @param [out] expires:need expire blocks

* @return Success or failure

*/

int Layoutmanager::update_relation (std::vector<uint32_t>& expires, servercollect* server,

Const std::set<blockinfoext>& blocks, const time_t Now, const int8_t type)

{

int32_t ret = ((NULL!= server) && (server->is_alive ()))? Tfs_success:exit_parameter_error;

if (tfs_success = ret)

{

ret = Get_block_manager (). Update_relation (expires, server, blocks, now, type);

}

return ret;

}

int Layoutmanager::build_relation (blockcollect* block, servercollect* server, const time_t now, const BOOL set)

{

int32_t ret = ((null!= block) && (null!= server))? Tfs_success:exit_parameter_error;

if (tfs_success = ret)

{

BOOL writable = FALSE;

BOOL Master = false;

ret = Get_block_manager (). Build_relation (blocks, writable, Master, Server->id (), now, set);

if (tfs_success = ret)

{

ret = Get_server_manager (). Build_relation (server, Block->id (), writable, master);

}

}

return ret;

}

BOOL Layoutmanager::relieve_relation (blockcollect* block, servercollect* server, time_t now)

{

int32_t result = Tfs_error;

int32_t ret

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.