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.
27 28 29 30 31 32 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 27 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
149 150 151 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 149 def build_deferred_indexes( = Options::Query::BuildDeferredIndexes.new) @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
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 69 def create_index(index_name, fields, = Options::Query::CreateIndex.new) unless .scope_name.nil? raise ArgumentError, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise ArgumentError, "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
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 89 def create_primary_index( = Options::Query::CreatePrimaryIndex.new) unless .scope_name.nil? raise ArgumentError, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise ArgumentError, "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
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 110 def drop_index(index_name, = Options::Query::DropIndex.new) unless .scope_name.nil? raise ArgumentError, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise ArgumentError, "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
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 130 def drop_primary_index( = Options::Query::DropPrimaryIndex.new) unless .scope_name.nil? raise ArgumentError, "Scope name cannot be set in the options when using the Query Index manager at the collection level" end unless .collection_name.nil? raise ArgumentError, "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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 41 def get_all_indexes( = Options::Query::GetAllIndexes.new) 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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/couchbase/management/collection_query_index_manager.rb', line 161 def watch_indexes(index_names, timeout, = Options::Query::WatchIndexes.new) 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 |