Class: Pinot::TableAwareBrokerSelector

Inherits:
Object
  • Object
show all
Includes:
BrokerSelector
Defined in:
lib/pinot/table_aware_broker_selector.rb

Direct Known Subclasses

ControllerBasedBrokerSelector

Constant Summary collapse

OFFLINE_SUFFIX =
"_OFFLINE"
REALTIME_SUFFIX =
"_REALTIME"

Instance Method Summary collapse

Constructor Details

#initializeTableAwareBrokerSelector

Returns a new instance of TableAwareBrokerSelector.



8
9
10
11
12
# File 'lib/pinot/table_aware_broker_selector.rb', line 8

def initialize
  @mutex = Mutex.new
  @all_broker_list = []
  @table_broker_map = {}
end

Instance Method Details

#initObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/pinot/table_aware_broker_selector.rb', line 14

def init
  raise NotImplementedError, "subclasses must implement init"
end

#select_broker(table) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pinot/table_aware_broker_selector.rb', line 18

def select_broker(table)
  table_name = extract_table_name(table.to_s)
  @mutex.synchronize do
    if table_name.empty?
      raise BrokerNotFoundError, "no available broker" if @all_broker_list.empty?
      return @all_broker_list.sample
    end
    brokers = @table_broker_map[table_name]
    raise TableNotFoundError, "unable to find table: #{table}" unless brokers
    raise BrokerNotFoundError, "no available broker for table: #{table}" if brokers.empty?
    brokers.sample
  end
end

#update_broker_data(all_brokers, table_map) ⇒ Object



32
33
34
35
36
37
# File 'lib/pinot/table_aware_broker_selector.rb', line 32

def update_broker_data(all_brokers, table_map)
  @mutex.synchronize do
    @all_broker_list = all_brokers
    @table_broker_map = table_map
  end
end