Skip to content

Commit

Permalink
resolve conflixts
Browse files Browse the repository at this point in the history
  • Loading branch information
JackieTien97 committed Feb 28, 2020
2 parents d8bcffc + d6ae1c3 commit cf31d9c
Show file tree
Hide file tree
Showing 102 changed files with 2,291 additions and 821 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ IoTDB provides three installation methods, you can refer to the following sugges

* Installation from source code. If you need to modify the code yourself, you can use this method.
* Installation from binary files. Download the binary files from the official website. This is the recommended method, in which you will get a binary released package which is out-of-the-box.(Comming Soon...)
* Using Docker:The path to the dockerfile is https://github.com/apache/incubator-iotdb/blob/master/docker/Dockerfile
* Using Docker:The path to the dockerfile is https://github.com/apache/incubator-iotdb/tree/master/docker/src/main


Here in the Quick Start, we give a brief introduction of using source code to install IoTDB. For further information, please refer to Chapter 4 of the User Guide.
Expand Down
33 changes: 17 additions & 16 deletions client-py/src/client_example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# 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
# 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
# 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.
# 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.
#

import sys, struct
Expand Down Expand Up @@ -164,14 +164,15 @@ def convertQueryDataSet(queryDataSet, dataTypeList):
transport.open()

# Authentication
clientProtocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1
clientProtocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2
resp = client.openSession(TSOpenSessionReq(client_protocol=clientProtocol,
username=username,
password=password))
if resp.serverProtocolVersion != clientProtocol:
print('Inconsistent protocol, server version: %d, client version: %d'
% (resp.serverProtocolVersion, clientProtocol))
exit()
if resp.serverProtocolVersion > clientProtocol:
exit()
sessionId = resp.sessionId

# This is necessary for resource control
Expand Down
8 changes: 4 additions & 4 deletions docs/Documentation-CHN/SystemDesign/1-TsFile/3-Write.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

TsFile 的写入流程如下图所示:

<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/19167280/73625238-efba2980-467e-11ea-927e-a7021f8153af.png">
< img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/19167280/73625238-efba2980-467e-11ea-927e-a7021f8153af.png">

其中,每个设备对应一个 ChunkGroupWriter,每个传感器对应一个 ChunkWriter。

Expand All @@ -41,11 +41,11 @@ TsFile 文件层的写入接口有两种

* TsFileWriter.write(TSRecord record)

写入一个设备一个时间戳多个测点。
写入一个设备一个时间戳多个测点。

* TsFileWriter.write(RowBatch rowBatch)

写入一个设备多个时间戳多个测点。
写入一个设备多个时间戳多个测点。

当调用 write 接口时,这个设备的数据会交给对应的 ChunkGroupWriter,其中的每个测点会交给对应的 ChunkWriter 进行写入。ChunkWriter 完成编码和打包(生成 Page)。

Expand All @@ -62,4 +62,4 @@ TsFile 文件层的写入接口有两种

* TsFileWriter.close()

根据内存中缓存的元数据,生成 TsFileMetadata 追加到文件尾部,最后关闭文件。
根据内存中缓存的元数据,生成 TsFileMetadata 追加到文件尾部,最后关闭文件。
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,9 @@
负责一个 TsFile 文件的数据写入和访问。


### 单行数据(一个设备一个时间戳多个值)写入

* 对应的接口
* JDBC 的 execute 和 executeBatch 接口
* Session 的 insert 和 insertInBatch

* 总入口: public void insert(InsertPlan insertPlan)
* 找到对应的 StorageGroupProsessor
* 根据写入数据的时间以及当前设备落盘的最后时间戳,找到对应的 TsFileProcessor
* 写入 TsFileProcessor 对应的 memtable 中
* 记录写前日志
* 根据 memtable 大小,来判断是否触发异步持久化 memtable 操作
* 根据当前磁盘 TsFile 的大小,判断是否触发文件关闭操作

### 批量数据(一个设备多个时间戳多个值)写入

* 对应的接口
* Session 的 insertBatch

* 总入口: public Integer[] insertBatch(BatchInsertPlan batchInsertPlan)
* 找到对应的 StorageGroupProsessor
* 根据这批数据的时间以及当前设备落盘的最后时间戳,将这批数据分成小批,分别对应到一个 TsFileProcessor 中
* 分别将每小批写入 TsFileProcessor 对应的 memtable 中
* 记录写前日志
* 根据 memtable 大小,来判断是否触发异步持久化 memtable 操作
* 根据当前磁盘 TsFile 的大小,判断是否触发文件关闭操作

## 数据写入
详见:
* [数据写入](/#/SystemDesign/progress/chap4/sec6)

## 数据访问

Expand Down
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 方法
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 方法
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ BatchData nextBatch() throws IOException;
#### 一般使用流程

```
while (batchReader. hasNextBatch()) {
while (batchReader.hasNextBatch()) {
BatchData batchData = batchReader.nextBatch();
// use batchData to do some work
Expand Down

0 comments on commit cf31d9c

Please sign in to comment.