25.5.6 NDB 集群表中的 BLOB 和 TEXT 列检查和修复工具 — ndb_blob_tool
该工具可以用于检查并从NDB表中删除孤立的 BLOB 列部分,以及生成包含孤立部分的文件列表。它有时在诊断和修复损坏或损害的NDB表中包含BLOB或TEXT列时非常有用。
ndb_blob_tool 的基本语法如下:
ndb_blob_tool [options] table [column, ...]
除非使用--help选项,您必须指定要执行的操作,包括一个或多个选项:--check-orphans、--delete-orphans或--dump-file。这些选项会导致ndb_blob_tool检查孤儿BLOB部分、删除任何孤儿BLOB部分和生成一个列出孤儿BLOB部分的dump文件,分别对应于后续本节中更详细描述的操作。
在调用ndb_ blob_tool时,您还需要指定表名。另外,您可以选择在表名后跟随一个或多个该表的BLOB或TEXT列的名称(以逗号分隔)。如果未指定列名,工具将对该表中的所有BLOB和TEXT列进行操作。如果需要指定数据库,请使用--database(-d)选项。
--verbose 选项将在输出中提供工具进度的额外信息。
以下是ndb_ mgmd可用的所有选项的表格。额外描述在表格后面。
-
Command-Line Format --add-missing对于 NDB 集群表中的每个内联部分,如果没有相应的 BLOB 部分,则写入一个 dummy BLOB 部分,长度为所需长度,内容为空格。
-
Command-Line Format --character-sets-dir=路径包含字符集的目录。
-
Command-Line Format --check-missing检查 NDB 集群表中的内联部分是否有相应的 BLOB 部分。
-
Command-Line Format --check-orphans检查 NDB 集群表中的 BLOB 部分是否有相应的内联部分。
-
Command-Line Format --connect-retries=#Type 整数 Default Value 12Minimum Value 0Maximum Value 12连接失败重试的次数。
-
Command-Line Format --connect-retry-delay=#Type Integer Default Value 5Minimum Value 0Maximum Value 5连接管理服务器时等待的秒数。
-
Command-Line Format --connect-string=connection_stringType String Default Value [none] -
Command-Line Format --core-file错误时写入核心文件;用于调试。
-
Command-Line Format --database=nameType String Default Value [none]指定要查找表的数据库名称。
-
Command-Line Format --defaults-extra-file=路径Type 字符串 Default Value [none]在读取全局文件后,读取给定的文件。
-
Command-Line Format --defaults-file=路径Type 字符串 Default Value [none]从给定的文件中读取默认选项。
-
Command-Line Format --defaults-group-suffix=字符串Type 字符串 Default Value [none]也读取concat(组,后缀)中的组。
-
Command-Line Format --delete-orphans从 NDB 集群表中删除没有相应 inline 部分的 BLOB 部分。
-
Command-Line Format --dump-file=文件Type 文件名称 Default Value [none]将 orphaned BLOB 列的列表写入到
file中。该文件中的信息包括每个 orphaned BLOB 部分的表键和 BLOB 部分号。 -
Command-Line Format --help显示帮助文本并退出。
-
Command-Line Format --login-path=pathType 字符串 Default Value [none]从登录文件中读取给定的路径。
-
Command-Line Format --no-login-paths跳过从登录路径文件中读取选项。
-
Command-Line Format --ndb-connectstring=connection_stringType 字符串 Default Value [none]设置连接字符串,以连接到ndb_ mgmd。语法:
[nodeid=。覆盖了id;][host=]hostname[:port]NDB_ CONNECTSTRING和my.cnf中的条目。 -
Command-Line Format --ndb-mgm-tls=levelType 枚举 Default Value relaxedValid Values relaxedstrict设置连接到管理服务器所需的TLS支持级别;可以是
relaxed或strict。relaxed(默认)表示尝试建立TLS连接,但成功不要求;strict表示需要TLS连接。 -
Command-Line Format --ndb-mgmd-host=connection_stringType 字符串 Default Value [none] -
Command-Line Format --ndb-nodeid=#Type 整数 Default Value [none]将当前节点的ID设置为指定值,覆盖由
--ndb-connectstring设置的ID。 -
--ndb-optimized-node-selectionCommand-Line Format --ndb-optimized-node-selection启用事务节点选择优化。默认启用,可以使用
--skip-ndb-optimized-node-selection来禁用。 -
Command-Line Format --ndb-tls-search-path=列表Type 路径名称 Default Value (Unix) $HOME/ndb-tlsDefault Value (Windows) $HOMEDIR/ndb-tls指定搜索CA文件的目录列表。Unix平台上,目录名称使用冒点(
:)分隔;Windows系统中,分隔符为分号(;)。目录引用可以是相对或绝对路径,可以包含一个或多个环境变量,每个变量以前缀的美元符号($)表示,并在使用时展开。搜索从左侧命名目录开始,自左向右直到找到文件为止。空字符串表示空搜索路径,这将导致所有搜索失败。包含单个点(
.)的字符串表示搜索路径限制于当前工作目录。如果未提供搜索路径,则使用编译时默认值。这取决于平台:在Windows上,这是
\ndb-tls;在其他平台(包括Linux)中,这是$HOME/ndb-tls。可以通过编译NDB集群使用-DWITH_NDB_TLS_SEARCH_PATH来覆盖该值。 -
Command-Line Format --no-defaults不从任何选项文件中读取默认选项,除了登录文件。
-
Command-Line Format --print-defaults打印程序参数列表并退出。
-
Command-Line Format --usage显示帮助文本并退出;与 --help相同。
-
Command-Line Format --verbose在工具的输出中提供额外信息,以便了解其进度。
-
Command-Line Format --version显示版本信息并退出。
首先,我们在 test 数据库中创建一个 NDB 表,使用以下语句:
USE test;
CREATE TABLE btest (
c0 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
c1 TEXT,
c2 BLOB
) ENGINE=NDB;
然后,我们将一些行插入到这个表中,使用一系列类似于以下语句的语句:
INSERT INTO btest VALUES (NULL, 'x', REPEAT('x', 1000));
当使用 --check-orphans 对这个表进行检查时,ndb_blob_工具 生成以下输出:
$> ndb_blob_tool --check-orphans --verbose -d test btest
connected
processing 2 blobs
processing blob #0 c1 NDB$BLOB_19_1
NDB$BLOB_19_1: nextResult: res=1
total parts: 0
orphan parts: 0
processing blob #1 c2 NDB$BLOB_19_2
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=0
NDB$BLOB_19_2: nextResult: res=1
total parts: 10
orphan parts: 0
disconnected
工具报告说,列c1没有关联的NDBBLOB列部分,即使c1是一个TEXT列。这是因为在NDB表中,只有BLOB或TEXT列的前256个字节存储在行内,超过256个字节的部分则单独存储;因此,如果某个类型的列中没有使用超过256个字节的值,那么NDB就不会为该列创建BLOB列部分。请参阅第13.7节,“数据类型存储要求”,了解更多信息。