Exemplo n.º 1
0
void expectEqTestCompactRequest(
    const TestCompactRequest& a,
    const TestCompactRequest& b) {
  EXPECT_EQ(a.key().fullKey(), b.key().fullKey());

  EXPECT_EQ(a.testBool(), b.testBool());
  EXPECT_EQ(a.testChar(), b.testChar());
  EXPECT_EQ(a.testEnum(), b.testEnum());

  EXPECT_EQ(a.testInt8(), b.testInt8());
  EXPECT_EQ(a.testInt16(), b.testInt16());
  EXPECT_EQ(a.testInt32(), b.testInt32());
  EXPECT_EQ(a.testInt64(), b.testInt64());

  EXPECT_EQ(a.testUInt8(), b.testUInt8());
  EXPECT_EQ(a.testUInt16(), b.testUInt16());
  EXPECT_EQ(a.testUInt32(), b.testUInt32());
  EXPECT_EQ(a.testUInt64(), b.testUInt64());

  EXPECT_EQ(a.testShortString(), b.testShortString());
  EXPECT_EQ(a.testLongString(), b.testLongString());

  EXPECT_EQ(
      coalesceAndGetRange(const_cast<folly::IOBuf&>(a.testIobuf())),
      coalesceAndGetRange(const_cast<folly::IOBuf&>(b.testIobuf())));
  EXPECT_EQ(a.testList(), b.testList());
}
Exemplo n.º 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);
  }
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
folly::StringPiece coalesceAndGetRange(std::unique_ptr<folly::IOBuf>& buf) {
  if (!buf) {
    return {};
  }

  return coalesceAndGetRange(*buf);
}
Exemplo n.º 5
0
std::pair<bool, int64_t> MockMc::arith(folly::StringPiece key, int64_t delta) {
  auto item = get(key);
  if (!item) {
    return std::make_pair(false, 0);
  }

  auto oldval = folly::to<uint64_t>(coalesceAndGetRange(item->value));
  auto newval = folly::to<std::string>(oldval + delta);
  item->value = folly::IOBuf::copyBuffer(newval);
  return std::make_pair(true, oldval + delta);
}
Exemplo n.º 6
0
void McRequest::ensureMsgExists(mc_op_t op) const {
  /* dependentMsg* functions assume msg_ exists,
     so create one if necessary. */
  if (!msg_.get()) {
    auto msg = createMcMsgRef();
    dependentHelper(op, getRange(keyData_),
                    coalesceAndGetRange(const_cast<folly::IOBuf&>(valueData_)),
                    msg);
    const_cast<McMsgRef&>(msg_) = std::move(msg);
  }
}
Exemplo n.º 7
0
std::pair<bool, int64_t> MockMc::arith(folly::StringPiece key, int64_t delta) {
  auto it = findUnexpired(key);
  if (it == citems_.end() || it->second.state != CacheItem::CACHE) {
    return std::make_pair(false, 0);
  }

  auto oldval = folly::to<uint64_t>(coalesceAndGetRange(it->second.item.value));
  auto newval = folly::to<std::string>(oldval + delta);
  it->second.updateCasToken();
  it->second.item.value = folly::IOBuf::copyBuffer(newval);
  return std::make_pair(true, oldval + delta);
}
Exemplo n.º 8
0
void expectEqTestRequest(const TestRequest& a, const TestRequest& b) {
  EXPECT_EQ(a.key().fullKey(), b.key().fullKey());

  EXPECT_EQ(a.testBool(), b.testBool());
  EXPECT_EQ(a.testChar(), b.testChar());
  EXPECT_EQ(a.testEnum(), b.testEnum());

  EXPECT_EQ(a.testInt8(), b.testInt8());
  EXPECT_EQ(a.testInt16(), b.testInt16());
  EXPECT_EQ(a.testInt32(), b.testInt32());
  EXPECT_EQ(a.testInt64(), b.testInt64());

  EXPECT_EQ(a.testUInt8(), b.testUInt8());
  EXPECT_EQ(a.testUInt16(), b.testUInt16());
  EXPECT_EQ(a.testUInt32(), b.testUInt32());
  EXPECT_EQ(a.testUInt64(), b.testUInt64());

  EXPECT_FLOAT_EQ(a.testFloat(), b.testFloat());
  EXPECT_DOUBLE_EQ(a.testDouble(), b.testDouble());

  EXPECT_EQ(a.testShortString(), b.testShortString());
  EXPECT_EQ(a.testLongString(), b.testLongString());

  EXPECT_EQ(
      coalesceAndGetRange(const_cast<folly::IOBuf&>(a.testIobuf())),
      coalesceAndGetRange(const_cast<folly::IOBuf&>(b.testIobuf())));

  // Mixed-in structure
  EXPECT_EQ(a.int32Member(), b.int32Member());
  EXPECT_EQ(a.stringMember(), b.stringMember());
  EXPECT_EQ(a.enumMember(), b.enumMember());
  expectEqSimpleStruct(a.asBase(), b.asBase());

  // Member structure
  expectEqSimpleStruct(a.testStruct(), b.testStruct());

  EXPECT_EQ(a.testList(), b.testList());

  EXPECT_EQ(a.testNestedVec(), b.testNestedVec());

  EXPECT_EQ(a.testEnumVec(), b.testEnumVec());

  EXPECT_EQ(a.testUMap(), b.testUMap());
  EXPECT_EQ(a.testMap(), b.testMap());
  EXPECT_EQ(a.testF14FastMap(), b.testF14FastMap());
  EXPECT_EQ(a.testF14NodeMap(), b.testF14NodeMap());
  EXPECT_EQ(a.testF14ValueMap(), b.testF14ValueMap());
  EXPECT_EQ(a.testF14VectorMap(), b.testF14VectorMap());
  EXPECT_EQ(a.testComplexMap(), b.testComplexMap());

  EXPECT_EQ(a.testUSet(), b.testUSet());
  EXPECT_EQ(a.testSet(), b.testSet());
  EXPECT_EQ(a.testF14FastSet(), b.testF14FastSet());
  EXPECT_EQ(a.testF14NodeSet(), b.testF14NodeSet());
  EXPECT_EQ(a.testF14ValueSet(), b.testF14ValueSet());
  EXPECT_EQ(a.testF14VectorSet(), b.testF14VectorSet());

  EXPECT_EQ(a.testOptionalString(), b.testOptionalString());
  compareOptionalIobuf(a.testOptionalIobuf(), b.testOptionalIobuf());

  EXPECT_EQ(a.testType().name, b.testType().name);
  EXPECT_EQ(a.testType().points, b.testType().points);

  EXPECT_EQ(a.testOptionalBool(), b.testOptionalBool());
  EXPECT_EQ(a.testOptionalVec(), b.testOptionalVec());
}