数据压缩与加密
内存数据库可以进行压缩以节省内存,持久数据库的数据和日志文件也可以进行压缩以节省磁盘空间。数据还可以进行加密以确保安全。
内存数据库压缩
对于内存数据库压缩,配置文件选项 db_params:mode_mask 必须设置为 inmemory_compression 标志值。还可以显式设置选项 page_hash_bundles、compression_level、compression_mask 和 expected_compression_ratio。例如:
db_params:
{
mode_mask: in_memory_compression,
page_hash_bundles: 8,
compression_level: 1,
compression_mask: 3,
expected_compression_ratio: 4
}
持久数据库压缩
请注意,正如在“数据压缩”中所解释的那样,磁盘文件压缩仅在 Unix-Linux 平台上受支持。
若要在 SmartEDB 中启用压缩功能,配置文件必须指明要压缩(或已被压缩)的文件以及要加载的特殊文件系统库以管理压缩操作。(数据库文件必须使用库 mcofu98zip,而日志文件则使用库 mcofu98ziplog。)
例如,要压缩持久数据库文件 test.dbs,配置文件应为文件设备指定压缩标志值,并使用库 mcofu98zip 以及以下选项设置:
devices : [
{assignment: database, size : 100m},
{assignment: cache, size : 100m},
{type:file, assignment : persistent, name : test.dbs, flags: compressed},
{type:file, assignment : log, name : test.log},
],
runtime_configuration:
{
fs_library: mcofu98zip,
}
要压缩日志文件 test.log,配置文件应包含以下选项:
devices : [
{assignment: database, size : 100m},
{assignment: cache, size : 100m},
{type:file, assignment : persistent, name : test.dbs},
{type:file, assignment : log, name : test.log, flags: compressed },
],
runtime_configuration:
{
fs_library: mcofu98ziplog,
}
请注意,如果需要压缩数据库文件和日志文件,则必须运行两次 xSQL,一次使用 mcofu98zip 压缩数据库文件,一次使用 mcofu98ziplog 压缩日志文件——每次只能加载一个文件系统库,要么是 mcofu98zip,要么是 mcofu98ziplog。
物联网通信中的数据压缩
物联网通信中的数据压缩是通过设置 iot_params 配置文件部分的 compression_level 参数来实现的(该参数对应于结构体 mco_iot_comm_paramst_t 中的 compression_level 元素)。
此外,正如“数据压缩”页面中所解释的那样,这是用于确定压缩比的公式。可以调用 xsql_iot_list() SQL 函数来检索连接的统计信息;返回的结果集中的 rx_zratio 和 tx_zratio 字段(分别对应于结构体 mco_iot_connection_stat_t 中的元素 sent_compression_ratio 和 recv_compression_ratio)显示了传入和传出通信的压缩效率。
数据加密
要对磁盘数据库进行加密,配置文件的 db_params 部分必须包含 cipher_key 选项:
db_params : {
cipher_key : "my_secret_password"
}