describe_log_dirs_response.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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) requiredVersion() KafkaVersion {
  53. return V1_0_0_0
  54. }
  55. type DescribeLogDirsResponseDirMetadata struct {
  56. ErrorCode KError
  57. // The absolute log directory path
  58. Path string
  59. Topics []DescribeLogDirsResponseTopic
  60. }
  61. func (r *DescribeLogDirsResponseDirMetadata) encode(pe packetEncoder) error {
  62. pe.putInt16(int16(r.ErrorCode))
  63. if err := pe.putString(r.Path); err != nil {
  64. return err
  65. }
  66. if err := pe.putArrayLength(len(r.Topics)); err != nil {
  67. return err
  68. }
  69. for _, topic := range r.Topics {
  70. if err := topic.encode(pe); err != nil {
  71. return err
  72. }
  73. }
  74. return nil
  75. }
  76. func (r *DescribeLogDirsResponseDirMetadata) decode(pd packetDecoder, version int16) error {
  77. errCode, err := pd.getInt16()
  78. if err != nil {
  79. return err
  80. }
  81. r.ErrorCode = KError(errCode)
  82. path, err := pd.getString()
  83. if err != nil {
  84. return err
  85. }
  86. r.Path = path
  87. // Decode array of DescribeLogDirsResponseTopic
  88. n, err := pd.getArrayLength()
  89. if err != nil {
  90. return err
  91. }
  92. r.Topics = make([]DescribeLogDirsResponseTopic, n)
  93. for i := 0; i < n; i++ {
  94. t := DescribeLogDirsResponseTopic{}
  95. if err := t.decode(pd, version); err != nil {
  96. return err
  97. }
  98. r.Topics[i] = t
  99. }
  100. return nil
  101. }
  102. // DescribeLogDirsResponseTopic contains a topic's partitions descriptions
  103. type DescribeLogDirsResponseTopic struct {
  104. Topic string
  105. Partitions []DescribeLogDirsResponsePartition
  106. }
  107. func (r *DescribeLogDirsResponseTopic) encode(pe packetEncoder) error {
  108. if err := pe.putString(r.Topic); err != nil {
  109. return err
  110. }
  111. if err := pe.putArrayLength(len(r.Partitions)); err != nil {
  112. return err
  113. }
  114. for _, partition := range r.Partitions {
  115. if err := partition.encode(pe); err != nil {
  116. return err
  117. }
  118. }
  119. return nil
  120. }
  121. func (r *DescribeLogDirsResponseTopic) decode(pd packetDecoder, version int16) error {
  122. t, err := pd.getString()
  123. if err != nil {
  124. return err
  125. }
  126. r.Topic = t
  127. n, err := pd.getArrayLength()
  128. if err != nil {
  129. return err
  130. }
  131. r.Partitions = make([]DescribeLogDirsResponsePartition, n)
  132. for i := 0; i < n; i++ {
  133. p := DescribeLogDirsResponsePartition{}
  134. if err := p.decode(pd, version); err != nil {
  135. return err
  136. }
  137. r.Partitions[i] = p
  138. }
  139. return nil
  140. }
  141. // DescribeLogDirsResponsePartition describes a partition's log directory
  142. type DescribeLogDirsResponsePartition struct {
  143. PartitionID int32
  144. // The size of the log segments of the partition in bytes.
  145. Size int64
  146. // The lag of the log's LEO w.r.t. partition's HW (if it is the current log for the partition) or
  147. // current replica's LEO (if it is the future log for the partition)
  148. OffsetLag int64
  149. // True if this log is created by AlterReplicaLogDirsRequest and will replace the current log of
  150. // the replica in the future.
  151. IsTemporary bool
  152. }
  153. func (r *DescribeLogDirsResponsePartition) encode(pe packetEncoder) error {
  154. pe.putInt32(r.PartitionID)
  155. pe.putInt64(r.Size)
  156. pe.putInt64(r.OffsetLag)
  157. pe.putBool(r.IsTemporary)
  158. return nil
  159. }
  160. func (r *DescribeLogDirsResponsePartition) decode(pd packetDecoder, version int16) error {
  161. pID, err := pd.getInt32()
  162. if err != nil {
  163. return err
  164. }
  165. r.PartitionID = pID
  166. size, err := pd.getInt64()
  167. if err != nil {
  168. return err
  169. }
  170. r.Size = size
  171. lag, err := pd.getInt64()
  172. if err != nil {
  173. return err
  174. }
  175. r.OffsetLag = lag
  176. isTemp, err := pd.getBool()
  177. if err != nil {
  178. return err
  179. }
  180. r.IsTemporary = isTemp
  181. return nil
  182. }