【问题标题】:Sphinx and real time index with mysql innodb transactionSphinx 和带有 mysql innodb 事务的实时索引
【发布时间】:2012-05-28 14:00:48
【问题描述】:

是否可以结合使用 Sphinx RT 索引和 Mysql innodb 表来支持事务?

例如,我在 mysql 中有一个表 products,我在 Sphinx 中构建了一个实时索引以进行全文搜索。当在 mysql 中更新产品行时,我希望 Sphinx 中的索引也必须实时更新,以便立即对更新产品进行全文搜索,但都以一致的方式。

如果产品行更新失败或实时索引更新失败,都必须回滚以避免不一致。有可能的?我怎样才能得到这个?

【问题讨论】:

    标签: mysql innodb real-time sphinx


    【解决方案1】:

    是的,这是可能的,但它有一些怪癖。 Sphinx 支持事务(开始/语句/(提交,回滚)),但仅限于单个实时索引。这意味着,如果您想在单个事务中写入多个索引,它将无法工作。 假设您有以下 mysql 表和 sphinx 实时索引,它们之间有直接的对应关系:

      posts_db      -> posts_rt
      comments_db   -> comments_rt
    

    在 mysql 中很容易在一个事务中写入两个表:

    START TRANSACTION;
        INSERT INTO posts_db ...;
        INSERT INTO comments_db ...;
    COMMIT or ROLLBACK; // so far everthing ok
    

    但如果你想对 sphinx 做同样的事情,它会失败:

    START TRANSACTION;
        INSERT INTO posts_rt ...;
        // when executing the next statement you'll get an error
        INSERT INTO comments_rt ...;  // ERROR 1064 (42000): current txn is working with another index ('posts_rt')
    

    在 sphinx 中,您一次只能使用一个索引:

    START TRANSACTION;
        INSERT INTO posts_rt ...;
    COMMIT or ROLLBACK; // so far everthing ok
    
    START TRANSACTION;
        INSERT INTO comments_db ...;
    COMMIT or ROLLBACK; // so far everthing ok
    

    这太糟糕了!!!这对于单索引应用程序来说很好,但对于其他情况,您必须使用 php 或您使用的任何东西来模拟事务。

    【讨论】:

      【解决方案2】:

      是的,这是可能的。这是实时索引的描述 http://sphinxsearch.com/docs/current.html#rt-indexes

      【讨论】:

      • 如果我理解得很好,我会在 Sphinx 中创建索引,例如在示例中将其称为 rt,然后在 mysql 中直接执行 REPLACE 语句以在 Sphinx 中更新 rt 索引值存储?这个语句可以在交易中间吗?所以如果我执行回滚或提交失败,它会 UNTOUCH rt 索引吗?
      猜你喜欢
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 2011-10-18
      • 1970-01-01
      相关资源
      最近更新 更多