Class: Couchbase::Management::CollectionQueryIndexManager
- Inherits:
-
Object
- Object
- Couchbase::Management::CollectionQueryIndexManager
- Defined in:
- lib/couchbase/management/collection_query_index_manager.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/management/collection_query_index_manager.rb more...
Instance Method Summary collapse
-
#build_deferred_indexes(options = Options::Query::BuildDeferredIndexes.new) ⇒ Object
Build all indexes which are currently in deferred state.
-
#create_index(index_name, fields, options = Options::Query::CreateIndex.new) ⇒ Object
Creates a new index.
-
#create_primary_index(options = Options::Query::CreatePrimaryIndex.new) ⇒ Object
Creates new primary index.
-
#drop_index(index_name, options = Options::Query::DropIndex.new) ⇒ Object
Drops the index.
-
#drop_primary_index(options = Options::Query::DropPrimaryIndex.new) ⇒ Object
Drops the primary index.
-
#get_all_indexes(options = Options::Query::GetAllIndexes.new) ⇒ Array<QueryIndex>
Fetches all indexes from the server.
-
#initialize(backend, bucket_name, scope_name, collection_name) ⇒ CollectionQueryIndexManager
constructor
A new instance of CollectionQueryIndexManager.
-
#watch_indexes(index_names, timeout, options = Options::Query::WatchIndexes.new) ⇒ Object
Polls indexes until they are online.
Constructor Details
#initialize(backend, bucket_name, scope_name, collection_name) ⇒ CollectionQueryIndexManager
Returns a new instance of CollectionQueryIndexManager.
28 29 30 31 32 33 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 28 def initialize(backend, bucket_name, scope_name, collection_name) @backend = backend @bucket_name = bucket_name @scope_name = scope_name @collection_name = collection_name end |
Instance Method Details
#build_deferred_indexes(options = Options::Query::BuildDeferredIndexes.new) ⇒ Object
Build all indexes which are currently in deferred state
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 168 def build_deferred_indexes( = Options::Query::BuildDeferredIndexes.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end @backend.collection_query_index_build_deferred(@bucket_name, @scope_name, @collection_name, .to_backend) end |
#create_index(index_name, fields, options = Options::Query::CreateIndex.new) ⇒ Object
Creates a new index
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 80 def create_index(index_name, fields, = Options::Query::CreateIndex.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end @backend.collection_query_index_create(@bucket_name, @scope_name, @collection_name, index_name, fields, .to_backend) end |
#create_primary_index(options = Options::Query::CreatePrimaryIndex.new) ⇒ Object
Creates new primary index
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 102 def create_primary_index( = Options::Query::CreatePrimaryIndex.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end @backend.collection_query_index_create_primary(@bucket_name, @scope_name, @collection_name, .to_backend) end |
#drop_index(index_name, options = Options::Query::DropIndex.new) ⇒ Object
Drops the index
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 125 def drop_index(index_name, = Options::Query::DropIndex.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end @backend.collection_query_index_drop(@bucket_name, @scope_name, @collection_name, index_name, .to_backend) end |
#drop_primary_index(options = Options::Query::DropPrimaryIndex.new) ⇒ Object
Drops the primary index
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 147 def drop_primary_index( = Options::Query::DropPrimaryIndex.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end @backend.collection_query_index_drop_primary(@bucket_name, @scope_name, @collection_name, .to_backend) end |
#get_all_indexes(options = Options::Query::GetAllIndexes.new) ⇒ Array<QueryIndex>
Fetches all indexes from the server
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 42 def get_all_indexes( = Options::Query::GetAllIndexes.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end res = @backend.collection_query_index_get_all(@bucket_name, @scope_name, @collection_name, .to_backend) res[:indexes].map do |idx| QueryIndex.new do |index| index.name = idx[:name] index.is_primary = idx[:is_primary] index.type = idx[:type] index.state = idx[:state] index.bucket = idx[:bucket_name] index.scope = idx[:scope_name] index.collection = idx[:collection_name] index.index_key = idx[:index_key] index.condition = idx[:condition] index.partition = idx[:partition] end end end |
#watch_indexes(index_names, timeout, options = Options::Query::WatchIndexes.new) ⇒ Object
Polls indexes until they are online
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 190 def watch_indexes(index_names, timeout, = Options::Query::WatchIndexes.new) unless .scope_name.nil? raise Error::InvalidArgument, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise Error::InvalidArgument, "Collection name cannot be set in the options when using the Query Index manager at the collection level" end index_names.append("#primary") if .watch_primary interval_millis = 50 deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001) while Time.now <= deadline get_all_opts = Options::Query::GetAllIndexes.new(timeout: ((deadline - Time.now) * 1000).round) indexes = get_all_indexes(get_all_opts).select { |idx| index_names.include? idx.name } indexes_not_found = index_names - indexes.map(&:name) raise Error::IndexNotFound, "Failed to find the indexes: #{indexes_not_found.join(', ')}" unless indexes_not_found.empty? all_online = indexes.all? { |idx| idx.state == :online } return if all_online sleep(interval_millis / 1000) interval_millis += 500 interval_millis = 1000 if interval_millis > 1000 end raise Error::UnambiguousTimeout, "Failed to find all indexes online within the allotted time" end |