Ejemplo n.º 1
0
 void ObUpsKeepAlive::renew_keep_alive_time()
 {
   int64_t cur_time_us = tbsys::CTimeUtil::getTime(); 
   TBSYS_LOG(DEBUG, "slave renew keep alive msg. cur_time = %ld, last_keep_alive_time=%ld", cur_time_us, last_keep_alive_time_);
   last_keep_alive_time_ = cur_time_us;
 }
Ejemplo n.º 2
0
    int ObTbnetCallback::encode(easy_request_t *r, void *data)
    {
      int ret = EASY_OK;
      easy_buf_t* b = NULL;
      char* buff = NULL;
      ObPacket* packet = reinterpret_cast<ObPacket*>(data);
      int64_t header_size = 0;
      uint16_t ob_packet_header_size = 0;
#if !defined(_OB_VERSION) || _OB_VERSION<=300
      /* 0.3 ObPacket 头格式: 16 bytes */
      /*         2 bytes                 2 bytes       8 bytes     4 bytes
       *----------------------------------------------------------------------
       *| ob_packet_header_size_== 0 | api_version_ | session_id_ | timeout_ |
       *----------------------------------------------------------------------
       */
      ob_packet_header_size = 0;
      header_size = sizeof(uint16_t)/* ob_packet_header_size_ */ + sizeof(int16_t) /* api_version_ */+ sizeof(int64_t) /* session_id_ */+ sizeof(int32_t)/* timeout_ */;
#elif _OB_VERSION>300
      /* 0.4 ObPacket 头格式: 24 bytes */
      /*         2 bytes            2 bytes       8 bytes     4 bytes   8 bytes     8 bytes
       *--------------------------------------------------------------------------------------
       *| ob_packet_header_size_ | api_version_ | session_id_ | timeout_ |trace_id_|req_sign_|
       *--------------------------------------------------------------------------------------
       */
      ob_packet_header_size = sizeof(ob_packet_header_size) + sizeof(int16_t)/* api_version_ */ + sizeof(int64_t) /* session_id_ */ + sizeof(int32_t)/* timeout_ */ + sizeof(uint64_t)/* trace_id_ */ + sizeof(uint64_t) /* req_sign_ */;
      header_size = ob_packet_header_size;
#endif
      packet->set_ob_packet_header_size(ob_packet_header_size);
      int64_t size = packet->get_inner_buffer()->get_position() + OB_TBNET_HEADER_LENGTH + header_size;
      b = reinterpret_cast<easy_buf_t *>(easy_pool_alloc(r->ms->pool,
                                                          static_cast<uint32_t>(sizeof(easy_buf_t) + size)));
      if (NULL == b)
      {
        TBSYS_LOG(WARN, "alloc mem for send buffer failed buf=%p size is %lu", b,
                  sizeof(easy_buf_t) + size);
        ret = EASY_ERROR;
      }
      else
      {
        //skip sizeof(easy_buf_t) bytes
        buff = reinterpret_cast<char *>(b + 1);
        //b->pos = buff;
        //b->end = buff + size;
        //set packet length
        init_easy_buf(b, buff, r, size);
        packet->set_packet_len(static_cast<int>(
                                 packet->get_inner_buffer()->get_position() + header_size));

        if (false == packet->encode(buff, size))
        {
          ret = EASY_ERROR;
          TBSYS_LOG(WARN, "encode failed packet is %p, buff is %p, size is %ld", packet, buff, size);
        }

        if (EASY_OK == ret)
        {
          easy_buf_set_data(r->ms->pool, b, buff, static_cast<uint32_t>(size));
          easy_request_addbuf(r, b);
          //add rpc bytes out statistics
          OB_STAT_INC(COMMON, RPC_BYTES_OUT, size);
          TBSYS_LOG(DEBUG, "encode packet success packet code is %d, c is %s",packet->get_packet_code(),
                    easy_connection_str(r->ms->c));
        }
      }

      return ret;
    }
Ejemplo n.º 3
0
    int ExpireService::do_clean_task(ReqCleanTaskFromRtsMessage* req_clean_task_msg)
    {
      //we will give a resp to rootserver first,
      //then execute the clean task and report task result to rootserver
      int ret = TFS_SUCCESS;
      int rspret = TFS_SUCCESS;
      if (NULL == req_clean_task_msg)
      {
        ret = EXIT_INVALID_ARGU;
        TBSYS_LOG(ERROR, "ExpireService::req_clean_task fail, ret: %d", ret);
      }

      ExpireTaskInfo::ExpireTaskType task_type;
      int32_t total_es;
      int32_t num_es;
      int32_t note_interval;
      int32_t task_time;
      ExpireTaskInfo task;

      if (TFS_SUCCESS == ret)
      {
        task = req_clean_task_msg->get_task();
        task_type = task.type_;
        total_es = task.alive_total_;
        num_es =  task.assign_no_;
        note_interval = task.note_interval_;
        task_time = task.spec_time_;
        if ((task_type == ExpireTaskInfo::TASK_TYPE_DELETE) &&
            (total_es > 0 && num_es >= 0 && note_interval >= 0) &&
            (num_es < total_es) && task_time > 0)
        {
          TBSYS_LOG(DEBUG, "%d, %d, %d, %d, %d",task_type, total_es, num_es, note_interval, task_time);
          ret = TFS_SUCCESS;
        }
        else
        {
          ret = EXIT_INVALID_ARGU;
          TBSYS_LOG(ERROR, "ExpireService::req_clean_task fail EXIT_INVALID_ARGU, ret: %d", ret);
        }
      }

      if (TFS_SUCCESS != ret)
      {
        rspret = req_clean_task_msg->reply_error_packet(TBSYS_LOG_LEVEL(INFO), ret, "clean is not start");
      }
      else
      {
        rspret = req_clean_task_msg->reply(new StatusMessage(STATUS_MESSAGE_OK));
      }

      if (TFS_SUCCESS == ret)
      {
        //tbutil::Time start = tbutil::Time::now();
        if (ExpireTaskInfo::TASK_TYPE_DELETE == task_type)
        {
          ret = clean_task_helper_.do_clean_task(local_ipport_id_, total_es, num_es, note_interval, task_time);
        }
        //tbutil::Time end = tbutil::Time::now();
        //TBSYS_LOG(INFO, "put_object cost: %"PRI64_PREFIX"d", (int64_t)(end - start).toMilliSeconds());

        // send finish msg
        ReqFinishTaskFromEsMessage req_finish_task_msg;
        //req_finish_task_msg.set_reserve(0);
        req_finish_task_msg.set_es_id(local_ipport_id_);
        req_finish_task_msg.set_task(task);

        NewClient* client = NULL;
        int32_t retry_count = 0;
        int32_t iret = TFS_SUCCESS;
        tbnet::Packet* response = NULL;
        do
        {
          ++retry_count;
          client = NewClientManager::get_instance().create_client();
          iret = send_msg_to_server(expireroot_ipport_id_, client, &req_finish_task_msg, response, MAX_TIMEOUT_MS);
          if (TFS_SUCCESS != iret)
          {
            TBSYS_LOG(ERROR, "EXIT_NETWORK_ERROR ret: %d",iret);
            iret = EXIT_NETWORK_ERROR;
          }
          else if (STATUS_MESSAGE == response->getPCode())
          {
            StatusMessage* resp_status_msg = dynamic_cast<StatusMessage*>(response);
            if ((iret = resp_status_msg->get_status()) != STATUS_MESSAGE_OK)
            {
              TBSYS_LOG(ERROR, "es root return error, ret: %d", ret);
            }
          }
          else
          {
            ret = EXIT_UNKNOWN_MSGTYPE;
            TBSYS_LOG(ERROR, "rsp fail,"
                "server_addr: %s,"
                "ret: %d, msg type: %d",
                tbsys::CNetUtil::addrToString(expireroot_ipport_id_).c_str(), ret, response->getPCode());
          }
          NewClientManager::get_instance().destroy_client(client);
        }while ((retry_count < FINISH_TASK_MAX_RETRY_COUNT)
            && (TFS_SUCCESS != iret));
      }
      return ret;
    }
Ejemplo n.º 4
0
    FIFOAllocator::Page *FIFOAllocator::get_page_(const int64_t require_size, uint64_t &id)
    {
      Page *ret = NULL;
      ThreadNode *thread_node = (ThreadNode*)pthread_getspecific(thread_node_key_);
      if (NULL == thread_node)
      {
        pthread_spin_lock(&thread_node_lock_);
        thread_node = thread_node_allocator_.alloc(sizeof(ThreadNode));
        pthread_spin_unlock(&thread_node_lock_);
        if (NULL != thread_node)
        {
          thread_node->id = UINT64_MAX;
          thread_node->next = NULL;
          int tmp_ret = pthread_setspecific(thread_node_key_, thread_node);
          if (0 != tmp_ret)
          {
            TBSYS_LOG(WARN, "setspecific fail, ret=%d key=%d thread_node=%p",
                tmp_ret, thread_node_key_, thread_node);
          }
          else
          {
            while (true)
            {
              volatile ThreadNode *ov = thread_node_list_;
              thread_node->next = ov;
              if (ov == ATOMIC_CAS(&thread_node_list_, ov, thread_node))
              {
                break;
              }
            }

            int64_t new_thread_num = ATOMIC_ADD(&thread_num_, 1);
            int64_t old_total_limit = total_limit_;
            int64_t new_total_limit = page_size_ * new_thread_num;
            if (new_total_limit > total_limit_
                && old_total_limit == ATOMIC_CAS(&total_limit_, old_total_limit, new_total_limit))
            {
              TBSYS_LOG(WARN, "total_limit cannot support at least one page for each thread, will force to modify total_limit from %ld to %ld",
                  old_total_limit, new_total_limit);
            }
          }
        }
      }
      if (NULL != thread_node)
      {
        Page *tmp_page = NULL;
        id_map_.get(thread_node->id, tmp_page);
        if (NULL != tmp_page
            && page_size_ < (tmp_page->pos + require_size))
        {
          revert_page_(thread_node->id, NULL);
          thread_node->id = UINT64_MAX;
          tmp_page = NULL;
        }
        if (NULL == tmp_page)
        {
          tmp_page = alloc_page_();
          uint64_t tmp_id = UINT64_MAX;
          if (NULL != tmp_page)
          {
            ATOMIC_ADD(&(tmp_page->ref_cnt), 1);
            if (OB_SUCCESS == id_map_.assign(tmp_page, tmp_id))
            {
              thread_node->id = tmp_id;
            }
            else
            {
              TBSYS_LOG(WARN, "assign from id_map_ fail, page=%p", tmp_page);
              free_page_(tmp_page);
              tmp_page = NULL;
            }
          }
        }
        if (NULL != tmp_page
            && page_size_ >= (tmp_page->pos + require_size))
        {
          id = thread_node->id;
          ret = tmp_page;
        }
      }
      return ret;
    }
Ejemplo n.º 5
0
 int PhysicalBlock::dump_block_prefix()
 {
   TBSYS_LOG(DEBUG, "dump block prefix. logic blockid: %u, prev physical blockid: %u, next physical blockid: %u",
       block_prefix_.logic_blockid_, block_prefix_.prev_physic_blockid_, block_prefix_.next_physic_blockid_);
   return file_op_->pwrite_file((const char*) (&block_prefix_), sizeof(BlockPrefix), 0);
 }
Ejemplo n.º 6
0
 void BlockBase::dump() const
 {
   TBSYS_LOG(INFO, "family_id: %"PRI64_PREFIX"d,block_id: %"PRI64_PREFIX"u, version: %d, file_count: %d, size: %d, del_file_count: %d, del_size: %d, copys: %Zd",
       info_.family_id_, info_.block_id_, info_.version_, info_.file_count_, info_.size_, info_.del_file_count_, info_.del_size_, server_list_.size());
 }
Ejemplo n.º 7
0
    int KvMetaService::initialize(int argc, char* argv[])
    {
      int ret = TFS_SUCCESS;
      UNUSED(argc);
      UNUSED(argv);

      if ((ret = SYSPARAM_KVMETA.initialize(config_file_)) != TFS_SUCCESS)
      {
        TBSYS_LOG(ERROR, "call SYSPARAM_METAKVSERVER::initialize fail. ret: %d", ret);
      }
      if (TFS_SUCCESS == ret)
      {
        kv_engine_helper_ = new MysqlEngineHelper(SYSPARAM_KVMETA.conn_str_,
            SYSPARAM_KVMETA.user_name_,
            SYSPARAM_KVMETA.pass_wd_,
            SYSPARAM_KVMETA.pool_size_);
        ret = kv_engine_helper_->init();
      }

      if (TFS_SUCCESS == ret)
      {
        ret = meta_info_helper_.init(kv_engine_helper_);
        if (TFS_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "MetaKv server initial fail: %d", ret);
        }
      }

      if (TFS_SUCCESS == ret)
      {
        ret = life_cycle_helper_.init(kv_engine_helper_);
        if (TFS_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "life cycle initial fail: %d", ret);
        }
      }

      if (TFS_SUCCESS == ret)
      {
        //init global stat
        ret = stat_mgr_.initialize(get_timer());
      }
      if (ret != TFS_SUCCESS)
      {
        TBSYS_LOG(ERROR, "%s", "initialize stat manager fail");
      }
      else
      {
        int64_t current = tbsys::CTimeUtil::getTime();
        StatEntry<string, string>::StatEntryPtr stat_ptr = new StatEntry<string, string>(tfs_kv_meta_stat_, current, false);
        stat_ptr->add_sub_key("put_bucket");
        stat_ptr->add_sub_key("get_bucket");
        stat_ptr->add_sub_key("del_bucket");
        stat_ptr->add_sub_key("head_bucket");
        stat_ptr->add_sub_key("put_object");
        stat_ptr->add_sub_key("get_object");
        stat_ptr->add_sub_key("del_object");
        stat_ptr->add_sub_key("head_object");
        stat_mgr_.add_entry(stat_ptr, SYSPARAM_KVMETA.dump_stat_info_interval_);
      }

      //init heart
      if (TFS_SUCCESS == ret)
      {
        bool ms_ip_same_flag = false;
        ms_ip_same_flag = tbsys::CNetUtil::isLocalAddr(SYSPARAM_KVMETA.ms_ip_port_);

        if (true == ms_ip_same_flag)
        {
          local_ipport_id_ = SYSPARAM_KVMETA.ms_ip_port_;
          kvroot_ipport_id_ = SYSPARAM_KVMETA.rs_ip_port_;
          server_start_time_ = time(NULL);
          ret = heart_manager_.initialize(kvroot_ipport_id_, local_ipport_id_, server_start_time_);
          if (TFS_SUCCESS != ret)
          {
            TBSYS_LOG(ERROR, "init heart_manager error");
          }
          else
          {
            is_inited_ = true;
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "is not local ip ret: %d", ret);
          ret = TFS_ERROR;
        }
      }
      return ret;
    }
Ejemplo n.º 8
0
    bool KvMetaService::handlePacketQueue(tbnet::Packet *packet, void *args)
    {
      int ret = true;
      BasePacket* base_packet = NULL;
      if (!(ret = BaseService::handlePacketQueue(packet, args)))
      {
        TBSYS_LOG(ERROR, "call BaseService::handlePacketQueue fail. ret: %d", ret);
      }
      else
      {
        base_packet = dynamic_cast<BasePacket*>(packet);
        if (!is_inited_)
        {
          ret = EXIT_NOT_INIT_ERROR;
        }
        else
        {
          switch (base_packet->getPCode())
          {
            case REQ_KVMETA_GET_SERVICE_MESSAGE:
              ret = get_service(dynamic_cast<ReqKvMetaGetServiceMessage*>(base_packet));
              break;
            case REQ_KVMETA_PUT_OBJECT_MESSAGE:
              ret = put_object(dynamic_cast<ReqKvMetaPutObjectMessage*>(base_packet));
              break;
            case REQ_KVMETA_GET_OBJECT_MESSAGE:
              ret = get_object(dynamic_cast<ReqKvMetaGetObjectMessage*>(base_packet));
              break;
            case REQ_KVMETA_DEL_OBJECT_MESSAGE:
              ret = del_object(dynamic_cast<ReqKvMetaDelObjectMessage*>(base_packet));
              break;
            case REQ_KVMETA_HEAD_OBJECT_MESSAGE:
              ret = head_object(dynamic_cast<ReqKvMetaHeadObjectMessage*>(base_packet));
              break;
            case REQ_KVMETA_PUT_OBJECT_USER_METADATA_MESSAGE:
              ret = put_object_user_metadata(dynamic_cast<ReqKvMetaPutObjectUserMetadataMessage*>(base_packet));
              break;
            case REQ_KVMETA_DEL_OBJECT_USER_METADATA_MESSAGE:
              ret = del_object_user_metadata(dynamic_cast<ReqKvMetaDelObjectUserMetadataMessage*>(base_packet));
              break;
            case REQ_KVMETA_PUT_BUCKET_MESSAGE:
              ret = put_bucket(dynamic_cast<ReqKvMetaPutBucketMessage*>(base_packet));
              break;
            case REQ_KVMETA_GET_BUCKET_MESSAGE:
              ret = get_bucket(dynamic_cast<ReqKvMetaGetBucketMessage*>(base_packet));
              break;
            case REQ_KVMETA_DEL_BUCKET_MESSAGE:
              ret = del_bucket(dynamic_cast<ReqKvMetaDelBucketMessage*>(base_packet));
              break;
            case REQ_KVMETA_HEAD_BUCKET_MESSAGE:
              ret = head_bucket(dynamic_cast<ReqKvMetaHeadBucketMessage*>(base_packet));
              break;
            case REQ_KVMETA_SET_LIFE_CYCLE_MESSAGE:
              ret = set_file_lifecycle(dynamic_cast<ReqKvMetaSetLifeCycleMessage*>(base_packet));
              break;
            case REQ_KVMETA_GET_LIFE_CYCLE_MESSAGE:
              ret = get_file_lifecycle(dynamic_cast<ReqKvMetaGetLifeCycleMessage*>(base_packet));
              break;
            case REQ_KVMETA_RM_LIFE_CYCLE_MESSAGE:
              ret = rm_file_lifecycle(dynamic_cast<ReqKvMetaRmLifeCycleMessage*>(base_packet));
              break;
            case REQ_KVMETA_PUT_BUCKET_ACL_MESSAGE:
              ret = put_bucket_acl(dynamic_cast<ReqKvMetaPutBucketAclMessage*>(base_packet));
              break;
            case REQ_KVMETA_GET_BUCKET_ACL_MESSAGE:
              ret = get_bucket_acl(dynamic_cast<ReqKvMetaGetBucketAclMessage*>(base_packet));
              break;
            default:
              ret = EXIT_UNKNOWN_MSGTYPE;
              TBSYS_LOG(ERROR, "unknown msg type: %d", base_packet->getPCode());
              break;
          }
        }
      }

      if (ret != TFS_SUCCESS && NULL != base_packet)
      {
        base_packet->reply_error_packet(TBSYS_LOG_LEVEL(INFO), ret, "execute message failed");
      }

      // always return true. packet will be freed by caller
      return true;
    }
void ModifyLoginPasswordReq(RequestPacket* req,
void* args, ResponsePacket* resp) {
    Document req_doc;
/*    Document resp_doc;
    Document::AllocatorType& resp_allocator=resp_doc.GetAllocator();
    StringBuffer resp_buffer;
    Writer<StringBuffer> resp_writer(resp_buffer);
    Value resp_json(kObjectType);
    Value resp_error_msg(kStringType);
*/
    TBSYS_LOG(DEBUG,"-------data:%s",req->data_);
    req_doc.Parse(req->data_);

    //检查account
    if (!req_doc.HasMember("account") 
        || !req_doc["account"].IsString()
        || 0==req_doc["account"].GetStringLength()) {
        SetErrorMsg(20001,"account is invalid",resp);
        return;
    }

    //检查old_password
    if (!req_doc.HasMember("old_password") 
        || !req_doc["old_password"].IsString()
        || 0==req_doc["old_password"].GetStringLength()) {
        SetErrorMsg(20001,"old_password is invalid",resp);
        return;
    }
    
    //检查new_password
    if (!req_doc.HasMember("new_password") 
        || !req_doc["new_password"].IsString()
        || 0==req_doc["new_password"].GetStringLength()) {
        SetErrorMsg(20001,"new_password is invalid",resp);
        return;
    }

    //判断账号是否存在
    RedisClient* rc=g_account_redis->GetRedisClient();
    char cmd[512];
    sprintf(cmd,"EXISTS %s", req_doc["account"].GetString());
    redisReply* reply;
    int cmd_ret=Rexists(rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(20003,"account does not exist",resp);
        return;
    }

    sprintf(cmd,"HGET %s password", req_doc["account"].GetString());
    cmd_ret=Rhget(rc,cmd,reply,false);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {//没有字段password,允许直接设置密码
    } else {
        if (0!=strcmp(req_doc["old_password"].GetString(),reply->str)) {
            g_account_redis->ReleaseRedisClient(rc,true);
            SetErrorMsg(20005,"login password is wrong",resp);
            freeReplyObject(reply);
            return;
        }
    }
    freeReplyObject(reply);
    if (0==strcmp(req_doc["old_password"].GetString(),
                req_doc["new_password"].GetString()) ) {//新密码不变
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(0,"",resp);
        return;
    }

    sprintf(cmd,"HSET %s password %s",
        req_doc["account"].GetString(),
        req_doc["new_password"].GetString());
    cmd_ret=Rhset(rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20006,"modify login password failed,redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE == cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(20006,"modify login password fail",resp);
        return;
    }

    g_account_redis->ReleaseRedisClient(rc,true);
    SetErrorMsg(0,"",resp);
}