Skip to content

Commit f5ea016

Browse files
Jay Ghuryemeta-codesync[bot]
authored andcommitted
add kcb_identity field on RequestCommon + thrift header write (#480)
Summary: X-link: facebookresearch/DCPerf#674 Pull Request resolved: #480 Adds the `kcbIdentity` field to `carbon::RequestCommon` (mirrors the existing `clientIdentifier` and `cryptoAuthToken` fields), and updates the carbon compiler template to emit a `setWriteHeader(kKcbIdentityHeader, ...)` block in every generated `*ThriftTransport.h`. This is the wire-format support for Generalized KCB: callers set `request.setKcbIdentity(aclName)` and the transport writes the `kcb_identity` thrift header on the outgoing thrift call so the UCache server can bind the cache key to the named ACL group Reviewed By: antonf Differential Revision: D104245265 fbshipit-source-id: 07c975c74a1dd8f5feb0bfac064b7301204a491a
1 parent 42a0663 commit f5ea016

8 files changed

Lines changed: 157 additions & 0 deletions

File tree

‎mcrouter/lib/carbon/RequestCommon.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RequestCommon::RequestCommon(const RequestCommon& other)
2323
replyBitMask_ = other.replyBitMask_;
2424
clientIdentifier_ = other.clientIdentifier_;
2525
privacyLibAgenticContext_ = other.privacyLibAgenticContext_;
26+
kcbIdentity_ = other.kcbIdentity_;
2627
}
2728

2829
RequestCommon& RequestCommon::operator=(const RequestCommon& other) {
@@ -32,6 +33,7 @@ RequestCommon& RequestCommon::operator=(const RequestCommon& other) {
3233
replyBitMask_ = other.replyBitMask_;
3334
clientIdentifier_ = other.clientIdentifier_;
3435
privacyLibAgenticContext_ = other.privacyLibAgenticContext_;
36+
kcbIdentity_ = other.kcbIdentity_;
3537
uniqueId_ = other.uniqueId_;
3638
}
3739
return *this;
@@ -92,6 +94,15 @@ void RequestCommon::setPrivacyLibAgenticContext(std::string&& context) {
9294
privacyLibAgenticContext_.emplace(std::move(context));
9395
}
9496

97+
const std::optional<std::string>& RequestCommon::getKcbIdentity()
98+
const noexcept {
99+
return kcbIdentity_;
100+
}
101+
102+
void RequestCommon::setKcbIdentity(folly::StringPiece kcbIdentity) noexcept {
103+
kcbIdentity_ = kcbIdentity.str();
104+
}
105+
95106
const std::optional<folly::IPAddress>& RequestCommon::getSourceIpAddr()
96107
const noexcept {
97108
return sourceIpAddr_;

‎mcrouter/lib/carbon/RequestCommon.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class RequestCommon : public MessageCommon {
7676

7777
void setPrivacyLibAgenticContext(std::string&& context);
7878

79+
// Returns the resolved Generalized KCB ACL identity name, if any.
80+
// Used by the transport layer to write the kcb_identity thrift header.
81+
const std::optional<std::string>& getKcbIdentity() const noexcept;
82+
83+
void setKcbIdentity(folly::StringPiece kcbIdentity) noexcept;
84+
7985
const std::optional<folly::IPAddress>& getSourceIpAddr() const noexcept;
8086

8187
void setSourceIpAddr(const folly::IPAddress& sourceIpAddr) noexcept;
@@ -101,6 +107,10 @@ class RequestCommon : public MessageCommon {
101107
std::optional<std::string> clientIdentifier_;
102108
// Privacylib agentic context in base64-encoded serialized format
103109
std::optional<std::string> privacyLibAgenticContext_;
110+
// Resolved Generalized KCB ACL identity name (DataTypeConfig.kcbIdentity).
111+
// When set, the transport writes it as the kcb_identity thrift header so
112+
// the UCache server can bind the cache key to this ACL group.
113+
std::optional<std::string> kcbIdentity_;
104114
// Source ip address.
105115
std::optional<folly::IPAddress> sourceIpAddr_;
106116
// write timestamp

‎mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::GoodbyeReply>> send
6060
rpcOptions.setWriteHeader(
6161
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
6262
}
63+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
64+
rpcOptions.setWriteHeader(
65+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
66+
}
6367
rpcOptions.setContextPropMask(0);
6468

6569
#ifndef LIBMC_FBTRACE_DISABLE
@@ -104,6 +108,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::HelloReply>> sendSy
104108
rpcOptions.setWriteHeader(
105109
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
106110
}
111+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
112+
rpcOptions.setWriteHeader(
113+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
114+
}
107115
rpcOptions.setContextPropMask(0);
108116

109117
#ifndef LIBMC_FBTRACE_DISABLE
@@ -151,6 +159,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
151159
rpcOptions.setWriteHeader(
152160
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
153161
}
162+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
163+
rpcOptions.setWriteHeader(
164+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
165+
}
154166
rpcOptions.setContextPropMask(0);
155167

156168
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/AThriftTransport.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::A::TestAReply>> sen
5858
rpcOptions.setWriteHeader(
5959
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
6060
}
61+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
62+
rpcOptions.setWriteHeader(
63+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
64+
}
6165
rpcOptions.setContextPropMask(0);
6266

6367
#ifndef LIBMC_FBTRACE_DISABLE
@@ -102,6 +106,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
102106
rpcOptions.setWriteHeader(
103107
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104108
}
109+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
110+
rpcOptions.setWriteHeader(
111+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
112+
}
105113
rpcOptions.setContextPropMask(0);
106114

107115
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/BThriftTransport.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::B::TestBReply>> sen
5858
rpcOptions.setWriteHeader(
5959
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
6060
}
61+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
62+
rpcOptions.setWriteHeader(
63+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
64+
}
6165
rpcOptions.setContextPropMask(0);
6266

6367
#ifndef LIBMC_FBTRACE_DISABLE
@@ -102,6 +106,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
102106
rpcOptions.setWriteHeader(
103107
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104108
}
109+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
110+
rpcOptions.setWriteHeader(
111+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
112+
}
105113
rpcOptions.setContextPropMask(0);
106114

107115
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReply>> sendSyn
5858
rpcOptions.setWriteHeader(
5959
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
6060
}
61+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
62+
rpcOptions.setWriteHeader(
63+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
64+
}
6165
rpcOptions.setContextPropMask(0);
6266

6367
#ifndef LIBMC_FBTRACE_DISABLE
@@ -102,6 +106,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReplyStringKey>
102106
rpcOptions.setWriteHeader(
103107
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104108
}
109+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
110+
rpcOptions.setWriteHeader(
111+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
112+
}
105113
rpcOptions.setContextPropMask(0);
106114

107115
#ifndef LIBMC_FBTRACE_DISABLE
@@ -146,6 +154,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
146154
rpcOptions.setWriteHeader(
147155
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
148156
}
157+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
158+
rpcOptions.setWriteHeader(
159+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
160+
}
149161
rpcOptions.setContextPropMask(0);
150162

151163
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::CustomReply>> sendS
5858
rpcOptions.setWriteHeader(
5959
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
6060
}
61+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
62+
rpcOptions.setWriteHeader(
63+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
64+
}
6165
rpcOptions.setContextPropMask(0);
6266

6367
#ifndef LIBMC_FBTRACE_DISABLE
@@ -102,6 +106,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::DummyThriftReply>>
102106
rpcOptions.setWriteHeader(
103107
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104108
}
109+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
110+
rpcOptions.setWriteHeader(
111+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
112+
}
105113
rpcOptions.setContextPropMask(0);
106114

107115
#ifndef LIBMC_FBTRACE_DISABLE
@@ -146,6 +154,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::ThriftTestReply>> s
146154
rpcOptions.setWriteHeader(
147155
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
148156
}
157+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
158+
rpcOptions.setWriteHeader(
159+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
160+
}
149161
rpcOptions.setContextPropMask(0);
150162

151163
#ifndef LIBMC_FBTRACE_DISABLE
@@ -190,6 +202,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
190202
rpcOptions.setWriteHeader(
191203
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
192204
}
205+
if (FOLLY_UNLIKELY(request.getKcbIdentity().has_value())) {
206+
rpcOptions.setWriteHeader(
207+
std::string{carbon::MessageCommon::kKcbIdentityHeader}, request.getKcbIdentity().value());
208+
}
193209
rpcOptions.setContextPropMask(0);
194210

195211
#ifndef LIBMC_FBTRACE_DISABLE

0 commit comments

Comments
 (0)