-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
102 changed files
with
2,291 additions
and
821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
docs/Documentation-CHN/SystemDesign/4-StorageEngine/5-DataPartition.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# 数据分区 | ||
|
||
时间序列数据在存储组和时间范围两个层级上进行分区 | ||
|
||
## 存储组 | ||
|
||
存储组由用户显示指定,使用语句"SET STORAGE GROUP TO"来指定存储组,每一个存储组有一个对应的 StorageGroupProcessor | ||
|
||
其拥有的主要字段为: | ||
|
||
* 一个读写锁: insertLock | ||
|
||
* 每个时间分区所对应的未关闭的顺序文件处理器: workSequenceTsFileProcessors | ||
|
||
* 每个时间分区所对应的未关闭的乱序文件处理器: workUnsequenceTsFileProcessors | ||
|
||
* 该存储组的全部顺序文件列表(按照时间排序): sequenceFileTreeSet | ||
|
||
* 该存储组的全部乱序文件列表(无顺序): unSequenceFileList | ||
|
||
* 记录每一个设备最后写入时间的map,顺序数据刷盘时会使用该map记录的时间: latestTimeForEachDevice | ||
|
||
* 记录每一个设备最后刷盘时间的map,用来区分顺序和乱序数据: latestFlushedTimeForEachDevice | ||
|
||
* 每个时间分区所对应的版本生成器map,便于查询时确定不同chunk的优先级: timePartitionIdVersionControllerMap | ||
|
||
|
||
### 相关代码 | ||
|
||
* src/main/java/org/apache/iotdb/db/engine/StorageEngine.java | ||
|
||
|
||
## 时间范围 | ||
|
||
同一个存储组中的数据按照用户指定的时间范围进行分区,相关参数为partition_interval,默认为周,也就是不同周的数据会放在不同的分区中 | ||
|
||
### 实现逻辑 | ||
|
||
StorageGroupProcessor 对插入的数据进行分区计算,找到指定的 TsFileProcessor,而每一个 TsFileProcessor 对应的 TsFile 会被放置在不同的分区文件夹内 | ||
|
||
### 文件结构 | ||
|
||
分区后的文件结构如下: | ||
|
||
data | ||
|
||
-- sequence | ||
|
||
---- [存储组名1] | ||
|
||
------ [时间分区ID1] | ||
|
||
-------- xxxx.tsfile | ||
|
||
-------- xxxx.resource | ||
|
||
------ [时间分区ID2] | ||
|
||
---- [存储组名2] | ||
|
||
-- unsequence | ||
|
||
### 相关代码 | ||
|
||
* src/main/java/org/apache/iotdb/db/engine/storagegroup.StoragetGroupProcessor.java 中的 getOrCreateTsFileProcessorIntern 方法 |
96 changes: 96 additions & 0 deletions
96
docs/Documentation-CHN/SystemDesign/4-StorageEngine/6-DataManipulation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# 数据增删改 | ||
|
||
下面介绍四种常用数据操控操作,分别是插入,更新,删除和TTL设置 | ||
|
||
## 数据插入 | ||
|
||
### 单行数据(一个设备一个时间戳多个值)写入 | ||
|
||
* 对应的接口 | ||
* JDBC 的 execute 和 executeBatch 接口 | ||
* Session 的 insert 和 insertInBatch | ||
|
||
* 总入口: public void insert(InsertPlan insertPlan) StorageEngine.java | ||
* 找到对应的 StorageGroupProcessor | ||
* 根据写入数据的时间以及当前设备落盘的最后时间戳,找到对应的 TsFileProcessor | ||
* 记录写前日志 | ||
* 写入 TsFileProcessor 对应的 memtable 中 | ||
* 如果是乱序文件,则更新tsfileResource中的endTimeMap | ||
* 如果tsfile中没有该设备的信息,则更新tsfileResource中的startTimeMap | ||
* 根据 memtable 大小,来判断是否触发异步持久化 memtable 操作 | ||
* 如果是顺序文件且执行了刷盘动作,则更新tsfileResource中的endTimeMap | ||
* 根据当前磁盘 TsFile 的大小,判断是否触发文件关闭操作 | ||
|
||
### 批量数据(一个设备多个时间戳多个值)写入 | ||
|
||
* 对应的接口 | ||
* Session 的 insertBatch | ||
|
||
* 总入口: public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) StorageEngine.java | ||
* 找到对应的 StorageGroupProcessor | ||
* 根据这批数据的时间以及当前设备落盘的最后时间戳,将这批数据分成小批,分别对应到一个 TsFileProcessor 中 | ||
* 记录写前日志 | ||
* 分别将每小批写入 TsFileProcessor 对应的 memtable 中 | ||
* 如果是乱序文件,则更新tsfileResource中的endTimeMap | ||
* 如果tsfile中没有该设备的信息,则更新tsfileResource中的startTimeMap | ||
* 根据 memtable 大小,来判断是否触发异步持久化 memtable 操作 | ||
* 如果是顺序文件且执行了刷盘动作,则更新tsfileResource中的endTimeMap | ||
* 根据当前磁盘 TsFile 的大小,判断是否触发文件关闭操作 | ||
|
||
|
||
## 数据更新 | ||
|
||
目前不支持数据的原地更新操作,即update语句,但用户可以直接插入新的数据,在同一个时间点上的同一个时间序列以最新插入的数据为准 | ||
旧数据会通过合并来自动删除,参见: | ||
|
||
* [文件合并机制](/#/SystemDesign/progress/chap4/sec4) | ||
|
||
## 数据删除 | ||
|
||
* 对应的接口 | ||
* JDBC 的 execute 接口,使用delete SQL语句 | ||
|
||
* 总入口: public void delete(String deviceId, String measurementId, long timestamp) StorageEngine.java | ||
* 找到对应的 StorageGroupProcessor | ||
* 找到受影响的所有TsfileProcessor | ||
* 写写前日志 | ||
* 找到受影响的所有TsfileResource | ||
* 在mod文件中记录删除的时间点 | ||
* 如果文件没有关闭(存在对应的TsfileProcessor),则删除内存中的数据 | ||
|
||
|
||
## 数据TTL设置 | ||
|
||
* 对应的接口 | ||
* JDBC 的 execute 接口,使用SET TTL语句 | ||
|
||
* 总入口: public void setTTL(String storageGroup, long dataTTL) StorageEngine.java | ||
* 找到对应的 StorageGroupProcessor | ||
* 在 StorageGroupProcessor 中设置新的data ttl | ||
* 对所有TsfileResource进行TTL检查 | ||
* 如果某个文件在当前TTL下失效,则删除文件 | ||
|
||
同时,我们在 StorageEngine 中启动了一个定时检查文件TTL的线程,详见 | ||
|
||
* src/main/java/org/apache/iotdb/db/engine/StorageEngine.java 中的 start 方法 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.