Skip to content

Commit

Permalink
Merge pull request #70 from bibendi/robin-rabin
Browse files Browse the repository at this point in the history
feature: rejection of master node. searchd connection pooling
  • Loading branch information
bibendi committed Oct 20, 2015
2 parents 302000f + 8400c44 commit 350a958
Show file tree
Hide file tree
Showing 48 changed files with 1,265 additions and 1,552 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test/tmp
test/version_tmp
tmp
spec/internal/config/database.yml
spec/internal/config/sphinx.yml
combustion
.ruby-version
Makefile.local
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--color
--tty
--format progress
--order random
71 changes: 26 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
## Rake tasks
Если в параметрах не передавать node, то по умолчанию комманда будет выполнена на всех нодах

rake sphinx:start[node]
rake sphinx:stop[node]
rake sphinx:restart[node]
rake sphinx:index[node,offline]
rake sphinx:rebuild[node]
rake sphinx:start[host]
rake sphinx:stop[host]
rake sphinx:restart[host]
rake sphinx:index[host,offline]
rake sphinx:rebuild[host]
rake sphinx:conf
rake sphinx:copy_conf[node]
rake sphinx:rm_indexes[node]
rake sphinx:rm_binlog[node]
rake sphinx:copy_conf[host]
rake sphinx:rm_indexes[host]
rake sphinx:rm_binlog[host]

*Внимание* при офлайн индексации rt индексы не очищаются. Рекоммендуется в этом случае использовать rebuild

Expand All @@ -36,7 +36,6 @@ development:
address: localhost
port: 10300
mysql41: 9300
listen_all_interfaces: true

max_matches: 5000
version: 2.0.3
Expand All @@ -61,7 +60,6 @@ production:
address: index
port: 10300
mysql41: 9300
listen_all_interfaces: true

max_matches: 5000
version: 2.0.3
Expand All @@ -75,30 +73,30 @@ production:
dist_threads: 2
binlog_max_log_size: 1024M
rt_flush_period: 86400
log_level: fatal
mysql_connect_timeout: 2
mysql_read_timeout: 5

user: sphinx
remote_path: /home/index
query_log_file: /dev/null
searchd_log_file: logs/searchd.log
pid_file: pid/searchd.pid
searchd_file_path: data
binlog_path: binlog
log_level: warn
mysql_connect_timeout: 2
mysql_read_timeout: 5
searchd_log_file: /absolute/path/to/logs/searchd.log
pid_file: /absolute/path/to/pid/searchd.pid
searchd_file_path: /absolute/path/to/data
binlog_path: /absolute/path/to/binlog
```
### production with replication
```yml
production:
remote: true
replication: true

address: index
address:
- index-slave1
- index-slave2
port: 10300
mysql41: 9300
listen_all_interfaces: false
ssh_port: 22123

max_matches: 5000
version: 2.0.3
Expand All @@ -112,33 +110,16 @@ production:
dist_threads: 2
binlog_max_log_size: 1024M
rt_flush_period: 86400
agent_connect_timeout: 50
ha_strategy: nodeads
log_level: warn
log_level: fatal
mysql_connect_timeout: 2
mysql_read_timeout: 5

user: sphinx
remote_path: /home/index/master
query_log_file: /dev/null
searchd_log_file: logs/searchd.log
pid_file: pid/searchd.pid
searchd_file_path: data
binlog_path: binlog

agents:
slave1:
address: index
port: 10301
mysql41: 9301
listen_all_interfaces: true
remote_path: /home/index/slave
slave2:
address: index2
port: 10302
mysql41: 9302
listen_all_interfaces: true
remote_path: /home/index/slave
searchd_log_file: /absolute/path/to/logs/searchd.log
pid_file: /absolute/path/to/pid/searchd.pid
searchd_file_path: /absolute/path/to/data
binlog_path: /absolute/path/to/binlog
```
Expand All @@ -160,9 +141,9 @@ Workflow:
Когда запускается очередная полная индексация:
+ начинает наполнятся core индекс сфинксовым индексатором
+ но в этот момент данные могут обновляться, записываться в rt индекс они будут, но потом всё равно удаляться после завершения полной индексации
+ для того, чтобы не потерять обновления данные начинают попадать в дополнительный delta_rt индекс
+ для того, чтобы не потерять обновления данные начинают попадать в дополнительный rt индекс
+ после завершения полной индексации, очищается основной rt индекс
+ и в него перетекают данные из delta rt индекса
+ а дополнительный rt индекс становится основным

## Дополнительные возможности конфигурировани индекса

Expand Down
3 changes: 3 additions & 0 deletions lib/sphinx/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module Integration
autoload :Helper, 'sphinx/integration/helper'
autoload :Mysql, 'sphinx/integration/mysql'
autoload :Searchd, 'sphinx/integration/searchd'
autoload :Decaying, 'sphinx/integration/decaying'
autoload :Transmitter, 'sphinx/integration/transmitter'
autoload :FastFacet, 'sphinx/integration/fast_facet'
autoload :RecentRt, 'sphinx/integration/recent_rt'
autoload :WasteRecords, 'sphinx/integration/waste_records'
autoload :ServerPool, 'sphinx/integration/server_pool'
autoload :Server, 'sphinx/integration/server'
end
end

Expand Down
36 changes: 36 additions & 0 deletions lib/sphinx/integration/decaying.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Sphinx
module Integration
# A float value which decays exponentially toward 0 over time.
class Decaying
attr_accessor :e
attr_accessor :p

# opts - Hash
# :p - Float (0.0) The initial value
# :e - Float (Math::E) Exponent base
# :r - Float (Math.log(0.5) / 10) Timescale factor - defaulting to decay 50% every 10 seconds
def initialize(opts = {})
@p = opts[:p] || 0.0
@e = opts[:e] || Math::E
@r = opts[:r] || Math.log(0.5) / 10
@t0 = Time.now
end

# Add to current value
#
# d - Float value to add
def <<(d)
@p = value + d
end

# Returns Float the current value (adjusted for the time decay)
def value
return 0.0 unless @p > 0
now = Time.now
dt = now - @t0
@t0 = now
@p *= @e**(@r * dt)
end
end
end
end
24 changes: 21 additions & 3 deletions lib/sphinx/integration/extensions/riddle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@ module Client
extend ActiveSupport::Concern

included do
alias_method_chain :initialize, :pooling
alias_method_chain :connect, :pooling
alias_method_chain :request, :pooling
end

module ClassMethods
def server_pool
@server_pool
end

def init_server_pool(servers, host)
@server_pool = ::Sphinx::Integration::ServerPool.new(servers, host, mysql: false)
end
end

def initialize_with_pooling(*args)
initialize_without_pooling(*args)

self.class.init_server_pool(@servers, @port) unless self.class.server_pool
end

def connect_with_pooling
options = {server: servers.sample, port: @port}
::Sphinx::Integration::Searchd::ConnectionPool.take(options) do |socket|
yield socket
self.class.server_pool.take do |server|
server.take do |connection|
yield connection.socket
end
end
end

Expand Down
20 changes: 4 additions & 16 deletions lib/sphinx/integration/extensions/riddle/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@
module Sphinx::Integration::Extensions
module Riddle
module Configuration
autoload :Searchd, 'sphinx/integration/extensions/riddle/configuration/searchd'
autoload :DistributedIndex, 'sphinx/integration/extensions/riddle/configuration/distributed_index'

extend ActiveSupport::Concern

included do
alias_method_chain :render, :integration
end

def render_with_integration(config_type, agent)
if config_type == :slave
searchd = @searchd.dup
searchd.address = agent[:address]
searchd.port = agent[:port]
searchd.mysql41 = agent[:mysql41]
searchd.listen_all_interfaces = agent.fetch(:listen_all_interfaces, true)
searchd.remote_path = Pathname.new(agent[:remote_path]) if agent.key?(:remote_path)
else
searchd = @searchd
end
def render_with_integration
searchd = @searchd

listen_ip = searchd.listen_all_interfaces ? '0.0.0.0' : searchd.address
listen_ip = "0.0.0.0"
searchd.listen = [
"#{listen_ip}:#{searchd.port}",
"#{listen_ip}:#{searchd.mysql41.is_a?(TrueClass) ? '9306' : searchd.mysql41}:mysql41",
]

(
[config_type == :master ? nil : @indexer.render, searchd.render].compact +
[@indexer.render, searchd.render].compact +
@sources.collect { |source| source.render } +
@indices.collect { |index| index.render }
).join("\n")
Expand Down

This file was deleted.

38 changes: 0 additions & 38 deletions lib/sphinx/integration/extensions/riddle/configuration/searchd.rb

This file was deleted.

Loading

0 comments on commit 350a958

Please sign in to comment.