Pregunta

We're in the middle of a bit of a big upgrade:

  • Rails 2.3 to Rails 3.2
  • ThinkingSphinx 1.4.1 to ThinkingSphinx 3.0.6
  • Sphinx 0.9.9 to Sphinx 2.0.8

And now our ThinkingSphinx configuration is broken. We have a multi-tenant setup, so it's a bit complicated as to how we connect. Our method set_sphinx_connection is called every time the search action is fired off. Here's how we used to do it:

def set_sphinx_connection
  Thread.current[:thinking_sphinx_environment] = "tenant_#{Tenant::active.id}"
  ThinkingSphinx::Configuration.instance.reset
end

And here's how we're trying to do it now:

def set_sphinx_connection
  framework = ThinkingSphinx::Frameworks::Plain.new
  framework.environment = "tenant_#{Tenant::active.id}"
  ThinkingSphinx::Configuration.instance.framework = framework
end

Each tenant has its own sphinx config file, and each is searching on its own port. An excerpt from our thinking_sphinx.yml is below:

tenant_1:
  mysql41: 9312
  enable_star: true
  min_infix_len: 1
tenant_2:
  mysql41: 9313
  enable_star: true
  min_infix_len: 1
tenant_3:
  mysql41: 9314
  enable_star: true
  min_infix_len: 1

If you only ever search on one tenant, it works just fine. However, when you search on one and then another, one of two errors are occurring:

  • stale ID errors on the second tenant
  • the search returns in counts from the first tenant to the second tenant

Does anyone have a way of getting this working? Pat if you're out there can you help?

UPDATE: We think it has to do with Passenger. When the first instance starts up, it works for that tenant consistently. However, from then on that passenger instance cannot search any other tenant.

¿Fue útil?

Solución 2

Putting this here in case someone else runs into this same issue. This was what ended up working.

def set_sphinx_connection
  framework = ThinkingSphinx::Frameworks::Plain.new
  framework.environment = "tenant_#{Tenant::active.id}"
  ThinkingSphinx::Configuration.instance.framework = framework
  ThinkingSphinx::Connection.pool.clear
end

Otros consejos

I think this is because Thinking Sphinx v3 persists Sphinx connections between searches. This can be disabled, but that feature appeared in TS v3.1.0, which will mean some more tweaks.

# in an initializer:
ThinkingSphinx::Connection.persistent = false

If you're sticking with Sphinx 2.0.8 (instead of, say, 2.1.4), please make sure you read the TS v3.1.0 release notes (which are probably worth a read anyway): https://github.com/pat/thinking-sphinx/releases/tag/v3.1.0

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top