Q1ngbo commented on code in PR #3197: URL: https://github.com/apache/brpc/pull/3197#discussion_r2711244192
########## src/brpc/policy/flatbuffers_protocol.cpp: ########## @@ -0,0 +1,472 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "butil/logging.h" // LOG() +#include "butil/iobuf.h" // butil::IOBuf +#include "butil/single_iobuf.h" // butil::SingleIOBuf +#include "butil/time.h" + +#include "butil/raw_pack.h" // RawPacker RawUnpacker + +#include "brpc/controller.h" // Controller +#include "brpc/socket.h" // Socket +#include "brpc/server.h" // Server +#include "brpc/stream_impl.h" +#include "brpc/rpc_dump.h" // SampledRequest +#include "brpc/policy/most_common_message.h" +#include "brpc/details/controller_private_accessor.h" +#include "brpc/details/server_private_accessor.h" +#include "brpc/policy/flatbuffers_protocol.h" + +namespace brpc { +namespace policy { + +struct FBRpcRequestMeta { + struct { + uint32_t service_index; Review Comment: > method_index 是怎么保证兼容性的。在另一个 pr 中,并没有看到为 method 声明 index,那么我猜可能是由 flatc 自动生成的。 假如用户删除,或者增加 method,那么可能会导致对应的 method index 产生变化,在升级的时候会出现问题。 method的index是由flatc生成的,可以参考example/benchmark_fb/test.brpc.fb.cpp中的descriptor(),该函数中创建了一个BrpcDescriptorTable,其第三个参数即method_name_list保存了所有的方法名,初始化时会按序解析并为method赋予index。Server接收到请求后,会根据service_index与method_index查找method,如果查找失败则调用controller::SetFailed并设置ENOMETHOD。否则会调用test.brpc.fb.cpp中的FBCallMethod函数,在switch语句中根据method index来判断执行哪个method。 如果server侧增加了新方法,且未修改method顺序,那么旧有的方法调用不会受影响,所以旧client仍能与新server通信;反之新client向旧server请求新方法时会产生“ENOMETHOD”错误。删除方法也类似,只要确保method index不受影响就能保证兼容性。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
