m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

386 lines
11 KiB

6 months ago
  1. from __future__ import absolute_import
  2. from kafka.protocol.api import Request, Response
  3. from kafka.protocol.types import Array, Int8, Int16, Int32, Int64, Schema, String, Bytes
  4. class FetchResponse_v0(Response):
  5. API_KEY = 1
  6. API_VERSION = 0
  7. SCHEMA = Schema(
  8. ('topics', Array(
  9. ('topics', String('utf-8')),
  10. ('partitions', Array(
  11. ('partition', Int32),
  12. ('error_code', Int16),
  13. ('highwater_offset', Int64),
  14. ('message_set', Bytes)))))
  15. )
  16. class FetchResponse_v1(Response):
  17. API_KEY = 1
  18. API_VERSION = 1
  19. SCHEMA = Schema(
  20. ('throttle_time_ms', Int32),
  21. ('topics', Array(
  22. ('topics', String('utf-8')),
  23. ('partitions', Array(
  24. ('partition', Int32),
  25. ('error_code', Int16),
  26. ('highwater_offset', Int64),
  27. ('message_set', Bytes)))))
  28. )
  29. class FetchResponse_v2(Response):
  30. API_KEY = 1
  31. API_VERSION = 2
  32. SCHEMA = FetchResponse_v1.SCHEMA # message format changed internally
  33. class FetchResponse_v3(Response):
  34. API_KEY = 1
  35. API_VERSION = 3
  36. SCHEMA = FetchResponse_v2.SCHEMA
  37. class FetchResponse_v4(Response):
  38. API_KEY = 1
  39. API_VERSION = 4
  40. SCHEMA = Schema(
  41. ('throttle_time_ms', Int32),
  42. ('topics', Array(
  43. ('topics', String('utf-8')),
  44. ('partitions', Array(
  45. ('partition', Int32),
  46. ('error_code', Int16),
  47. ('highwater_offset', Int64),
  48. ('last_stable_offset', Int64),
  49. ('aborted_transactions', Array(
  50. ('producer_id', Int64),
  51. ('first_offset', Int64))),
  52. ('message_set', Bytes)))))
  53. )
  54. class FetchResponse_v5(Response):
  55. API_KEY = 1
  56. API_VERSION = 5
  57. SCHEMA = Schema(
  58. ('throttle_time_ms', Int32),
  59. ('topics', Array(
  60. ('topics', String('utf-8')),
  61. ('partitions', Array(
  62. ('partition', Int32),
  63. ('error_code', Int16),
  64. ('highwater_offset', Int64),
  65. ('last_stable_offset', Int64),
  66. ('log_start_offset', Int64),
  67. ('aborted_transactions', Array(
  68. ('producer_id', Int64),
  69. ('first_offset', Int64))),
  70. ('message_set', Bytes)))))
  71. )
  72. class FetchResponse_v6(Response):
  73. """
  74. Same as FetchResponse_v5. The version number is bumped up to indicate that the client supports KafkaStorageException.
  75. The KafkaStorageException will be translated to NotLeaderForPartitionException in the response if version <= 5
  76. """
  77. API_KEY = 1
  78. API_VERSION = 6
  79. SCHEMA = FetchResponse_v5.SCHEMA
  80. class FetchResponse_v7(Response):
  81. """
  82. Add error_code and session_id to response
  83. """
  84. API_KEY = 1
  85. API_VERSION = 7
  86. SCHEMA = Schema(
  87. ('throttle_time_ms', Int32),
  88. ('error_code', Int16),
  89. ('session_id', Int32),
  90. ('topics', Array(
  91. ('topics', String('utf-8')),
  92. ('partitions', Array(
  93. ('partition', Int32),
  94. ('error_code', Int16),
  95. ('highwater_offset', Int64),
  96. ('last_stable_offset', Int64),
  97. ('log_start_offset', Int64),
  98. ('aborted_transactions', Array(
  99. ('producer_id', Int64),
  100. ('first_offset', Int64))),
  101. ('message_set', Bytes)))))
  102. )
  103. class FetchResponse_v8(Response):
  104. API_KEY = 1
  105. API_VERSION = 8
  106. SCHEMA = FetchResponse_v7.SCHEMA
  107. class FetchResponse_v9(Response):
  108. API_KEY = 1
  109. API_VERSION = 9
  110. SCHEMA = FetchResponse_v7.SCHEMA
  111. class FetchResponse_v10(Response):
  112. API_KEY = 1
  113. API_VERSION = 10
  114. SCHEMA = FetchResponse_v7.SCHEMA
  115. class FetchResponse_v11(Response):
  116. API_KEY = 1
  117. API_VERSION = 11
  118. SCHEMA = Schema(
  119. ('throttle_time_ms', Int32),
  120. ('error_code', Int16),
  121. ('session_id', Int32),
  122. ('topics', Array(
  123. ('topics', String('utf-8')),
  124. ('partitions', Array(
  125. ('partition', Int32),
  126. ('error_code', Int16),
  127. ('highwater_offset', Int64),
  128. ('last_stable_offset', Int64),
  129. ('log_start_offset', Int64),
  130. ('aborted_transactions', Array(
  131. ('producer_id', Int64),
  132. ('first_offset', Int64))),
  133. ('preferred_read_replica', Int32),
  134. ('message_set', Bytes)))))
  135. )
  136. class FetchRequest_v0(Request):
  137. API_KEY = 1
  138. API_VERSION = 0
  139. RESPONSE_TYPE = FetchResponse_v0
  140. SCHEMA = Schema(
  141. ('replica_id', Int32),
  142. ('max_wait_time', Int32),
  143. ('min_bytes', Int32),
  144. ('topics', Array(
  145. ('topic', String('utf-8')),
  146. ('partitions', Array(
  147. ('partition', Int32),
  148. ('offset', Int64),
  149. ('max_bytes', Int32)))))
  150. )
  151. class FetchRequest_v1(Request):
  152. API_KEY = 1
  153. API_VERSION = 1
  154. RESPONSE_TYPE = FetchResponse_v1
  155. SCHEMA = FetchRequest_v0.SCHEMA
  156. class FetchRequest_v2(Request):
  157. API_KEY = 1
  158. API_VERSION = 2
  159. RESPONSE_TYPE = FetchResponse_v2
  160. SCHEMA = FetchRequest_v1.SCHEMA
  161. class FetchRequest_v3(Request):
  162. API_KEY = 1
  163. API_VERSION = 3
  164. RESPONSE_TYPE = FetchResponse_v3
  165. SCHEMA = Schema(
  166. ('replica_id', Int32),
  167. ('max_wait_time', Int32),
  168. ('min_bytes', Int32),
  169. ('max_bytes', Int32), # This new field is only difference from FR_v2
  170. ('topics', Array(
  171. ('topic', String('utf-8')),
  172. ('partitions', Array(
  173. ('partition', Int32),
  174. ('offset', Int64),
  175. ('max_bytes', Int32)))))
  176. )
  177. class FetchRequest_v4(Request):
  178. # Adds isolation_level field
  179. API_KEY = 1
  180. API_VERSION = 4
  181. RESPONSE_TYPE = FetchResponse_v4
  182. SCHEMA = Schema(
  183. ('replica_id', Int32),
  184. ('max_wait_time', Int32),
  185. ('min_bytes', Int32),
  186. ('max_bytes', Int32),
  187. ('isolation_level', Int8),
  188. ('topics', Array(
  189. ('topic', String('utf-8')),
  190. ('partitions', Array(
  191. ('partition', Int32),
  192. ('offset', Int64),
  193. ('max_bytes', Int32)))))
  194. )
  195. class FetchRequest_v5(Request):
  196. # This may only be used in broker-broker api calls
  197. API_KEY = 1
  198. API_VERSION = 5
  199. RESPONSE_TYPE = FetchResponse_v5
  200. SCHEMA = Schema(
  201. ('replica_id', Int32),
  202. ('max_wait_time', Int32),
  203. ('min_bytes', Int32),
  204. ('max_bytes', Int32),
  205. ('isolation_level', Int8),
  206. ('topics', Array(
  207. ('topic', String('utf-8')),
  208. ('partitions', Array(
  209. ('partition', Int32),
  210. ('fetch_offset', Int64),
  211. ('log_start_offset', Int64),
  212. ('max_bytes', Int32)))))
  213. )
  214. class FetchRequest_v6(Request):
  215. """
  216. The body of FETCH_REQUEST_V6 is the same as FETCH_REQUEST_V5.
  217. The version number is bumped up to indicate that the client supports KafkaStorageException.
  218. The KafkaStorageException will be translated to NotLeaderForPartitionException in the response if version <= 5
  219. """
  220. API_KEY = 1
  221. API_VERSION = 6
  222. RESPONSE_TYPE = FetchResponse_v6
  223. SCHEMA = FetchRequest_v5.SCHEMA
  224. class FetchRequest_v7(Request):
  225. """
  226. Add incremental fetch requests
  227. """
  228. API_KEY = 1
  229. API_VERSION = 7
  230. RESPONSE_TYPE = FetchResponse_v7
  231. SCHEMA = Schema(
  232. ('replica_id', Int32),
  233. ('max_wait_time', Int32),
  234. ('min_bytes', Int32),
  235. ('max_bytes', Int32),
  236. ('isolation_level', Int8),
  237. ('session_id', Int32),
  238. ('session_epoch', Int32),
  239. ('topics', Array(
  240. ('topic', String('utf-8')),
  241. ('partitions', Array(
  242. ('partition', Int32),
  243. ('fetch_offset', Int64),
  244. ('log_start_offset', Int64),
  245. ('max_bytes', Int32))))),
  246. ('forgotten_topics_data', Array(
  247. ('topic', String),
  248. ('partitions', Array(Int32))
  249. )),
  250. )
  251. class FetchRequest_v8(Request):
  252. """
  253. bump used to indicate that on quota violation brokers send out responses before throttling.
  254. """
  255. API_KEY = 1
  256. API_VERSION = 8
  257. RESPONSE_TYPE = FetchResponse_v8
  258. SCHEMA = FetchRequest_v7.SCHEMA
  259. class FetchRequest_v9(Request):
  260. """
  261. adds the current leader epoch (see KIP-320)
  262. """
  263. API_KEY = 1
  264. API_VERSION = 9
  265. RESPONSE_TYPE = FetchResponse_v9
  266. SCHEMA = Schema(
  267. ('replica_id', Int32),
  268. ('max_wait_time', Int32),
  269. ('min_bytes', Int32),
  270. ('max_bytes', Int32),
  271. ('isolation_level', Int8),
  272. ('session_id', Int32),
  273. ('session_epoch', Int32),
  274. ('topics', Array(
  275. ('topic', String('utf-8')),
  276. ('partitions', Array(
  277. ('partition', Int32),
  278. ('current_leader_epoch', Int32),
  279. ('fetch_offset', Int64),
  280. ('log_start_offset', Int64),
  281. ('max_bytes', Int32))))),
  282. ('forgotten_topics_data', Array(
  283. ('topic', String),
  284. ('partitions', Array(Int32)),
  285. )),
  286. )
  287. class FetchRequest_v10(Request):
  288. """
  289. bumped up to indicate ZStandard capability. (see KIP-110)
  290. """
  291. API_KEY = 1
  292. API_VERSION = 10
  293. RESPONSE_TYPE = FetchResponse_v10
  294. SCHEMA = FetchRequest_v9.SCHEMA
  295. class FetchRequest_v11(Request):
  296. """
  297. added rack ID to support read from followers (KIP-392)
  298. """
  299. API_KEY = 1
  300. API_VERSION = 11
  301. RESPONSE_TYPE = FetchResponse_v11
  302. SCHEMA = Schema(
  303. ('replica_id', Int32),
  304. ('max_wait_time', Int32),
  305. ('min_bytes', Int32),
  306. ('max_bytes', Int32),
  307. ('isolation_level', Int8),
  308. ('session_id', Int32),
  309. ('session_epoch', Int32),
  310. ('topics', Array(
  311. ('topic', String('utf-8')),
  312. ('partitions', Array(
  313. ('partition', Int32),
  314. ('current_leader_epoch', Int32),
  315. ('fetch_offset', Int64),
  316. ('log_start_offset', Int64),
  317. ('max_bytes', Int32))))),
  318. ('forgotten_topics_data', Array(
  319. ('topic', String),
  320. ('partitions', Array(Int32))
  321. )),
  322. ('rack_id', String('utf-8')),
  323. )
  324. FetchRequest = [
  325. FetchRequest_v0, FetchRequest_v1, FetchRequest_v2,
  326. FetchRequest_v3, FetchRequest_v4, FetchRequest_v5,
  327. FetchRequest_v6, FetchRequest_v7, FetchRequest_v8,
  328. FetchRequest_v9, FetchRequest_v10, FetchRequest_v11,
  329. ]
  330. FetchResponse = [
  331. FetchResponse_v0, FetchResponse_v1, FetchResponse_v2,
  332. FetchResponse_v3, FetchResponse_v4, FetchResponse_v5,
  333. FetchResponse_v6, FetchResponse_v7, FetchResponse_v8,
  334. FetchResponse_v9, FetchResponse_v10, FetchResponse_v11,
  335. ]