describe_log_dirs_response.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package sarama
  2. import "time"
  3. type DescribeLogDirsResponse struct {
  4. ThrottleTime time.Duration
  5. // Version 0 and 1 are equal
  6. // The version number is bumped to indicate that on quota violation brokers send out responses before throttling.
  7. Version int16
  8. LogDirs []DescribeLogDirsResponseDirMetadata
  9. }
  10. func (r *DescribeLogDirsResponse) encode(pe packetEncoder) error {
  11. pe.putInt32(int32(r.ThrottleTime / time.Millisecond))
  12. if err := pe.putArrayLength(len(r.LogDirs)); err != nil {
  13. return err
  14. }
  15. for _, dir := range r.LogDirs {
  16. if err := dir.encode(pe); err != nil {
  17. return err
  18. }
  19. }
  20. return nil
  21. }
  22. func (r *DescribeLogDirsResponse) decode(pd packetDecoder, version int16) error {
  23. throttleTime, err := pd.getInt32()
  24. if err != nil {
  25. return err
  26. }
  27. r.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  28. // Decode array of DescribeLogDirsResponseDirMetadata
  29. n, err := pd.getArrayLength()
  30. if err != nil {
  31. return err
  32. }
  33. r.LogDirs = make([]DescribeLogDirsResponseDirMetadata, n)
  34. for i := 0; i < n; i++ {
  35. dir := DescribeLogDirsResponseDirMetadata{}
  36. if err := dir.decode(pd, version); err != nil {
  37. return err
  38. }
  39. r.LogDirs[i] = dir
  40. }
  41. return nil
  42. }
  43. func (r *DescribeLogDirsResponse) key() int16 {
  44. return 35
  45. }
  46. func (r *DescribeLogDirsResponse) version() int16 {
  47. return r.Version
  48. }
  49. func (r *DescribeLogDirsResponse) headerVersion() int16 {
  50. return 0
  51. }
  52. func (r *DescribeLogDirsResponse) isValidVersion() bool {
  53. return r.Version >= 0 && r.Version <= 1
  54. }
  55. func (r *DescribeLogDirsResponse) requiredVersion() KafkaVersion {
  56. if r.Version > 0 {
  57. return V2_0_0_0
  58. }
  59. return V1_0_0_0
  60. }
  61. func (r *DescribeLogDirsResponse) throttleTime() time.Duration {
  62. return r.ThrottleTime
  63. }
  64. type DescribeLogDirsResponseDirMetadata struct {
  65. ErrorCode KError
  66. // The absolute log directory path
  67. Path string
  68. Topics []DescribeLogDirsResponseTopic
  69. }
  70. func (r *DescribeLogDirsResponseDirMetadata) encode(pe packetEncoder) error {
  71. pe.putInt16(int16(r.ErrorCode))
  72. if err := pe.putString(r.Path); err != nil {
  73. return err
  74. }
  75. if err := pe.putArrayLength(len(r.Topics)); err != nil {
  76. return err
  77. }
  78. for _, topic := range r.Topics {
  79. if err := topic.encode(pe); err != nil {
  80. return err
  81. }
  82. }
  83. return nil
  84. }
  85. func (r *DescribeLogDirsResponseDirMetadata) decode(pd packetDecoder, version int16) error {
  86. errCode, err := pd.getInt16()
  87. if err != nil {
  88. return err
  89. }
  90. r.ErrorCode = KError(errCode)
  91. path, err := pd.getString()
  92. if err != nil {
  93. return err
  94. }
  95. r.Path = path
  96. // Decode array of DescribeLogDirsResponseTopic
  97. n, err := pd.getArrayLength()
  98. if err != nil {
  99. return err
  100. }
  101. r.Topics = make([]DescribeLogDirsResponseTopic, n)
  102. for i := 0; i < n; i++ {
  103. t := DescribeLogDirsResponseTopic{}
  104. if err := t.decode(pd, version); err != nil {
  105. return err
  106. }
  107. r.Topics[i] = t
  108. }
  109. return nil
  110. }
  111. // DescribeLogDirsResponseTopic contains a topic's partitions descriptions
  112. type DescribeLogDirsResponseTopic struct {
  113. Topic string
  114. Partitions []DescribeLogDirsResponsePartition
  115. }
  116. func (r *DescribeLogDirsResponseTopic) encode(pe packetEncoder) error {
  117. if err := pe.putString(r.Topic); err != nil {
  118. return err
  119. }
  120. if err := pe.putArrayLength(len(r.Partitions)); err != nil {
  121. return err
  122. }
  123. for _, partition := range r.Partitions {
  124. if err := partition.encode(pe); err != nil {
  125. return err
  126. }
  127. }
  128. return nil
  129. }
  130. func (r *DescribeLogDirsResponseTopic) decode(pd packetDecoder, version int16) error {
  131. t, err := pd.getString()
  132. if err != nil {
  133. return err
  134. }
  135. r.Topic = t
  136. n, err := pd.getArrayLength()
  137. if err != nil {
  138. return err
  139. }
  140. r.Partitions = make([]DescribeLogDirsResponsePartition, n)
  141. for i := 0; i < n; i++ {
  142. p := DescribeLogDirsResponsePartition{}
  143. if err := p.decode(pd, version); err != nil {
  144. return err
  145. }
  146. r.Partitions[i] = p
  147. }
  148. return nil
  149. }
  150. // DescribeLogDirsResponsePartition describes a partition's log directory
  151. type DescribeLogDirsResponsePartition struct {
  152. PartitionID int32
  153. // The size of the log segments of the partition in bytes.
  154. Size int64
  155. // The lag of the log's LEO w.r.t. partition's HW (if it is the current log for the partition) or
  156. // current replica's LEO (if it is the future log for the partition)
  157. OffsetLag int64
  158. // True if this log is created by AlterReplicaLogDirsRequest and will replace the current log of
  159. // the replica in the future.
  160. IsTemporary bool
  161. }
  162. func (r *DescribeLogDirsResponsePartition) encode(pe packetEncoder) error {
  163. pe.putInt32(r.PartitionID)
  164. pe.putInt64(r.Size)
  165. pe.putInt64(r.OffsetLag)
  166. pe.putBool(r.IsTemporary)
  167. return nil
  168. }
  169. func (r *DescribeLogDirsResponsePartition) decode(pd packetDecoder, version int16) error {
  170. pID, err := pd.getInt32()
  171. if err != nil {
  172. return err
  173. }
  174. r.PartitionID = pID
  175. size, err := pd.getInt64()
  176. if err != nil {
  177. return err
  178. }
  179. r.Size = size
  180. lag, err := pd.getInt64()
  181. if err != nil {
  182. return err
  183. }
  184. r.OffsetLag = lag
  185. isTemp, err := pd.getBool()
  186. if err != nil {
  187. return err
  188. }
  189. r.IsTemporary = isTemp
  190. return nil
  191. }