Class: Couchbase::Protostellar::Management::CollectionQueryIndexManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/protostellar/management/collection_query_index_manager.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(client:, bucket_name:, scope_name:, collection_name:) ⇒ CollectionQueryIndexManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CollectionQueryIndexManager.



26
27
28
29
30
31
32
33
34
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 26

def initialize(client:, bucket_name:, scope_name:, collection_name:)
  @client = client
  @bucket_name = bucket_name
  @scope_name = scope_name
  @collection_name = collection_name
  @request_generator = RequestGenerator::Admin::Query.new(
    bucket_name: @bucket_name, scope_name: @scope_name, collection_name: @collection_name
  )
end

Instance Method Details

#build_deferred_indexes(options = Couchbase::Management::Options::Query::BuildDeferredIndexes.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
77
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 72

def build_deferred_indexes(options = Couchbase::Management::Options::Query::BuildDeferredIndexes.new)
  validate_options(options)

  req = @request_generator.build_deferred_indexes_request(options)
  @client.send_request(req)
end

#create_index(index_name, fields, options = Couchbase::Management::Options::Query::CreateIndex.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 44

def create_index(index_name, fields, options = Couchbase::Management::Options::Query::CreateIndex.new)
  validate_options(options)

  req = @request_generator.create_index_request(index_name, fields, options)
  @client.send_request(req)
end

#create_primary_index(options = Couchbase::Management::Options::Query::CreatePrimaryIndex.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
54
55
56
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 51

def create_primary_index(options = Couchbase::Management::Options::Query::CreatePrimaryIndex.new)
  validate_options(options)

  req = @request_generator.create_primary_index_request(options)
  @client.send_request(req)
end

#drop_index(index_name, options = Couchbase::Management::Options::Query::DropIndex.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
61
62
63
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 58

def drop_index(index_name, options = Couchbase::Management::Options::Query::DropIndex.new)
  validate_options(options)

  req = @request_generator.drop_index_request(index_name, options)
  @client.send_request(req)
end

#drop_primary_index(options = Couchbase::Management::Options::Query::DropPrimaryIndex.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
70
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 65

def drop_primary_index(options = Couchbase::Management::Options::Query::DropPrimaryIndex.new)
  validate_options(options)

  req = @request_generator.drop_primary_index_request(options)
  @client.send_request(req)
end

#get_all_indexes(options = Couchbase::Management::Options::Query::GetAllIndexes.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 36

def get_all_indexes(options = Couchbase::Management::Options::Query::GetAllIndexes.new)
  validate_options(options)

  req = @request_generator.get_all_indexes_request(options)
  resp = @client.send_request(req)
  ResponseConverter::Admin::Query.to_query_index_array(resp)
end

#watch_indexes(index_names, timeout, options = Couchbase::Management::Options::Query::WatchIndexes.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/couchbase/protostellar/management/collection_query_index_manager.rb', line 79

def watch_indexes(index_names, timeout, options = Couchbase::Management::Options::Query::WatchIndexes.new)
  validate_options(options)

  # TODO: Will this be implemented in the gateway instead?

  index_names.append("#primary") if options.watch_primary

  interval_millis = 50
  deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001)

  while Time.now <= deadline
    get_all_opts = Couchbase::Management::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)
    unless indexes_not_found.empty?
      raise Couchbase::Error::IndexNotFound,
            "Failed to find the indexes: #{indexes_not_found.join(', ')}"
    end

    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 Couchbase::Error::UnambiguousTimeout, "Failed to find all indexes online within the allotted time"
end