示例#1
0
rc_t LogCollectorImpl::reqFileData(file_id_t file_id, file_size_t pos, uint8_t* data, uint32_t len) {

  Request* pRequest = getRequest(0);
  if (NULL == pRequest) { return RC_S_NULL_VALUE; }

  // FileData
  FileDataRequest* pFileDataRequest = pRequest->GetFileDataRequest();
  if (NULL == pFileDataRequest) { return RC_E_NOMEM; }

  // send only
  if (IFileNode::INVALID_FILE_ID == file_id || NULL == data || 0 == len) { 

    if (0 == pFileDataRequest->filedata_size() || RC_S_OK != pRequest->SerializeRequest()) { return RC_S_FAILED; }
    return m_autoRelINetHandler->Send(this, pRequest->GetRequestData(), pRequest->GetRequestSize());
  }

  //
  // deflate
  ASSERT(IFileCollector::kMAX_READ_SIZE >= len);
  size_t encode_size = m_autoRelMemDefalte->len();
  if (RC_S_OK != m_autoRelICoderDefalte->encode(m_autoRelMemDefalte->data(), &encode_size, data, len)) {
    LOG(ILogWriter::LV_WARN, "Deflate EnCode Failed, Org. Data Len=%u", len);
    return RC_S_FAILED;
  }

  // is too big
  if (INetHandler::kMAX_REQ_DATA_SIZE < encode_size) { return RC_E_ACCESS; }

  if (INetHandler::kMAX_REQ_DATA_SIZE < pFileDataRequest->ByteSize() + encode_size) {
    if (RC_S_OK != pRequest->SerializeRequest()) {
      LOG(ILogWriter::LV_WARN, "FileData Packet EnCode Failed. len=%u(less)", pFileDataRequest->ByteSize() + encode_size);
      return RC_S_FAILED;
    }

    if (RC_S_OK != m_autoRelINetHandler->Send(this, pRequest->GetRequestData(), pRequest->GetRequestSize())) { return RC_S_FAILED; }
    pFileDataRequest = pRequest->GetFileDataRequest();
  }

  // make sure have FileDataRequest
  if (NULL == pFileDataRequest) { return RC_E_NOMEM; }

  FileDataRequest_FileData* pFileData = pFileDataRequest->add_filedata();
  if (NULL == pFileData) { return RC_E_NOMEM; }

  FileID* pFileID = pFileData->mutable_id();
  if (NULL == pFileID) { return RC_E_NOMEM; }

  pFileID->set_id(file_id);
  pFileData->set_pos(pos);

  pFileData->set_encode(FileDataRequest_FileData_EncodeType_DEFLATE);
  pFileData->set_org_len(len);
  pFileData->set_data(m_autoRelMemDefalte->data(), encode_size);

  return RC_S_OK;
}
示例#2
0
rc_t LogCollectorImpl::reqCheckSum(file_id_t file_id, uint32_t fb_cb_pos, uint32_t fb_cs_count) {

  Request* pRequest = getRequest(0);
  if (NULL == pRequest) { return RC_S_NULL_VALUE; }

  // checksum
  CheckSumRequest* pCheckSumRequest = pRequest->GetCheckSumRequest();
  if (NULL == pCheckSumRequest) { return RC_E_NOMEM; }

  FileID* pFileID = pCheckSumRequest->mutable_id();
  if (NULL == pFileID) { return RC_E_NOMEM; }
  pFileID->set_id(file_id);

  pCheckSumRequest->set_fb_cs_pos(fb_cb_pos);
  pCheckSumRequest->set_fb_cs_count(fb_cs_count);

  if (RC_S_OK != pRequest->SerializeRequest()) { return RC_S_FAILED; }
  return m_autoRelINetHandler->Send(this, pRequest->GetRequestData(), pRequest->GetRequestSize());
}