Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOTDB-1140 optimize regular data encoding #2621

Merged
merged 7 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/UserGuide/Concept/Encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Usage restrictions: When using GORILLA to encode INT32 data, you need to ensure

* REGULAR

Regular data encoding is more suitable for encoding regular sequence increasing data (e.g. the timeseries with the same time elapsed between each data point), in which case it's better than TS_2DIFF.
Regular data encoding is more suitable for time encoding regular sequence increasing data (e.g. the timeseries with the same time elapsed between each data point), in which case it's better than TS_2DIFF.

Regular data encoding method is not suitable for the data with fluctuations (irregular data), and TS_2DIFF is recommended to deal with it.

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/UserGuide/Concept/Encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ GORILLA编码是一种无损编码,它比较适合编码前后值比较接近

* 定频数据编码 (REGULAR)

定频数据编码,仅适用于整形(INT32)和长整型(INT64)的定频数据,且允许数据中有一些点缺失,使用此方法编码定频数据优于二阶差分编码(TS_2DIFF)。
定频数据编码,仅适用于整形(INT32)和长整型(INT64)的时间列定频数据,且允许数据中有一些点缺失,使用此方法编码定频数据优于二阶差分编码(TS_2DIFF)。

定频数据编码无法用于非定频数据,建议使用二阶差分编码(TS_2DIFF)进行处理。

Expand Down
4 changes: 2 additions & 2 deletions server/src/assembly/resources/conf/iotdb-engine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ max_string_length=128
float_precision=2

# Encoder configuration
# Encoder of time series, supports TS_2DIFF, PLAIN and RLE(run-length encoding) and default value is TS_2DIFF
# Encoder of time series, supports TS_2DIFF, PLAIN and RLE(run-length encoding), REGULAR and default value is TS_2DIFF
time_encoder=TS_2DIFF

# Encoder of value series. default value is PLAIN.
# For int, long data type, also supports TS_2DIFF and RLE(run-length encoding), REGULAR and GORILLA.
# For int, long data type, also supports TS_2DIFF and RLE(run-length encoding) and GORILLA.
# For float, double data type, also supports TS_2DIFF, RLE(run-length encoding) and GORILLA.
# For text data type, only supports PLAIN.
value_encoder=PLAIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public class IoTDBConfigCheck {
private static final String VIRTUAL_STORAGE_GROUP_NUM = "virtual_storage_group_num";
private static String virtualStorageGroupNum = String.valueOf(config.getVirtualStorageGroupNum());

private static final String TIME_ENCODER_KEY = "time_encoder";
private static String timeEncoderValue = String
.valueOf(TSFileDescriptor.getInstance().getConfig().getTimeEncoder());

private static final String IOTDB_VERSION_STRING = "iotdb_version";

public static IoTDBConfigCheck getInstance() {
Expand Down Expand Up @@ -144,6 +148,7 @@ private IoTDBConfigCheck() {
systemProperties.put(TAG_ATTRIBUTE_SIZE_STRING, tagAttributeTotalSize);
systemProperties.put(MAX_DEGREE_OF_INDEX_STRING, maxDegreeOfIndexNode);
systemProperties.put(VIRTUAL_STORAGE_GROUP_NUM, virtualStorageGroupNum);
systemProperties.put(TIME_ENCODER_KEY, timeEncoderValue);
}


Expand Down Expand Up @@ -316,6 +321,10 @@ private void checkProperties() throws IOException {
if (!(properties.getProperty(VIRTUAL_STORAGE_GROUP_NUM).equals(virtualStorageGroupNum))) {
printErrorLogAndExit(VIRTUAL_STORAGE_GROUP_NUM);
}

if (!(properties.getProperty(TIME_ENCODER_KEY).equals(timeEncoderValue))) {
printErrorLogAndExit(TIME_ENCODER_KEY);
}
}

private void printErrorLogAndExit(String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private SchemaUtils() {
intSet.add(TSEncoding.PLAIN);
intSet.add(TSEncoding.RLE);
intSet.add(TSEncoding.TS_2DIFF);
intSet.add(TSEncoding.REGULAR);
intSet.add(TSEncoding.GORILLA);
schemaChecker.put(TSDataType.INT32, intSet);
schemaChecker.put(TSDataType.INT64, intSet);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* 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.
*/
package org.apache.iotdb.db.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.iotdb.db.conf.IoTDBConfigCheck;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
import java.security.AccessControlException;
import java.security.Permission;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


public class IoTDBCheckConfigIT {
private File propertiesFile = SystemFileFactory.INSTANCE
.getFile(IoTDBDescriptor.getInstance().getConfig().getSchemaDir()
+ File.separator + "system.properties");

private TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig();

private Map<String, String> systemProperties = new HashMap<>();

private Properties properties = new Properties();

private PrintStream console = null;
private ByteArrayOutputStream bytes = null;

@Before
public void setUp() throws Exception {
EnvironmentUtils.closeStatMonitor();
EnvironmentUtils.envSetUp();

final SecurityManager securityManager = new SecurityManager() {
public void checkPermission(Permission permission) {
if (permission.getName().startsWith("exitVM")) {
throw new AccessControlException("Wrong system config");
}
}
};
System.setSecurityManager(securityManager);
bytes = new ByteArrayOutputStream();
console = System.out;
System.setOut(new PrintStream(bytes));

systemProperties.put("partition_interval", "604800");
systemProperties.put("timestamp_precision", "ms");
systemProperties.put("tsfile_storage_fs", "LOCAL");
systemProperties.put("enable_partition", "false");
systemProperties.put("max_degree_of_index_node", "1024");
systemProperties.put("tag_attribute_total_size", "700");
systemProperties.put("iotdb_version", "0.11.2");
systemProperties.put("virtual_storage_group_num", "1");

}

@After
public void tearDown() throws Exception {
EnvironmentUtils.cleanEnv();
systemProperties.clear();
properties.clear();
}

@Test
public void testSaveTimeEncoderToSystemProperties() throws Exception {
try {
IoTDBConfigCheck.getInstance().checkConfig();
} finally {
System.setSecurityManager(null);
}

// read properties from system.properties
try (FileInputStream inputStream = new FileInputStream(propertiesFile);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, TSFileConfig.STRING_CHARSET)) {
properties.load(inputStreamReader);
}
String timeEncoder = (String) properties.get("time_encoder");
assertTrue(!timeEncoder.isEmpty());
}

@Test
public void testAlterTimeEncoderAfterStartService() throws Exception {
EnvironmentUtils.shutdownDaemon();
EnvironmentUtils.stopDaemon();
IoTDB.metaManager.clear();
systemProperties.put("time_encoder", "REGULAR");
writeSystemFile();
EnvironmentUtils.reactiveDaemon();
try {
IoTDBConfigCheck.getInstance().checkConfig();
} catch (Throwable t) {
assertEquals("Wrong system config", t.getMessage());
} finally {
System.setSecurityManager(null);
}
assertTrue(bytes.toString().contains("Wrong time_encoder, please set as: REGULAR"));
}

@Test
public void testSameTimeEncoderAfterStartService() throws Exception {
EnvironmentUtils.shutdownDaemon();
EnvironmentUtils.stopDaemon();
IoTDB.metaManager.clear();
systemProperties.put("time_encoder", "TS_2DIFF");
writeSystemFile();
EnvironmentUtils.reactiveDaemon();
try {
IoTDBConfigCheck.getInstance().checkConfig();
} catch (Throwable t) {
assertTrue(false);
} finally {
System.setSecurityManager(null);
}
}

private void writeSystemFile() throws IOException {
// write properties to system.properties
try (FileOutputStream outputStream = new FileOutputStream(propertiesFile)) {
systemProperties.forEach((k, v) -> properties.setProperty(k, v));
properties.store(outputStream, "System properties:");
}
}
}
Loading