diff --git a/Readme.md b/Readme.md
index 582f4eab6e6..30f6a9a9ac7 100644
--- a/Readme.md
+++ b/Readme.md
@@ -22,8 +22,8 @@ To use IoTDB, you need to have:
1. Java >= 1.8
2. Maven >= 3.0 (If you want to compile and install IoTDB from source code)
-3. TsFile >= 0.6.0 (TsFile Github page: [https://github.com/thulab/tsfile](https://github.com/thulab/tsfile))
-4. IoTDB-JDBC >= 0.6.0 (IoTDB-JDBC Github page: [https://github.com/thulab/iotdb-jdbc](https://github.com/thulab/iotdb-jdbc))
+3. TsFile >= 0.7.0 (TsFile Github page: [https://github.com/thulab/tsfile](https://github.com/thulab/tsfile))
+4. IoTDB-JDBC >= 0.7.0 (IoTDB-JDBC Github page: [https://github.com/thulab/iotdb-jdbc](https://github.com/thulab/iotdb-jdbc))
TODO: TsFile and IoTDB-JDBC dependencies will be removed after Jialin Qiao re-structured the Project.
@@ -125,7 +125,7 @@ The command line client is interactive so if everything is ready you should see
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
-|_____|'.__.' |_____| |______.'|_______/ version 0.6.0
+|_____|'.__.' |_____| |______.'|_______/ version 0.7.0
IoTDB> login successfully
diff --git a/iotdb/conf/error_info_cn.properties b/iotdb/conf/error_info_cn.properties
new file mode 100644
index 00000000000..c0d6095986e
--- /dev/null
+++ b/iotdb/conf/error_info_cn.properties
@@ -0,0 +1,9 @@
+20000=未知错误
+20001=语句中无变量
+20002=无效的变量
+20003=无法连接到服务器:%s (%s)
+20061=验证失败:%S
+20062=不安全的函数调用:%s
+20064=M客户端内存溢出
+20130=语句未就绪
+20220=连接失败
\ No newline at end of file
diff --git a/iotdb/conf/error_info_en.properties b/iotdb/conf/error_info_en.properties
new file mode 100644
index 00000000000..c2f52c4d792
--- /dev/null
+++ b/iotdb/conf/error_info_en.properties
@@ -0,0 +1,9 @@
+20000=Unknown error
+20001=No parameters exist in the statement
+20002=Invalid parameter number
+20003=Can't connect to server on %s(%s)
+20061=Authentication failed: %s
+20062=Insecure API function call: %s
+20064=Client ran out of memory
+20130=Statement not prepared
+20220=Fail to connect.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 55c194ce621..2eb47727b68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
cn.edu.tsinghuaIoTDB
- 0.6.0
+ 0.8.0-SNAPSHOTjarIoTDB
@@ -23,7 +23,7 @@
cn.edu.tsinghuaiotdb-jdbc
- 0.6.0
+ 0.8.0-SNAPSHOTcn.edu.fudan.dsm
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsFileDBConstant.java b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsFileDBConstant.java
index 904dd7364ec..0d509e3c0e5 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsFileDBConstant.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsFileDBConstant.java
@@ -4,7 +4,7 @@ public class TsFileDBConstant {
public static final String ENV_FILE_NAME = "iotdb-env";
public static final String IOTDB_CONF = "IOTDB_CONF";
public static final String GLOBAL_DB_NAME = "IoTDB";
- public static final String VERSION = "0.6.0";
+ public static final String VERSION = "0.7.0";
public static final String REMOTE_JMX_PORT_NAME = "com.sun.management.jmxremote.port";
public static final String TSFILEDB_LOCAL_JMX_PORT_NAME = "iotdb.jmx.local.port";
public static final String TSFILEDB_REMOTE_JMX_PORT_NAME = "iotdb.jmx.remote.port";
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBConfig.java b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBConfig.java
index edb471551e2..41ff2fecdc8 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBConfig.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBConfig.java
@@ -14,6 +14,7 @@ public class TsfileDBConfig {
public static final String default_tsfile_dir = "settled";
public static final String mult_dir_strategy_prefix = "cn.edu.tsinghua.iotdb.conf.directories.strategy.";
public static final String default_mult_dir_strategy = "MaxDiskUsableSpaceFirstStrategy";
+
/**
* Port which JDBC server listens to
*/
@@ -246,6 +247,11 @@ public class TsfileDBConfig {
*/
public int postbackServerPort = 5555;
+ /*
+ * Set the language version when loading file including error information, default value is "EN"
+ * */
+ public String languageVersion = "EN";
+
/**
* Choose a postBack strategy of merging historical data: 1. It's more likely to
* update historical data, choose "true". 2. It's more likely not to update
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBDescriptor.java b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBDescriptor.java
index aa55484bd9d..d9fb69d5aa2 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBDescriptor.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBDescriptor.java
@@ -149,6 +149,8 @@ public class TsfileDBDescriptor {
int maxLogEntrySize = Integer.parseInt(properties.getProperty("max_log_entry_size", conf.maxLogEntrySize + "").trim());
conf.maxLogEntrySize = maxLogEntrySize > 0 ? maxLogEntrySize : conf.maxLogEntrySize;
+ conf.languageVersion = properties.getProperty("language_version", conf.languageVersion).trim();
+
String tmpTimeZone = properties.getProperty("time_zone", conf.timeZone.getID());
try {
conf.timeZone = DateTimeZone.forID(tmpTimeZone.trim());
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinDirOccupiedSpaceFirstStrategy.java b/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinDirOccupiedSpaceFirstStrategy.java
new file mode 100644
index 00000000000..883374e301f
--- /dev/null
+++ b/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinDirOccupiedSpaceFirstStrategy.java
@@ -0,0 +1,62 @@
+package cn.edu.tsinghua.iotdb.conf.directories.strategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.logging.Logger;
+
+public class MinDirOccupiedSpaceFirstStrategy extends DirectoryStrategy {
+
+ // directory space is measured by MB
+ private final long DATA_SIZE_SHIFT = 1024 * 1024;
+
+ @Override
+ public int nextFolderIndex() {
+ return getMinOccupiedSpaceFolder();
+ }
+
+ private int getMinOccupiedSpaceFolder() {
+ List candidates = new ArrayList<>();
+ long min = 0;
+
+ candidates.add(0);
+ min = getOccupiedSpace(folders.get(0));
+ for(int i = 1;i < folders.size();i++){
+ long current = getOccupiedSpace(folders.get(i));
+ if(min > current){
+ candidates.clear();
+ candidates.add(i);
+ min = current;
+ }
+ else if(min == current){
+ candidates.add(i);
+ }
+ }
+
+ Random random = new Random(System.currentTimeMillis());
+ int index = random.nextInt(candidates.size());
+
+ return candidates.get(index);
+ }
+
+ private long getOccupiedSpace(String path) {
+ Path folder = Paths.get(path);
+ long size = 0;
+ try {
+ size = Files.walk(folder)
+ .filter(p -> p.toFile().isFile())
+ .mapToLong(p -> p.toFile().length())
+ .sum();
+ } catch (IOException e) {
+ LOGGER.error("Cannot calculate occupied space for path {}.", path);
+ }
+
+ return size / DATA_SIZE_SHIFT;
+ }
+}
+
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinFolderOccupiedSpaceFirstStrategy.java b/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinFolderOccupiedSpaceFirstStrategy.java
index 3969844b63c..18c4dbcdf33 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinFolderOccupiedSpaceFirstStrategy.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/conf/directories/strategy/MinFolderOccupiedSpaceFirstStrategy.java
@@ -46,7 +46,7 @@ public class MinFolderOccupiedSpaceFirstStrategy extends DirectoryStrategy {
private long getOccupiedSpace(String path) {
Path folder = Paths.get(path);
- long size = 0;
+ long size = Long.MAX_VALUE;
try {
size = Files.walk(folder)
.filter(p -> p.toFile().isFile())
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwriteV2/BufferIO.java b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferIO.java
similarity index 95%
rename from src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwriteV2/BufferIO.java
rename to src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferIO.java
index 476e52369ca..e4a38eaf8dc 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwriteV2/BufferIO.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferIO.java
@@ -1,4 +1,4 @@
-package cn.edu.tsinghua.iotdb.engine.bufferwriteV2;
+package cn.edu.tsinghua.iotdb.engine.bufferwrite;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIOWriter.java b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIOWriter.java
deleted file mode 100644
index 602885701b3..00000000000
--- a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIOWriter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package cn.edu.tsinghua.iotdb.engine.bufferwrite;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import cn.edu.tsinghua.tsfile.common.utils.ITsRandomAccessFileWriter;
-import cn.edu.tsinghua.tsfile.file.metadata.RowGroupMetaData;
-import cn.edu.tsinghua.tsfile.file.metadata.TimeSeriesChunkMetaData;
-import cn.edu.tsinghua.tsfile.file.metadata.enums.TSDataType;
-import cn.edu.tsinghua.tsfile.timeseries.write.io.TsFileIOWriter;
-
-/**
- * @author kangrong
- *
- */
-public class BufferWriteIOWriter extends TsFileIOWriter {
-
- /*
- * The backup list is used to store the rowgroup's metadata whose data has
- * been flushed into file.
- */
- private final List backUpList = new ArrayList();
- private int lastRowGroupIndex = 0;
-
- public BufferWriteIOWriter(ITsRandomAccessFileWriter output) throws IOException {
- super(output);
- }
-
- /**
- * This is just used to restore a tsfile from the middle of the file
- *
- * @param schema
- * @param output
- * @param rowGroups
- * @throws IOException
- */
- public BufferWriteIOWriter(ITsRandomAccessFileWriter output, long offset, List rowGroups)
- throws IOException {
- super(output, offset, rowGroups);
- addrowGroupsTobackupList(rowGroups);
-
- }
-
- private void addrowGroupsTobackupList(List rowGroups) {
- for (RowGroupMetaData rowGroupMetaData : rowGroups) {
- backUpList.add(rowGroupMetaData);
- }
- lastRowGroupIndex = rowGroups.size();
- }
-
- /**
- * Note that,the method is not thread safe.
- */
- public void addNewRowGroupMetaDataToBackUp() {
- for (int i = lastRowGroupIndex; i < rowGroupMetaDatas.size(); i++) {
- backUpList.add(rowGroupMetaDatas.get(i));
- }
- lastRowGroupIndex = rowGroupMetaDatas.size();
- }
-
- /**
- * Note that, the method is not thread safe. You mustn't do any
- * change on the return.
- *
- * @return
- */
- public List getCurrentRowGroupMetaList(String deltaObjectId) {
- List ret = new ArrayList<>();
- for (RowGroupMetaData rowGroupMetaData : backUpList) {
- if (rowGroupMetaData.getDeltaObjectID().equals(deltaObjectId)) {
- ret.add(rowGroupMetaData);
- }
- }
- return ret;
- }
-
- public List getCurrentTimeSeriesMetadataList(String deltaObjectId, String measurementId,
- TSDataType dataType) {
- List chunkMetaDatas = new ArrayList<>();
- for (RowGroupMetaData rowGroupMetaData : backUpList) {
- if (rowGroupMetaData.getDeltaObjectID().equals(deltaObjectId)) {
- for (TimeSeriesChunkMetaData chunkMetaData : rowGroupMetaData.getTimeSeriesChunkMetaDataList()) {
- // filter data-type and measurementId
- if (chunkMetaData.getProperties().getMeasurementUID().equals(measurementId)
- && chunkMetaData.getVInTimeSeriesChunkMetaData().getDataType().equals(dataType)) {
- chunkMetaDatas.add(chunkMetaData);
- }
- }
- }
- }
- return chunkMetaDatas;
- }
-}
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIndex.java b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIndex.java
deleted file mode 100644
index 9469fe231ea..00000000000
--- a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteIndex.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package cn.edu.tsinghua.iotdb.engine.bufferwrite;
-
-import cn.edu.tsinghua.tsfile.timeseries.read.query.DynamicOneColumnData;
-import cn.edu.tsinghua.tsfile.timeseries.write.record.TSRecord;
-
-/**
- * The function of this interface is to store and index TSRecord in memory
- * temporarily
- *
- * @author kangrong
- *
- */
-@Deprecated
-public interface BufferWriteIndex {
- /**
- * insert a tsRecord
- *
- * @param tsRecord
- */
- void insert(TSRecord tsRecord);
-
- /**
- * Get the DynamicOneColumnData from the buffer index
- *
- * @param deltaObjectId
- * @param measurementId
- * @return
- */
- public DynamicOneColumnData query(String deltaObjectId, String measurementId);
-
- /**
- * clear all data written in the bufferindex structure which will be used
- * for next stage
- */
- void clear();
-}
diff --git a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteProcessor.java b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteProcessor.java
index df29200198e..0e31de6b96d 100644
--- a/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteProcessor.java
+++ b/src/main/java/cn/edu/tsinghua/iotdb/engine/bufferwrite/BufferWriteProcessor.java
@@ -1,14 +1,7 @@
package cn.edu.tsinghua.iotdb.engine.bufferwrite;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
@@ -29,7 +22,6 @@ import cn.edu.tsinghua.iotdb.engine.Processor;
import cn.edu.tsinghua.iotdb.engine.memcontrol.BasicMemController;
import cn.edu.tsinghua.iotdb.engine.memtable.IMemTable;
import cn.edu.tsinghua.iotdb.engine.memtable.MemSeriesLazyMerger;
-import cn.edu.tsinghua.iotdb.engine.memtable.MemTableFlushUtil;
import cn.edu.tsinghua.iotdb.engine.memtable.PrimitiveMemTable;
import cn.edu.tsinghua.iotdb.engine.pool.FlushManager;
import cn.edu.tsinghua.iotdb.engine.querycontext.RawSeriesChunk;
@@ -37,75 +29,50 @@ import cn.edu.tsinghua.iotdb.engine.querycontext.RawSeriesChunkLazyLoadImpl;
import cn.edu.tsinghua.iotdb.engine.utils.FlushStatus;
import cn.edu.tsinghua.iotdb.exception.BufferWriteProcessorException;
import cn.edu.tsinghua.iotdb.utils.MemUtils;
-import cn.edu.tsinghua.tsfile.common.conf.TSFileConfig;
import cn.edu.tsinghua.tsfile.common.conf.TSFileDescriptor;
-import cn.edu.tsinghua.tsfile.common.utils.BytesUtils;
-import cn.edu.tsinghua.tsfile.common.utils.ITsRandomAccessFileWriter;
import cn.edu.tsinghua.tsfile.common.utils.Pair;
-import cn.edu.tsinghua.tsfile.common.utils.TsRandomAccessFileWriter;
-import cn.edu.tsinghua.tsfile.file.metadata.RowGroupMetaData;
import cn.edu.tsinghua.tsfile.file.metadata.TimeSeriesChunkMetaData;
-import cn.edu.tsinghua.tsfile.file.metadata.TsRowGroupBlockMetaData;
import cn.edu.tsinghua.tsfile.file.metadata.enums.TSDataType;
-import cn.edu.tsinghua.tsfile.file.utils.ReadWriteThriftFormatUtils;
-import cn.edu.tsinghua.tsfile.format.RowGroupBlockMetaData;
import cn.edu.tsinghua.tsfile.timeseries.write.record.DataPoint;
import cn.edu.tsinghua.tsfile.timeseries.write.record.TSRecord;
import cn.edu.tsinghua.tsfile.timeseries.write.schema.FileSchema;
-/**
- * @author liukun
- */
public class BufferWriteProcessor extends Processor {
-
private static final Logger LOGGER = LoggerFactory.getLogger(BufferWriteProcessor.class);
- private static final TsfileDBConfig TsFileDBConf = TsfileDBDescriptor.getInstance().getConfig();
- private static final TSFileConfig TsFileConf = TSFileDescriptor.getInstance().getConfig();
- private static final int TS_METADATA_BYTE_SIZE = 4;
- private static final int TSFILE_POSITION_BYTE_SIZE = 8;
+
+ private FileSchema fileSchema;
+ private BufferWriteResource bufferWriteResource;
private volatile FlushStatus flushStatus = new FlushStatus();
+ private volatile boolean isFlush;
private ReentrantLock flushQueryLock = new ReentrantLock();
+ private AtomicLong memSize = new AtomicLong();
+ private long memThreshold = TSFileDescriptor.getInstance().getConfig().groupSizeInByte;
private IMemTable workMemTable;
private IMemTable flushMemTable;
- private FileSchema fileSchema;
- private BufferWriteIOWriter bufferIOWriter;
- private int lastRowgroupSize = 0;
-
- // this just the bufferwrite file name
- private String baseDir;
- private String fileName;
- private static final String restoreFile = ".restore";
- // this is the bufferwrite file absolute path
- private String bufferwriteRestoreFilePath;
- private String bufferwriteOutputFilePath;
- private String bufferwriterelativePath;
- private File bufferwriteOutputFile;
-
- private boolean isNewProcessor = false;
-
private Action bufferwriteFlushAction = null;
private Action bufferwriteCloseAction = null;
private Action filenodeFlushAction = null;
- private long memThreshold = TsFileConf.groupSizeInByte;
private long lastFlushTime = -1;
private long valueCount = 0;
- private volatile boolean isFlush;
- private AtomicLong memSize = new AtomicLong();
+
+ private String baseDir;
+ private String fileName;
+ private String insertFilePath;
+ private String bufferwriterelativePath;
private WriteLogNode logNode;
public BufferWriteProcessor(String baseDir, String processorName, String fileName, Map parameters,
FileSchema fileSchema) throws BufferWriteProcessorException {
super(processorName);
-
- this.fileName = fileName;
- String restoreFileName = fileName + restoreFile;
-
+ this.fileSchema = fileSchema;
this.baseDir = baseDir;
+ this.fileName = fileName;
+
if (baseDir.length() > 0
&& baseDir.charAt(baseDir.length() - 1) != File.separatorChar) {
baseDir = baseDir + File.separatorChar;
@@ -116,50 +83,21 @@ public class BufferWriteProcessor extends Processor {
dataDir.mkdirs();
LOGGER.debug("The bufferwrite processor data dir doesn't exists, create new directory {}.", dataDirPath);
}
- bufferwriteOutputFile = new File(dataDir, fileName);
- File restoreFile = new File(dataDir, restoreFileName);
- bufferwriteRestoreFilePath = restoreFile.getPath();
- bufferwriteOutputFilePath = bufferwriteOutputFile.getPath();
+ this.insertFilePath = new File(dataDir, fileName).getPath();
bufferwriterelativePath = processorName + File.separatorChar + fileName;
- // get the fileschema
- this.fileSchema = fileSchema;
-
- if (bufferwriteOutputFile.exists() && restoreFile.exists()) {
- //
- // There is one damaged file, and the RESTORE_FILE_SUFFIX exist
- //
- LOGGER.info("Recorvery the bufferwrite processor {}.", processorName);
- bufferwriteRecovery();
-
- } else {
-
- ITsRandomAccessFileWriter outputWriter;
- try {
- outputWriter = new TsRandomAccessFileWriter(bufferwriteOutputFile);
- } catch (IOException e) {
- LOGGER.error("Construct the TSRandomAccessFileWriter error, the absolutePath is {}.",
- bufferwriteOutputFile.getPath(), e);
- throw new BufferWriteProcessorException(e);
- }
-
- try {
- bufferIOWriter = new BufferWriteIOWriter(outputWriter);
- } catch (IOException e) {
- LOGGER.error("Get the BufferWriteIOWriter error, the bufferwrite is {}.", processorName, e);
- throw new BufferWriteProcessorException(e);
- }
- isNewProcessor = true;
- // write restore file
- writeStoreToDisk();
+ try {
+ bufferWriteResource = new BufferWriteResource(processorName, insertFilePath);
+ } catch (IOException e) {
+ throw new BufferWriteProcessorException(e);
}
- // init action
- // the action from the corresponding filenode processor
+
+
bufferwriteFlushAction = (Action) parameters.get(FileNodeConstants.BUFFERWRITE_FLUSH_ACTION);
bufferwriteCloseAction = (Action) parameters.get(FileNodeConstants.BUFFERWRITE_CLOSE_ACTION);
filenodeFlushAction = (Action) parameters.get(FileNodeConstants.FILENODE_PROCESSOR_FLUSH_ACTION);
workMemTable = new PrimitiveMemTable();
- if (TsfileDBDescriptor.getInstance().getConfig().enableWal) {
+ if(TsfileDBDescriptor.getInstance().getConfig().enableWal) {
try {
logNode = MultiFileLogNodeManager.getInstance().getNode(
processorName + TsFileDBConstant.BUFFERWRITE_LOG_NODE_SUFFIX, getBufferwriteRestoreFilePath(),
@@ -170,256 +108,6 @@ public class BufferWriteProcessor extends Processor {
}
}
- /**
- *
- * Recovery the bufferwrite status.
- * The one part is the last intervalFile
- * The other part is all the intervalFile, and other file will be deleted
- *
- *
- * @throws BufferWriteProcessorException
- */
- private void bufferwriteRecovery() throws BufferWriteProcessorException {
-
- Pair> pair;
- try {
- pair = readStoreFromDisk();
- } catch (IOException e) {
- LOGGER.error("Failed to read bufferwrite {} restore file.", getProcessorName());
- throw new BufferWriteProcessorException(e);
- }
- ITsRandomAccessFileWriter output;
- long lastFlushPosition = pair.left;
- File lastBufferWriteFile = new File(bufferwriteOutputFilePath);
- if (lastBufferWriteFile.length() != lastFlushPosition) {
- LOGGER.warn(
- "The last bufferwrite file {} is damaged, the length of the last bufferwrite file is {}, the end of last successful flush is {}.",
- lastBufferWriteFile.getPath(), lastBufferWriteFile.length(), lastFlushPosition);
- try {
- FileChannel fileChannel = new FileOutputStream(bufferwriteOutputFile, true).getChannel();
- fileChannel.truncate(lastFlushPosition);
- fileChannel.close();
- //cutOffFile(lastFlushPosition);
- } catch (IOException e) {
- LOGGER.error(
- "Cut off damaged file error, the damaged file path is {}, the length is {}, the cut off length is {}.",
- bufferwriteOutputFilePath, lastBufferWriteFile.length(), lastFlushPosition, e);
- throw new BufferWriteProcessorException(e);
- }
- }
- try {
- // Notice: the offset is seek to end of the file by API of kr
- output = new TsRandomAccessFileWriter(lastBufferWriteFile);
- } catch (IOException e) {
- LOGGER.error("Can't construct the RandomAccessOutputStream, the outputPath is {}.",
- bufferwriteOutputFilePath);
- throw new BufferWriteProcessorException(e);
- }
- try {
- // Notice: the parameter of lastPosition is not used beacuse of the
- // API of kr
- bufferIOWriter = new BufferWriteIOWriter(output, lastFlushPosition, pair.right);
- } catch (IOException e) {
- LOGGER.error("Can't get the BufferWriteIOWriter while recoverying, the bufferwrite processor is {}.",
- getProcessorName(), e);
- throw new BufferWriteProcessorException(e);
- }
- isNewProcessor = false;
- }
-
- private void cutOffFile(long length) throws IOException {
-
- String tempPath = bufferwriteOutputFilePath + ".backup";
- File tempFile = new File(tempPath);
- File normalFile = new File(bufferwriteOutputFilePath);
-
- if (normalFile.exists() && normalFile.length() > 0) {
-
- if (tempFile.exists()) {
- tempFile.delete();
- }
- RandomAccessFile normalReader = null;
- RandomAccessFile tempWriter = null;
- try {
- normalReader = new RandomAccessFile(normalFile, "r");
- tempWriter = new RandomAccessFile(tempFile, "rw");
- } catch (FileNotFoundException e) {
- LOGGER.error(
- "Can't get the RandomAccessFile read and write, the normal path is {}, the temp path is {}.",
- bufferwriteOutputFilePath, tempPath);
- if (normalReader != null) {
- normalReader.close();
- }
- if (tempWriter != null) {
- tempWriter.close();
- }
- throw e;
- }
- long offset = 0;
- int step = 4 * 1024 * 1024;
- byte[] buff = new byte[step];
- while (length - offset >= step) {
- try {
- normalReader.readFully(buff);
- tempWriter.write(buff);
- } catch (IOException e) {
- LOGGER.error("normalReader read data failed or tempWriter write data error.");
- throw e;
- }
- offset = offset + step;
- }
- normalReader.readFully(buff, 0, (int) (length - offset));
- tempWriter.write(buff, 0, (int) (length - offset));
- normalReader.close();
- tempWriter.close();
- }
- normalFile.delete();
- tempFile.renameTo(normalFile);
- }
-
- /**
- * This is only used after flush one rowroup data successfully.
- *
- * @throws BufferWriteProcessorException
- */
- private void writeStoreToDisk() throws BufferWriteProcessorException {
-
- long lastPosition;
- try {
- lastPosition = bufferIOWriter.getPos();
- } catch (IOException e) {
- LOGGER.error("Can't get the bufferwrite io position, the buffewrite processor is {}", getProcessorName(),
- e);
- throw new BufferWriteProcessorException(e);
- }
- List rowGroupMetaDatas = bufferIOWriter.getRowGroups();
- List appendMetadata = new ArrayList<>();
- for (int i = lastRowgroupSize; i < rowGroupMetaDatas.size(); i++) {
- appendMetadata.add(rowGroupMetaDatas.get(i));
- }
- lastRowgroupSize = rowGroupMetaDatas.size();
- TsRowGroupBlockMetaData tsRowGroupBlockMetaData = new TsRowGroupBlockMetaData();
- tsRowGroupBlockMetaData.setRowGroups(appendMetadata);
-
- RandomAccessFile out = null;
- try {
- out = new RandomAccessFile(bufferwriteRestoreFilePath, "rw");
- } catch (FileNotFoundException e) {
- LOGGER.error("The restore file {} can't be created, the bufferwrite processor is {}",
- bufferwriteRestoreFilePath, getProcessorName(), e);
- throw new BufferWriteProcessorException(e);
- }
- try {
- if (out.length() > 0) {
- out.seek(out.length() - TSFILE_POSITION_BYTE_SIZE);
- }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ReadWriteThriftFormatUtils.writeRowGroupBlockMetadata(tsRowGroupBlockMetaData.convertToThrift(), baos);
- // write metadata size using int
- int metadataSize = baos.size();
- out.write(BytesUtils.intToBytes(metadataSize));
- // write metadata
- out.write(baos.toByteArray());
- // write tsfile position using byte[8] which is present one long
- // number
- byte[] lastPositionBytes = BytesUtils.longToBytes(lastPosition);
- out.write(lastPositionBytes);
- } catch (IOException e) {
- throw new BufferWriteProcessorException(e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- throw new BufferWriteProcessorException(e);
- }
- }
- }
- }
-
- /**
- * This is used to delete the file which is used to restore buffer write
- * processor. This is only used after closing the buffer write processor
- * successfully.
- */
- private void deleteRestoreFile() {
- File restoreFile = new File(bufferwriteRestoreFilePath);
- if (restoreFile.exists()) {
- restoreFile.delete();
- }
- }
-
- /**
- * The left of the pair is the last successful flush position. The right of
- * the pair is the rowGroupMetadata.
- *
- * @return - the left is the end position of the last rowgroup flushed, the
- * right is all the rowgroup meatdata flushed
- * @throws IOException
- */
- private Pair> readStoreFromDisk() throws IOException {
- byte[] lastPostionBytes = new byte[TSFILE_POSITION_BYTE_SIZE];
- List groupMetaDatas = new ArrayList<>();
- RandomAccessFile randomAccessFile = null;
- try {
- randomAccessFile = new RandomAccessFile(bufferwriteRestoreFilePath, "rw");
- long fileLength = randomAccessFile.length();
- // read tsfile position
- long point = randomAccessFile.getFilePointer();
- while (point + TSFILE_POSITION_BYTE_SIZE < fileLength) {
- byte[] metadataSizeBytes = new byte[TS_METADATA_BYTE_SIZE];
- randomAccessFile.read(metadataSizeBytes);
- int metadataSize = BytesUtils.bytesToInt(metadataSizeBytes);
- byte[] thriftBytes = new byte[metadataSize];
- randomAccessFile.read(thriftBytes);
- ByteArrayInputStream inputStream = new ByteArrayInputStream(thriftBytes);
- RowGroupBlockMetaData rowGroupBlockMetaData = ReadWriteThriftFormatUtils
- .readRowGroupBlockMetaData(inputStream);
- TsRowGroupBlockMetaData blockMeta = new TsRowGroupBlockMetaData();
- blockMeta.convertToTSF(rowGroupBlockMetaData);
- groupMetaDatas.addAll(blockMeta.getRowGroups());
- lastRowgroupSize = groupMetaDatas.size();
- point = randomAccessFile.getFilePointer();
- }
- // read the tsfile position information using byte[8] which is
- // present one long number.
- randomAccessFile.read(lastPostionBytes);
- } catch (FileNotFoundException e) {
- LOGGER.error("The restore file does not exist, the restore file path is {}.", bufferwriteRestoreFilePath,
- e);
- throw e;
- } catch (IOException e) {
- LOGGER.error("Read data from file error.", e);
- throw e;
- } finally {
- if (randomAccessFile != null) {
- randomAccessFile.close();
- }
- }
- long lastPostion = BytesUtils.bytesToLong(lastPostionBytes);
- Pair> result = new Pair>(lastPostion, groupMetaDatas);
- return result;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public String getBaseDir() { return baseDir; }
-
- public String getFileRelativePath() {
- return bufferwriterelativePath;
- }
-
- public boolean isNewProcessor() {
- return isNewProcessor;
- }
-
- public void setNewProcessor(boolean isNewProcessor) {
- this.isNewProcessor = isNewProcessor;
- }
-
/**
* write one data point to the bufferwrite
*
@@ -443,7 +131,6 @@ public class BufferWriteProcessor extends Processor {
public boolean write(TSRecord tsRecord) throws BufferWriteProcessorException {
long memUage = MemUtils.getRecordSize(tsRecord);
BasicMemController.UsageLevel level = BasicMemController.getInstance().reportUse(this, memUage);
-
for (DataPoint dataPoint : tsRecord.dataPointList) {
workMemTable.write(tsRecord.deltaObjectId, dataPoint.getMeasurementId(), dataPoint.getType(), tsRecord.time,
dataPoint.getValue().toString());
@@ -490,18 +177,6 @@ public class BufferWriteProcessor extends Processor {
}
}
- @Deprecated
- public Pair, List> queryBufferwriteData(String deltaObjectId, String measurementId) {
- flushQueryLock.lock();
- try {
- List