Beispiel #1
0
 WaitObject* WaitObjectManager::create_wait_object()
 {
   WaitObject* wo = new(std::nothrow) WaitObject();
   if (wo != NULL)
   {
     // create thread buffer
     ThreadSpecificBuffer::Buffer* tb = thread_buffer_->get_buffer();
     if (tb == NULL || tb->used() > 0)
     {
       TBSYS_LOG(ERROR, "get waitobject packet thread buffer failed, buffer %p, used: %d", 
           tb, NULL == tb ? 0 : tb->used());
     }
     else
     {
       char* buf = tb->current();
       wo->response_buffer_ = buf;
       if (!insert_wait_object(wo))
       {
         delete wo;
         wo = NULL;
         TBSYS_LOG(ERROR, "add waitobject into list failed");
       }
       else
       {
         tb->advance(THREAD_BUFFER_ADVANCE_SIZE);
       }
     }
   }
   return wo;
 }
Beispiel #2
0
 void WaitObjectManager::destroy_wait_object(WaitObject*& wait_object)
 {
   if (wait_object != NULL) {
     tbsys::CThreadGuard guard(&mutex_);
     wait_objects_map_.erase(wait_object->seq_id_);
     delete wait_object;
     wait_object = NULL;
     ThreadSpecificBuffer::Buffer* tb = thread_buffer_->get_buffer();
     if (tb != NULL)
     {
       tb->reset();
     }
   }
 }
Beispiel #3
0
    ObPacket* ObPacketQueue::pop()
    {
      if (head_ == NULL)
      {
        return NULL;
      }

      ObPacket* packet = head_;
      ObPacket* ret_packet = NULL;
      head_ = (ObPacket*)head_->_next;
      if (head_ == NULL)
      {
        tail_ = NULL;
      }
      size_ --;

      int err = ring_buffer_.pop_task(packet);
      if (err == OB_SUCCESS)
      {
        ThreadSpecificBuffer::Buffer* tb = thread_buffer_->get_buffer();
        if (tb == NULL)
        {
          TBSYS_LOG(ERROR, "get packet thread buffer failed, return NULL");
        }
        else
        {
          int64_t total_size = sizeof(ObPacket) + packet->get_packet_buffer()->get_capacity();
          char* buf = tb->current();
          memcpy(buf, packet, total_size);
          ret_packet = (ObPacket*)buf;
          buf += sizeof(ObPacket);
          ret_packet->set_packet_buffer(buf, packet->get_packet_buffer()->get_capacity());
        }
      }
      else
      {
        TBSYS_LOG(ERROR, "pop task from ring buffer failed, task: %p, err: %d", packet, err);
      }

      return ret_packet;
    }
    ObMySQLCommandPacket* ObMySQLCommandQueue::pop()
    {
      ObMySQLCommandPacket* ret = NULL;
      if (NULL != head_)
      {
        ObMySQLCommandPacket* packet = head_;
        head_ = reinterpret_cast<ObMySQLCommandPacket*>(head_->next_);
        if (NULL == head_)
        {
          tail_ = NULL;
        }
        size_ --;

        int err = ring_buffer_.pop_task(packet);
        if (OB_SUCCESS == err)
        {
          ThreadSpecificBuffer::Buffer* tb = thread_buffer_->get_buffer();
          if (NULL == tb)
          {
            TBSYS_LOG(ERROR, "get packet thread buffer failed, return NULL");
          }
          else
          {
            //copy packet from ring buffer
            int64_t total_size = sizeof(ObMySQLCommandPacket) + packet->get_command_length();
            TBSYS_LOG(DEBUG, "pop out packet packet command length is %d total size is %ld",
                      packet->get_command_length(), total_size);
            char* buf = tb->current();
            memcpy(buf, packet, total_size);
            ret = reinterpret_cast<ObMySQLCommandPacket*>(buf);
            ret->set_command(buf + sizeof(ObMySQLCommandPacket), packet->get_command_length());
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "pop tack from ring buffer failed, task: %p, err: %d", packet, err);
        }
      }
      return ret;
    }
Beispiel #5
0
int ObTabletJoin::fetch_ups_row(ObGetParam *get_param)
{
  int ret = OB_SUCCESS;
  const ObUpsRow *ups_row = NULL;
  ObString compact_row; //用于存储ObRow的紧缩格式,内存已经分配好
  const ObString *rowkey = NULL;
  ThreadSpecificBuffer::Buffer *buffer = NULL;
  if(NULL == get_param)
  {
    ret = OB_INVALID_ARGUMENT;
    TBSYS_LOG(WARN, "get param is null");
  }

  if(OB_SUCCESS == ret)
  {
    buffer = thread_buffer_.get_buffer();
    if(NULL == buffer)
    {
      ret = OB_ALLOCATE_MEMORY_FAILED;
      TBSYS_LOG(WARN, "get thread specific buffer fail:ret[%d]", ret);
    }
    else
    {
      buffer->reset();
    }
  }

  if(OB_SUCCESS == ret && get_param->get_cell_size() > 0)
  {
    ups_multi_get_->reset();
    ups_multi_get_->set_get_param(*get_param);
    ups_multi_get_->set_row_desc(ups_row_desc_);
    
    if(OB_SUCCESS != (ret = ups_multi_get_->open()))
    {
      TBSYS_LOG(WARN, "open ups multi get fail:ret[%d]", ret);
    }

    while(OB_SUCCESS == ret)
    {
      const ObRow *tmp_row_ptr = NULL;
      ret = ups_multi_get_->get_next_row(rowkey, tmp_row_ptr);
      if(OB_ITER_END == ret)
      {
        ret = OB_SUCCESS;
        break;
      }
      else if(OB_SUCCESS != ret)
      {
        TBSYS_LOG(WARN, "ups multi get next row fail:ret[%d]", ret);
      }
      else
      {
        ups_row = dynamic_cast<const ObUpsRow *>(tmp_row_ptr);
        if(NULL == ups_row)
        {
          ret = OB_ERR_UNEXPECTED;
          TBSYS_LOG(WARN, "shoud be ObUpsRow");
        }
      }

      if(OB_SUCCESS == ret)
      {
        compact_row.assign_buffer(buffer->current(), buffer->remain());
        if(OB_SUCCESS != (ret = ObUpsRowUtil::convert(*ups_row, compact_row)))
        {
          TBSYS_LOG(WARN, "convert ups row to compact row fail:ret[%d]", ret);
        }
        else if(OB_SUCCESS != (ret = ups_row_cache_.put(*rowkey, compact_row)))
        {
          TBSYS_LOG(WARN, "join cache put fail:ret[%d]", ret);
        }
      }
    }

    if(OB_SUCCESS == ret && NULL != ups_multi_get_)
    {
      if(OB_SUCCESS != (ret = ups_multi_get_->close()))
      {
        TBSYS_LOG(WARN, "close ups multi get fail:ret[%d]", ret);
      }
    }
  }

  return ret;
}
Beispiel #6
0
    int ObPacketQueue::pop_packets(tbnet::Packet** packet_arr, const int64_t ary_size, int64_t& ret_size)
    {
      int err = OB_SUCCESS;
      ThreadSpecificBuffer::Buffer* tb = NULL;

      ret_size = 0;
      if (NULL == packet_arr || ary_size <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, packet_arr=%p, arr_size=%ld", packet_arr, ary_size);
        err = OB_ERROR;
      }
      else
      {
        tb = thread_buffer_->get_buffer();
        if (tb == NULL)
        {
          TBSYS_LOG(ERROR, "get packet thread buffer failed, return NULL");
          err = OB_ERROR;
        }
        else
        {
          tb->reset();
        }
      }

      while (OB_SUCCESS == err && ret_size < ary_size)
      {
        if (head_ == NULL)
        {
          break;
        }
        else
        {
          ObPacket* packet = head_;

          int64_t total_size = sizeof(ObPacket) + packet->get_packet_buffer()->get_capacity();
          if (tb->remain() < total_size)
          {
            if (0 == ret_size)
            {
              TBSYS_LOG(ERROR, "the thread buffer is too small, packet_size=%ld, buffer_size=%ld",
                  total_size, tb->remain());
              // discard packet
              ring_buffer_.pop_task(head_);
              head_ = (ObPacket*) head_->_next;
              if (head_ == NULL)
              {
                tail_ = NULL;
              }
              size_ --;
              err = OB_ERROR;
            }
            break;
          }
          else
          {
            char* buf = tb->current();
            memcpy(buf, packet, total_size);
            packet_arr[ret_size] = (ObPacket*) buf;
            buf += sizeof(ObPacket);
            ((ObPacket*) packet_arr[ret_size])->set_packet_buffer(buf, packet->get_packet_buffer()->get_capacity());

            // pop from queue
            head_ = (ObPacket*) head_->_next;
            if (head_ == NULL)
            {
              tail_ = NULL;
            }
            size_ --;
            // pop from ring buffer
            err = ring_buffer_.pop_task(packet);
            if (OB_SUCCESS != err)
            {
              TBSYS_LOG(ERROR, "failed to pop task, err=%d", err);
            }

            tb->advance(total_size);
            ++ret_size;

          }
        }
      }

      return err;
    }