doujiang24 / lua-resty-kafka

Lua kafka client driver for the Openresty based on the cosocket API
BSD 3-Clause "New" or "Revised" License
803 stars 277 forks source link

fix: api_version #152

Closed DG-Wangtao closed 1 year ago

DG-Wangtao commented 1 year ago

Hi @doujiang24 , I think I made a mistake in https://github.com/doujiang24/lua-resty-kafka/pull/137 while trying to resolve https://github.com/doujiang24/lua-resty-kafka/issues/135, so I'm creating a new pull request to fix it.

doujiang24 commented 1 year ago

could you please describe the bug in detail? I'm not sure I'm catching up with you.

DG-Wangtao commented 1 year ago
if not self.api_version then
        version = self.api_version 
end

First of all, the code means that we use self.api_version as version if we **not** set self.api_version manually. It's obvious an error and it should be we use self.api_version as version only if we set self.api_version.

Secondly,API_VERSION_V0 is useed as default value of self.api_version : https://github.com/doujiang24/lua-resty-kafka/blob/3fbed91d81d4fb32d4dda4316f5f2cba04622633/lib/resty/kafka/producer.lua#L341 The self.api_version will be API_VERSION_V0 if we not set manually.

So I implement it as "use self.api_version as version if it's set manually":

if not (self.api_version == API_VERSION_V0) then
        version = self.api_version 
end
doujiang24 commented 1 year ago

okay, I see the problem. but I'm afraid this may not be a proper fix.

actually, we hope to use API_VERSION_V1 as the default api_version here, only for producer send, right? this looks a bit weird, we use the different default values in different places.

I think the proper way is, you specify the api_version in your upper level code, while init the producer.

Or, if you think API_VERSION_V0 is not worthing to support, we could turn the default value to API_VERSION_V1 while init producer. and you need to approve it, i.e. the versions of kafka that support API_VERSION_V0 are too old.

DG-Wangtao commented 1 year ago
doujiang24 commented 1 year ago

@DG-Wangtao Thanks for your clearify.

I think the proper way is, you specify the api_version in your upper level code, while init the producer.

does this work for you?

DG-Wangtao commented 1 year ago

yes. it works well if I set api_version while init the producer.

I think use API_VERSION_V1 as default value would be better, thus I create a new branch here:

I you agree with this idea I will update this pull request.

DG-Wangtao commented 1 year ago

Hi @doujiang24, I think this pull request is ready to merge, do you have any concerns?

doujiang24 commented 1 year ago

@DG-Wangtao Sorry for the late. Seems this new branch is better, can it pass the CI? https://github.com/doujiang24/lua-resty-kafka/compare/master...DG-Wangtao:lua-resty-kafka:fix/api-version

doujiang24 commented 1 year ago

the code logical in the current patch looks weird, if the new branch passes the CI, I prefer the new branch.

DG-Wangtao commented 1 year ago

Yes, logical in branch https://github.com/DG-Wangtao/lua-resty-kafka/tree/fix/api-version is a better way, which has been running in my env for a long time. I created a new pull request from the branch here #160 an passed the CI.

@doujiang24 Thanks for your work, I'm closing this pull request.