大约 4 分钟
应用场景
部分应用中只有 2 台机器资源,因此只能部署 2 个 IoTDB 实例,但希望实现双活高可用效果,两个节点实现自动数据同步,向其中一个写入的数据,另一个也能接收到,且一个节点失效后能够自动将读写切换到另一个节点。
本场景有三个角色:客户端,IoTDB-A,IoTDB-B, 3 个角色互相连通。
IoTDB-A 与 IoTDB-B 互为主备(对于 A 来说,B 是备库,对于 B 来说,A 是备库)。
名词定义
- DDL: Data definition languge,元数据增删改
- DML: Data manipulation languge,数据增删
功能定义
双活包括两个组件:
- 带自动切换功能的 SessionPool 客户端:启动客户端时配置两台机器地址,默认向一个实例发送请求,如果出现连接异常,则自动切换到另一台实例中。
- 在 IoTDB 服务端打开操作级同步后:
- 已经写入的数据不会被同步,如果想同步,需要手动拷贝 TsFile 加载到备份 IoTDB 中。
- 新的数据和元数据增删改请求将不止在本地执行,还会转发至备份 IoTDB 中。
- 对于同一客户端发送的不同种类请求间的顺序保证:
- DDL 与 DDL 之间严格有序
- 同时发送 DML 与 DDL 时,优先执行 DDL
- 同时发送的 DML 不保证顺序
- 转发失败的请求会持久化到本地磁盘,总量上限可配置,超过上限时不再记录。
SessionPool 支持接口:
/* DDL */
public void setStorageGroup();
public void deleteStorageGroup();
public void deleteStorageGroups();
public void createTimeseries();
public void createMultiTimeseries();
/* DML */
public void insertTablet();
public void insertAlignedTablet();
public void insertTablets();
public void insertAlignedTablets();
public void insertRecords();
public void insertAlignedRecords();
public void insertRecordsOfOneDevice();
public void insertOneDeviceRecords();
public void insertStringRecordsOfOneDevice();
public void insertAlignedRecordsOfOneDevice();
public void insertAlignedStringRecordsOfOneDevice();
public void insertRecord();
public void insertAlignedRecord();
public void deleteTimeseries();
public void deleteData();
/* SQL */
public void executeNonQueryStatement();用户手册
当前双活功能推荐设置 auto_create_schema=false
配置带自动切换功能的 SessionPool 客户端
public class SessionPoolExample {
public void main(String[] args) {
// 配置两个服务端的 ip:port 参数
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
nodeUrls.add("127.0.0.1:6668");
// 配置带自动切换功能的 SessionPool
SessionPool sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build;
}
}服务端配置
在配置文件 iotdb-engine.properties 中增加以下参数
必填参数
设置必填参数后,即可在服务端启动双活功能
####################
### Operation Sync Configuration
####################
# Is Operation Sync enable
# Datatype: boolean
enable_operation_sync=true
# The destination IoTDB ip
# Datatype: String
secondary_address=127.0.0.1
# The destination IoTDB port
# Datatype: int
secondary_port=6668
# The destination IoTDB username
# Datatype: String
secondary_user=root
# The destination IoTDB password
# Datatype: String
secondary_password=root
# OperationSyncLog dir
# If this property is unset, OperationSync module will save the OperationSyncLogs # in the default relative path directory under the IoTDB folder
# i.e., %IOTDB_HOME%/data/operationsync.
# If it is absolute, OperationSync module will save the data in exact location it # points to.
# If it is relative, OperationSync module will save the data in the relative path # directory it indicates under the IoTDB folder.
# For windows platform
# If its prefix is a drive specifier followed by "\\", or if its prefix is
# "\\\\", then the path is absolute. Otherwise, it is relative.
# operation_sync_log_dir=data\\operationsync
# For Linux platform
# If its prefix is "/", then the path is absolute. Otherwise, it is relative.
# operation_sync_log_dir=data/operationsync选填参数
可以对以下选填参数进行调优
####################
### Operation Sync Configuration
####################
# The transmitting concurrency size of OperationSync SessionPool
# This parameter should better not exceed the sum of concurrent OperationSyncTask # or OperationSyncConsumer and concurrent OperationSyncProtector
# Datatype: int
# operation_sync_session_concurrency_size = 8
# The validity of each OperationSyncLog
# Datatype: int
# operation_sync_log_file_validity=30
# The maximum id of OperationSyncLog
# Datatype: int
# operation_sync_log_file_num = 32767
# The max size of all the OperationSyncLog. Default is 100GB
# Datatype: long
# operation_sync_max_log_size = 107374182400
# OperationSyncProducer cache size
# Datatype: int
# operation_sync_producer_cache_size=1024
# OperationSyncConsumer concurrency size
# Datatype: int
# operation_sync_consumer_concurrency_size=4部署示例
- 进入解压后的conf目录,编辑iotdb-engine.properties,修改以下配置项
# local db ip address
rpc_address=127.0.0.1
# local db port
rpc_port=6668
enable_operation_sync=true
# second db ip address
secondary_address=127.0.0.1
# second db port
secondary_port=6667
# second db username
secondary_user=root
# second db password
secondary_password=root- 修改完成之后,分别重启TimechoDB,双活配置即开启,可在一台TimechoDB实例上写入一条数据,验证另一台TimechoDB实例是否也有此数据,如果有,说明双活配置成功