Example #1
0
McRequest::McRequest(const McRequest& other)
    : exptime_(other.exptime_),
      flags_(other.flags_),
      delta_(other.delta_),
      leaseToken_(other.leaseToken_),
      cas_(other.cas_) {
  // Key is always a single piece, so it's safe to do cloneOneInto.
  other.keyData_.cloneOneInto(keyData_);
  keys_ = Keys(getRange(keyData_));
  other.valueData_.cloneInto(valueData_);

  if (hasSameMemoryRegion(keyData_, other.keyData_) &&
      hasSameMemoryRegion(valueData_, other.valueData_)) {

    msg_ = other.msg_.clone();
  } else {
    msg_ = createMcMsgRef(
      other.msg_, getRange(keyData_),
      coalesceAndGetRange(valueData_));
  }

#ifndef LIBMC_FBTRACE_DISABLE
  if (other.fbtraceInfo_.get()) {
    fbtraceInfo_ = McFbtraceRef::moveRef(
      mc_fbtrace_info_deep_copy(other.fbtraceInfo_.get()));
  }
#endif
}
Example #2
0
McMsgRef McRequest::dependentMsg(mc_op_t op) const {
  ensureMsgExists(op);

  auto is_key_set =
    hasSameMemoryRegion(keyData_, to<folly::StringPiece>(msg_->key));
  auto is_value_set =
    hasSameMemoryRegion(valueData_, to<folly::StringPiece>(msg_->value));

  if (msg_->op == op &&
      msg_->exptime == exptime_ &&
      msg_->flags == flags_ &&
      msg_->delta == delta_ &&
      msg_->lease_id == leaseToken_ &&
      msg_->cas == cas_ &&
#ifndef LIBMC_FBTRACE_DISABLE
      msg_->fbtrace_info == fbtraceInfo_.get() &&
#endif
      is_key_set &&
      is_value_set) {
    /* msg_ is an object with the same fields we expect.
       In addition, we want to keep routing prefix.
       We can simply return the reference. */
    return msg_.clone();
  } else {
    /* Out of luck.  The best we can do is make the copy
       reference key/value fields from the backing store. */
    auto toRelease = createMcMsgRef();
    dependentHelper(op, getRange(keyData_),
                    coalesceAndGetRange(const_cast<folly::IOBuf&>(valueData_)),
                    toRelease);
    return std::move(toRelease);
  }
}
Example #3
0
McMsgRef McReplyBase::releasedMsg(mc_op_t op) const {
  if (msg_.get() != nullptr &&
      msg_->op == op &&
      msg_->result == result_ &&
      msg_->flags == flags_ &&
      msg_->lease_id == leaseToken_ &&
      msg_->delta == delta_ &&
      msg_->err_code == errCode_ &&
      hasSameMemoryRegion(value(), to<folly::StringPiece>(msg_->value))) {
    return msg_.clone();
  } else {
    auto len = value().computeChainDataLength();
    auto toRelease = createMcMsgRef(len + 1);
    if (msg_.get() != nullptr) {
      mc_msg_shallow_copy(toRelease.get(), msg_.get());
      // TODO: fbtrace?
    }
    toRelease->key.str = nullptr;
    toRelease->key.len = 0;
    toRelease->value.str =
      static_cast<char*>(static_cast<void*>(toRelease.get() + 1));
    copyInto(toRelease->value.str, value());
    toRelease->value.len = len;
    toRelease->op = op;
    toRelease->result = result_;
    toRelease->flags = flags_;
    toRelease->lease_id = leaseToken_;
    toRelease->delta = delta_;
    toRelease->cas = cas_;
    toRelease->err_code = errCode_;

    return std::move(toRelease);
  }
}
Example #4
0
McRequest::McRequest(const McRequest& other)
    : exptime_(other.exptime_),
      number_(other.number_),
      flags_(other.flags_),
      delta_(other.delta_),
      leaseToken_(other.leaseToken_),
      cas_(other.cas_) {
  // Key is always a single piece, so it's safe to do cloneOneInto.
  other.keyData_.cloneOneInto(keyData_);
  assert(hasSameMemoryRegion(keyData_, other.keyData_));
  // it's safe to copy existing StringPieces since we don't copy the data
  keys_ = other.keys_;
  other.valueData_.cloneInto(valueData_);

#ifndef LIBMC_FBTRACE_DISABLE
  if (other.fbtraceInfo_.get()) {
    fbtraceInfo_ = McFbtraceRef::moveRef(
      mc_fbtrace_info_deep_copy(other.fbtraceInfo_.get()));
  }
#endif
}