maintenance_options.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Licensed to the LF AI & Data foundation under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. package client
  17. import (
  18. "time"
  19. "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
  20. )
  21. type LoadCollectionOption interface {
  22. Request() *milvuspb.LoadCollectionRequest
  23. CheckInterval() time.Duration
  24. }
  25. type loadCollectionOption struct {
  26. collectionName string
  27. interval time.Duration
  28. replicaNum int
  29. loadFields []string
  30. skipLoadDynamicField bool
  31. }
  32. func (opt *loadCollectionOption) Request() *milvuspb.LoadCollectionRequest {
  33. return &milvuspb.LoadCollectionRequest{
  34. CollectionName: opt.collectionName,
  35. ReplicaNumber: int32(opt.replicaNum),
  36. LoadFields: opt.loadFields,
  37. SkipLoadDynamicField: opt.skipLoadDynamicField,
  38. }
  39. }
  40. func (opt *loadCollectionOption) CheckInterval() time.Duration {
  41. return opt.interval
  42. }
  43. func (opt *loadCollectionOption) WithReplica(num int) *loadCollectionOption {
  44. opt.replicaNum = num
  45. return opt
  46. }
  47. func (opt *loadCollectionOption) WithLoadFields(loadFields ...string) *loadCollectionOption {
  48. opt.loadFields = loadFields
  49. return opt
  50. }
  51. func (opt *loadCollectionOption) WithSkipLoadDynamicField(skipFlag bool) *loadCollectionOption {
  52. opt.skipLoadDynamicField = skipFlag
  53. return opt
  54. }
  55. func NewLoadCollectionOption(collectionName string) *loadCollectionOption {
  56. return &loadCollectionOption{
  57. collectionName: collectionName,
  58. replicaNum: 1,
  59. interval: time.Millisecond * 200,
  60. }
  61. }
  62. type LoadPartitionsOption interface {
  63. Request() *milvuspb.LoadPartitionsRequest
  64. CheckInterval() time.Duration
  65. }
  66. var _ LoadPartitionsOption = (*loadPartitionsOption)(nil)
  67. type loadPartitionsOption struct {
  68. collectionName string
  69. partitionNames []string
  70. interval time.Duration
  71. replicaNum int
  72. loadFields []string
  73. skipLoadDynamicField bool
  74. }
  75. func (opt *loadPartitionsOption) Request() *milvuspb.LoadPartitionsRequest {
  76. return &milvuspb.LoadPartitionsRequest{
  77. CollectionName: opt.collectionName,
  78. PartitionNames: opt.partitionNames,
  79. ReplicaNumber: int32(opt.replicaNum),
  80. LoadFields: opt.loadFields,
  81. SkipLoadDynamicField: opt.skipLoadDynamicField,
  82. }
  83. }
  84. func (opt *loadPartitionsOption) CheckInterval() time.Duration {
  85. return opt.interval
  86. }
  87. func (opt *loadPartitionsOption) WithReplica(num int) *loadPartitionsOption {
  88. opt.replicaNum = num
  89. return opt
  90. }
  91. func (opt *loadPartitionsOption) WithLoadFields(loadFields ...string) *loadPartitionsOption {
  92. opt.loadFields = loadFields
  93. return opt
  94. }
  95. func (opt *loadPartitionsOption) WithSkipLoadDynamicField(skipFlag bool) *loadPartitionsOption {
  96. opt.skipLoadDynamicField = skipFlag
  97. return opt
  98. }
  99. func NewLoadPartitionsOption(collectionName string, partitionsNames ...string) *loadPartitionsOption {
  100. return &loadPartitionsOption{
  101. collectionName: collectionName,
  102. partitionNames: partitionsNames,
  103. replicaNum: 1,
  104. interval: time.Millisecond * 200,
  105. }
  106. }
  107. type ReleaseCollectionOption interface {
  108. Request() *milvuspb.ReleaseCollectionRequest
  109. }
  110. var _ ReleaseCollectionOption = (*releaseCollectionOption)(nil)
  111. type releaseCollectionOption struct {
  112. collectionName string
  113. }
  114. func (opt *releaseCollectionOption) Request() *milvuspb.ReleaseCollectionRequest {
  115. return &milvuspb.ReleaseCollectionRequest{
  116. CollectionName: opt.collectionName,
  117. }
  118. }
  119. func NewReleaseCollectionOption(collectionName string) *releaseCollectionOption {
  120. return &releaseCollectionOption{
  121. collectionName: collectionName,
  122. }
  123. }
  124. type ReleasePartitionsOption interface {
  125. Request() *milvuspb.ReleasePartitionsRequest
  126. }
  127. var _ ReleasePartitionsOption = (*releasePartitionsOption)(nil)
  128. type releasePartitionsOption struct {
  129. collectionName string
  130. partitionNames []string
  131. }
  132. func (opt *releasePartitionsOption) Request() *milvuspb.ReleasePartitionsRequest {
  133. return &milvuspb.ReleasePartitionsRequest{
  134. CollectionName: opt.collectionName,
  135. PartitionNames: opt.partitionNames,
  136. }
  137. }
  138. func NewReleasePartitionsOptions(collectionName string, partitionNames ...string) *releasePartitionsOption {
  139. return &releasePartitionsOption{
  140. collectionName: collectionName,
  141. partitionNames: partitionNames,
  142. }
  143. }
  144. type FlushOption interface {
  145. Request() *milvuspb.FlushRequest
  146. CollectionName() string
  147. CheckInterval() time.Duration
  148. }
  149. type flushOption struct {
  150. collectionName string
  151. interval time.Duration
  152. }
  153. func (opt *flushOption) Request() *milvuspb.FlushRequest {
  154. return &milvuspb.FlushRequest{
  155. CollectionNames: []string{opt.collectionName},
  156. }
  157. }
  158. func (opt *flushOption) CollectionName() string {
  159. return opt.collectionName
  160. }
  161. func (opt *flushOption) CheckInterval() time.Duration {
  162. return opt.interval
  163. }
  164. func NewFlushOption(collName string) *flushOption {
  165. return &flushOption{
  166. collectionName: collName,
  167. interval: time.Millisecond * 200,
  168. }
  169. }