// libeasy copy packet BasePacket* BasePacketStreamer::clone_packet(BasePacket* src) { int32_t pcode = src->getPCode(); int64_t length = src->length(); BasePacket* dest = dynamic_cast<BasePacket*>(_factory->createPacket(pcode)); assert(NULL != dest); // Stream stream(length); dest->stream_.expand(length); int ret = src->serialize(dest->stream_); if (TFS_SUCCESS == ret) { ret = dest->deserialize(dest->stream_); } TBSYS_LOG_DW(ret, "clone packet, ret=%d, pcode=%d, length=%ld, src=%p, dest=%p", ret, pcode, length, src, dest); if (TFS_SUCCESS != ret) { tbsys::gDelete(dest); dest = NULL; } else { dest->setChannelId(src->getChannelId()); dest->set_request(src->get_request()); dest->set_direction(src->get_direction()); } return dest; }
void LeaseManager::process_renew_response(DsRenewLeaseResponseMessage* response, const int32_t who) { assert(NULL != response); bool ns_switch = update_global_config(who, response->get_lease_meta()); if (ns_switch) { get_writable_block_manager().expire_all_blocks(); } if (NS_ROLE_MASTER == lease_meta_[who].ns_role_ && !ns_switch) { ArrayHelper<BlockLease> leases(response->get_size(), response->get_block_lease(), response->get_size()); for (int index = 0; index < response->get_size(); index++) { BlockLease& lease = *leases.at(index); if (TFS_SUCCESS == lease.result_) { WritableBlock* block = get_writable_block_manager().get(lease.block_id_); if (NULL != block) { // update replica information ArrayHelper<uint64_t> helper(lease.size_, lease.servers_, lease.size_); block->set_servers(helper); } } else // move to expired list { get_writable_block_manager().expire_one_block(lease.block_id_); TBSYS_LOG(INFO, "expire block %"PRI64_PREFIX"u because renew fail, ret: %d", lease.block_id_, lease.result_); } TBSYS_LOG_DW(lease.result_, "renew block %"PRI64_PREFIX"u, replica: %d, ret: %d", lease.block_id_, lease.size_, lease.result_); } } }