blog-post

掌握 Manticore Search:RT 模式与 Plain 模式解析

你是否曾对 Manticore Search 中的不同模式感到困惑?你并不孤单。许多开发人员在第一次使用 Manticore Search 时都困惑于实时 (RT) 模式与 Plain 模式之间的区别。但别担心 - 一旦理解了核心概念,实际上这非常简单。

在本指南中,我们将阐明这两种操作模式,并向您展示何时以及如何使用每一种。

理解 Manticore Search 模式

Manticore Search 提供两种主要的操作模式:

  • 实时 (RT) 模式 - 默认模式,允许您动态创建和删除表
  • Plain 模式 - 与静态架构和来自外部存储源构建的普通表一起工作

让我们深入研究每种模式,以了解它们的能力和局限性。

实时 (RT) 模式:动态与灵活

RT 模式是 Manticore Search 中的默认和最常用模式。它旨在动态环境中使用,您可以在不重新启动服务的情况下创建、修改或删除表。

如何识别 RT 模式

RT 模式的关键指标是在配置文件中存在 data_dir 指令。让我们来看一个典型的配置:

cat /opt/homebrew/etc/manticoresearch/manticore.conf
searchd {
    listen = 127.0.0.1:9312
    listen = 127.0.0.1:9306:mysql
    listen = 127.0.0.1:9308:http
    log = /opt/homebrew/var/log/manticore/searchd.log
    query_log = /opt/homebrew/var/log/manticore/query.log
    pid_file = /opt/homebrew/var/run/manticore/searchd.pid
    data_dir = /opt/homebrew/var/manticore
}

注意配置中的 data_dir 指令。这一行就是使 RT 模式得以启用的关键。

动态创建表

RT 模式最大优势之一是能够动态创建表:

mysql -P9306 -h0 -v
欢迎使用 MySQL 监视器。命令以 ; 或 \g 结束。
您的 MySQL 连接 ID 是 759523
服务器版本:7.0.1 763f4a0b9@25013111 dev (columnar 4.0.1 9f6686d@25012409) (secondary 4.0.1 9f6686d@25012409) (knn 4.0.1 9f6686d@25012409) git branch master...origin/master

版权所有 (c) 2000, 2024, Oracle 和/或其附属公司。

Oracle 是 Oracle Corporation 和/或其
附属公司的注册商标。其他名称可能是其各自
所有者的商标。

读取历史文件 /Users/sn/.mysql_history
输入 'help;' 或 '\h' 获取帮助。输入 '\c' 清除当前输入语句。

创建一个表就像这样简单:

mysql> create table t;
查询 OK, 受影响的行数为 0 (0.00 sec)

删除表同样简单:

mysql> drop table t;
查询 OK, 受影响的行数为 0 (0.01 sec)

复制支持

RT 模式独具的另一个强大功能是复制。您可以创建集群并向其添加表:

mysql> create table t;
查询 OK, 受影响的行数为 0 (0.00 sec)
mysql> create cluster c;
查询 OK, 受影响的行数为 0 (0.44 sec)
mysql> alter cluster c add t;
查询 OK, 受影响的行数为 0 (0.00 sec)

Plain 模式:稳定与结构化

Plain 模式旨在为您的架构相对稳定并提前定义的环境而设计。当需要处理外部数据源时,它特别有用。

如何识别 Plain 模式

在配置文件中缺少 data_dir 指令表示 Plain 模式。让我们来看一个 Plain 模式的配置:

cat ~/manticore/plain.conf
searchd {
  listen = 9315:mysql41
  log = searchd.log
  pid_file = searchd.pid
  binlog_path =
}

source src {
  type = csvpipe
  csvpipe_command = echo "1,abcdef,123"
  csvpipe_field = f
  csvpipe_attr_uint = a
}

table idx {
  type = plain
  source = src
  path = idx
}

table rt {
  type = rt
  path = rt
  rt_field = f
  rt_attr_uint = a
}

请注意没有 data_dir 指令,但配置文件中直接有表的定义。

启动 Plain 模式实例

让我们在 Plain 模式下启动 Manticore Search:

searchd -c plain.conf
Manticore 7.0.0 92c650401@25013002 (columnar 4.0.0 5aa8e43@25012409) (secondary 4.0.0 5aa8e43@25012409) (knn 4.0.0 5aa8e43@25012409)
版权所有 (c) 2001-2016, Andrew Aksyonoff
版权所有 (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
版权所有 (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)

[26:49.002] [20433033] 使用配置文件 '/Users/sn/manticore/plain.conf' (344 字符)...
启动守护进程版本 '7.0.0 92c650401@25013002 (columnar 4.0.0 5aa8e43@25012409) (secondary 4.0.0 5aa8e43@25012409) (knn 4.0.0 5aa8e43@25012409)' ...
在所有接口上监听 mysql,端口=9315
预缓存表 'idx'
索引头格式不是 json,将尝试将其作为二进制格式...
警告:无法加载头... 错误:无法打开 idx.sph:没有这样的文件或目录
警告:表 'idx':预分配:无法打开 idx.sph:没有这样的文件或目录 - 不提供服务
预缓存表 'rt'
在 0.004 秒内预缓存了 1 张表

在 Plain 模式下处理表

当我们检查可用表时,可以看到最初只有 RT 表可用:

mysql -P9315 -h0 -e "show tables"
+-------+------+
| 表      | 类型   |
+-------+------+
| rt    | rt   |
+-------+------+

为了使普通表可用,我们需要使用索引器工具构建它:

indexer -c plain.conf --all --rotate
Manticore 7.0.0 92c650401@25013002 (columnar 4.0.0 5aa8e43@25012409) (secondary 4.0.0 5aa8e43@25012409) (knn 4.0.0 5aa8e43@25012409)
版权所有 (c) 2001-2016, Andrew Aksyonoff
版权所有 (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
版权所有 (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)

using config file '/Users/sn/manticore/plain.conf'...
indexing table 'idx'...
collected 1 docs, 0.0 MB
creating secondary index
creating lookup: 0.0 Kdocs, 100.0% done
sorted 0.0 Mhits, 100.0% done
total 1 docs, 6 bytes
total 0.029 sec, 203 bytes/sec, 33.96 docs/sec
WARNING: skipping non-plain table 'rt'...
total 3 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 15 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
rotating tables: successfully sent SIGHUP to searchd (pid=89954).

After reloading the tables:

mysql -P9315 -h0 -e "reload tables"

Now both tables are available:

mysql -P9315 -h0 -e "show tables"
+-------+-------+
| Table | Type  |
+-------+-------+
| idx   | local |
| rt    | rt    |
+-------+-------+

Limitations of Plain Mode

In Plain mode, you cannot create tables dynamically:

mysql -P9315 -h0 -e "create table t"
ERROR 1064 (42000) at line 1: CREATE TABLE requires data_dir to be set in the config file

Replication is also not available:

mysql -P9315 -h0 -e "create cluster c"
ERROR 1064 (42000) at line 1: can not create cluster 'c': no 'listen' is found, cannot set incoming addresses, replication is disabled

When to Use Each Mode

Use RT Mode when:

  • You need to create or modify tables frequently
  • You want to use replication features
  • You prefer a more dynamic, flexible environment
  • You’re building applications that need to adapt to changing requirements

Use Plain Mode when:

  • Your schema is stable and well-defined
  • You’re primarily working with external data sources
  • You want to ensure schema consistency across deployments
  • You need a more controlled, configuration-driven approach

Conclusion

Understanding the difference between RT and Plain modes in Manticore Search is essential for optimizing your search implementation. RT mode offers flexibility and dynamic table management, while Plain mode provides stability and structure.

For most modern applications, RT mode is the recommended choice due to its flexibility and feature set. However, Plain mode still has its place, especially in environments where schema stability and configuration portability are priorities.

Prefer watching over reading? Check out our video on this topic:

Remember, the key to identifying which mode you’re using is simple: if there’s a data_dir directive in your configuration, you’re in RT mode; if not, you’re in Plain mode.

安装Manticore Search

安装Manticore Search