Class: Couchbase::Management::QueryIndexManager
- Inherits:
-
Object
- Object
- Couchbase::Management::QueryIndexManager
- Defined in:
- lib/couchbase/management/query_index_manager.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/management/query_index_manager.rb
Instance Method Summary collapse
-
#build_deferred_indexes(bucket_name, options = Options::Query::BuildDeferredIndexes.new) ⇒ Object
Build all indexes which are currently in deferred state.
-
#create_index(bucket_name, index_name, fields, options = Options::Query::CreateIndex.new) ⇒ Object
Creates a new index.
-
#create_primary_index(bucket_name, options = Options::Query::CreatePrimaryIndex.new) ⇒ Object
Creates new primary index.
-
#drop_index(bucket_name, index_name, options = Options::Query::DropIndex.new) ⇒ Object
Drops the index.
-
#drop_primary_index(bucket_name, options = Options::Query::DropPrimaryIndex.new) ⇒ Object
Drops the primary index.
-
#get_all_indexes(bucket_name, options = GetAllIndexOptions.new) ⇒ Array<QueryIndex>
Fetches all indexes from the server.
-
#watch_indexes(bucket_name, index_names, timeout, options = Options::Query::WatchIndexes.new) ⇒ Object
Polls indexes until they are online.
Instance Method Details
#build_deferred_indexes(bucket_name, options = Options::Query::BuildDeferredIndexes.new) ⇒ Object
Build all indexes which are currently in deferred state
535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/couchbase/management/query_index_manager.rb', line 535 def build_deferred_indexes(bucket_name, = Options::Query::BuildDeferredIndexes.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_BUILD_DEFERRED_INDEXES, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? @backend.query_index_build_deferred(bucket_name, .to_backend, obs_handler) end end |
#create_index(bucket_name, index_name, fields, options = Options::Query::CreateIndex.new) ⇒ Object
Creates a new index
443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/couchbase/management/query_index_manager.rb', line 443 def create_index(bucket_name, index_name, fields, = Options::Query::CreateIndex.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_CREATE_INDEX, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? @backend.query_index_create(bucket_name, index_name, fields, .to_backend, obs_handler) end end |
#create_primary_index(bucket_name, options = Options::Query::CreatePrimaryIndex.new) ⇒ Object
Creates new primary index
466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/couchbase/management/query_index_manager.rb', line 466 def create_primary_index(bucket_name, = Options::Query::CreatePrimaryIndex.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_CREATE_PRIMARY_INDEX, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? @backend.query_index_create_primary(bucket_name, .to_backend, obs_handler) end end |
#drop_index(bucket_name, index_name, options = Options::Query::DropIndex.new) ⇒ Object
Drops the index
490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/couchbase/management/query_index_manager.rb', line 490 def drop_index(bucket_name, index_name, = Options::Query::DropIndex.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_DROP_INDEX, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? @backend.query_index_drop(bucket_name, index_name, .to_backend, obs_handler) end end |
#drop_primary_index(bucket_name, options = Options::Query::DropPrimaryIndex.new) ⇒ Object
Drops the primary index
513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/couchbase/management/query_index_manager.rb', line 513 def drop_primary_index(bucket_name, = Options::Query::DropPrimaryIndex.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_DROP_PRIMARY_INDEX, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? @backend.query_index_drop_primary(bucket_name, .to_backend, obs_handler) end end |
#get_all_indexes(bucket_name, options = GetAllIndexOptions.new) ⇒ Array<QueryIndex>
Fetches all indexes from the server
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/couchbase/management/query_index_manager.rb', line 404 def get_all_indexes(bucket_name, = GetAllIndexOptions.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_GET_ALL_INDEXES, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? res = @backend.query_index_get_all(bucket_name, .to_backend, obs_handler) 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 end |
#watch_indexes(bucket_name, index_names, timeout, options = Options::Query::WatchIndexes.new) ⇒ Object
Polls indexes until they are online
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/couchbase/management/query_index_manager.rb', line 558 def watch_indexes(bucket_name, index_names, timeout, = Options::Query::WatchIndexes.new) unless .scope_name.nil? && .collection_name.nil? warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead" end @observability.record_operation(Observability::OP_QM_WATCH_INDEXES, .parent_span, self, :query) do |obs_handler| obs_handler.add_bucket_name(bucket_name) obs_handler.add_scope_name(.scope_name) unless .scope_name.nil? obs_handler.add_collection_name(.collection_name) unless .collection_name.nil? index_names.append("#primary") if .watch_primary interval_millis = 50 deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001) all_online = false while Time.now <= deadline get_all_opts = Options::Query::GetAllIndexes.new( timeout: ((deadline - Time.now) * 1000).round, scope_name: .scope_name, collection_name: .collection_name, parent_span: obs_handler.op_span, ) indexes = get_all_indexes(bucket_name, 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 } break 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" unless all_online end end |