-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-4914: Make TClient.Call to return the response meta #2315
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1493,11 +1493,15 @@ void t_go_generator::generate_go_struct_definition(ostream& out, | |
|
||
if (is_exception) { | ||
out << indent() << "func (p *" << tstruct_name << ") Error() string {" << endl; | ||
out << indent() << indent() << "return p.String()" << endl; | ||
indent_up(); | ||
out << indent() << "return p.String()" << endl; | ||
indent_down(); | ||
out << indent() << "}" << endl << endl; | ||
|
||
out << indent() << "func (" << tstruct_name << ") TExceptionType() thrift.TExceptionType {" << endl; | ||
out << indent() << indent() << "return thrift.TExceptionTypeCompiled" << endl; | ||
indent_up(); | ||
out << indent() << "return thrift.TExceptionTypeCompiled" << endl; | ||
indent_down(); | ||
out << indent() << "}" << endl << endl; | ||
|
||
out << indent() << "var _ thrift.TException = (*" << tstruct_name << ")(nil)" | ||
|
@@ -1990,6 +1994,7 @@ void t_go_generator::generate_service_client(t_service* tservice) { | |
f_types_ << indent() << "*" << extends_client << endl; | ||
} else { | ||
f_types_ << indent() << "c thrift.TClient" << endl; | ||
f_types_ << indent() << "meta thrift.ResponseMeta" << endl; | ||
} | ||
|
||
indent_down(); | ||
|
@@ -2059,7 +2064,19 @@ void t_go_generator::generate_service_client(t_service* tservice) { | |
indent_up(); | ||
f_types_ << indent() << "return p.c" << endl; | ||
indent_down(); | ||
f_types_ << indent() << "}" << endl; | ||
f_types_ << indent() << "}" << endl << endl; | ||
|
||
f_types_ << indent() << "func (p *" << serviceName << "Client) LastResponseMeta_() thrift.ResponseMeta {" << endl; | ||
indent_up(); | ||
f_types_ << indent() << "return p.meta" << endl; | ||
indent_down(); | ||
f_types_ << indent() << "}" << endl << endl; | ||
|
||
f_types_ << indent() << "func (p *" << serviceName << "Client) SetLastResponseMeta_(meta thrift.ResponseMeta) {" << endl; | ||
indent_up(); | ||
f_types_ << indent() << "p.meta = meta" << endl; | ||
indent_down(); | ||
f_types_ << indent() << "}" << endl << endl; | ||
} | ||
|
||
// Generate client method implementations | ||
|
@@ -2091,8 +2108,11 @@ void t_go_generator::generate_service_client(t_service* tservice) { | |
std::string resultName = tmp("_result"); | ||
std::string resultType = publicize(method + "_result", true); | ||
f_types_ << indent() << "var " << resultName << " " << resultType << endl; | ||
f_types_ << indent() << "if err = p.Client_().Call(ctx, \"" | ||
<< method << "\", &" << argsName << ", &" << resultName << "); err != nil {" << endl; | ||
f_types_ << indent() << "var meta thrift.ResponseMeta" << endl; | ||
f_types_ << indent() << "meta, err = p.Client_().Call(ctx, \"" | ||
<< method << "\", &" << argsName << ", &" << resultName << ")" << endl; | ||
f_types_ << indent() << "p.SetLastResponseMeta_(meta)" << endl; | ||
f_types_ << indent() << "if err != nil {" << endl; | ||
Comment on lines
-2094
to
+2115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we use // Parameters:
// - Key
// - Meta
func (p *NimbusClient) BeginCreateBlob(ctx context.Context, key string, meta *SettableBlobMeta) (r string, err error) {
var _args293 NimbusBeginCreateBlobArgs
_args293.Key = key
_args293.Meta = meta
var _result294 NimbusBeginCreateBlobResult
var meta thrift.ResponseMeta
meta, err = p.Client_().Call(ctx, "beginCreateBlob", &_args293, &_result294)
p.SetLastResponseMeta_(meta)
if err != nil {
return
}
switch {
case _result294.Aze!= nil:
return r, _result294.Aze
case _result294.Kae!= nil:
return r, _result294.Kae
}
return _result294.GetSuccess(), nil
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Thanks for reporting. Preparing a PR to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
indent_up(); | ||
f_types_ << indent() << "return" << endl; | ||
|
@@ -2131,9 +2151,13 @@ void t_go_generator::generate_service_client(t_service* tservice) { | |
f_types_ << indent() << "return nil" << endl; | ||
} | ||
} else { | ||
// Since we don't have response meta for oneway calls, overwrite it with | ||
// an empty one to avoid users getting the meta from last call and | ||
// mistaken it as from the oneway call. | ||
f_types_ << indent() << "p.SetLastResponseMeta_(thrift.ResponseMeta{})" << endl; | ||
// TODO: would be nice to not to duplicate the call generation | ||
f_types_ << indent() << "if err := p.Client_().Call(ctx, \"" | ||
<< method << "\", &"<< argsName << ", nil); err != nil {" << endl; | ||
f_types_ << indent() << "if _, err := p.Client_().Call(ctx, \"" | ||
<< method << "\", &"<< argsName << ", nil); err != nil {" << endl; | ||
|
||
indent_up(); | ||
f_types_ << indent() << "return err" << endl; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,20 +345,6 @@ func (p *THeaderProtocol) SetTConfiguration(cfg *TConfiguration) { | |
p.cfg = cfg | ||
} | ||
|
||
// GetResponseHeadersFromClient is a helper function to get the read THeaderMap | ||
// from the last response received from the given client. | ||
// | ||
// If the last response was not sent over THeader protocol, | ||
// a nil map will be returned. | ||
func GetResponseHeadersFromClient(c TClient) THeaderMap { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was in a tagged release. Maybe mark it as deprecated instead of removing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was added after 0.13.0 so I don't believe it's in any tagged release :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least it's not here: https://pkg.go.dev/github.com/apache/[email protected]/lib/go/thrift :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I was confused because the commit date was earlier than the 0.13 tag :) |
||
if sc, ok := c.(*TStandardClient); ok { | ||
if hp, ok := sc.iprot.(*THeaderProtocol); ok { | ||
return hp.transport.readHeaders | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
var ( | ||
_ TConfigurationSetter = (*tHeaderProtocolFactory)(nil) | ||
_ TConfigurationSetter = (*THeaderProtocol)(nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are cosmetic fix of a wrongly did indent from my previous PR :$ not really related to this PR.