Class: Couchbase::Protostellar::Management::QueryIndexManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/protostellar/management/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:) ⇒ QueryIndexManager

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 QueryIndexManager.



26
27
28
29
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 26

def initialize(client:)
  @client = client
  @request_generator = RequestGenerator::Admin::Query.new
end

Instance Method Details

#build_deferred_indexes(bucket_name, 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.



67
68
69
70
71
72
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 67

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

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

#create_index(bucket_name, 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.



39
40
41
42
43
44
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 39

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

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

#create_primary_index(bucket_name, 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.



46
47
48
49
50
51
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 46

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

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

#drop_index(bucket_name, 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.



53
54
55
56
57
58
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 53

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

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

#drop_primary_index(bucket_name, 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.



60
61
62
63
64
65
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 60

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

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

#get_all_indexes(bucket_name, 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.



31
32
33
34
35
36
37
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 31

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

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

#watch_indexes(bucket_name, 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.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/couchbase/protostellar/management/query_index_manager.rb', line 74

def watch_indexes(bucket_name, 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(bucket_name, 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