Skip to content
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 cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>tsfile-cpp</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion java/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>
<name>TsFile: Java: Common</name>
Expand Down
4 changes: 2 additions & 2 deletions java/examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>examples</artifactId>
<name>TsFile: Java: Examples</name>
Expand All @@ -36,7 +36,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
4 changes: 2 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
<packaging>pom</packaging>
<name>TsFile: Java</name>
<modules>
Expand Down
6 changes: 3 additions & 3 deletions java/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>tools</artifactId>
<name>TsFile: Java: Tools</name>
<dependencies>
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>common</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand All @@ -50,7 +50,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java/tsfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</parent>
<artifactId>tsfile</artifactId>
<name>TsFile: Java: TsFile</name>
Expand All @@ -38,7 +38,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>common</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-250325-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ protected void reset() {
firstValue = 0;
previousValue = 0;
minDeltaBase = Integer.MAX_VALUE;
for (int i = 0; i < blockSize; i++) {
encodingBlockBuffer[i] = 0;
deltaBlockBuffer[i] = 0;
}
}

private int getValueWidth(int v) {
Expand Down Expand Up @@ -262,10 +258,6 @@ protected void reset() {
firstValue = 0L;
previousValue = 0L;
minDeltaBase = Long.MAX_VALUE;
for (int i = 0; i < blockSize; i++) {
encodingBlockBuffer[i] = 0;
deltaBlockBuffer[i] = 0L;
}
}

private int getValueWidth(long v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public IDeviceID create(String[] segments) {
// or we can just use a tuple like Relational DB.
private final String[] segments;

/** Cache the hash code */
private int hash; // Default to 0

/**
* Cache if the hash has been calculated as actually being zero, enabling us to avoid
* recalculating this.
*/
private boolean hashIsZero; // Default to false;

public StringArrayDeviceID(String... deviceIdSegments) {
this.segments = formalize(deviceIdSegments);
}
Expand Down Expand Up @@ -238,6 +247,9 @@ public String segment(int i) {

@Override
public int compareTo(IDeviceID o) {
if (this == o) {
return 0;
}
int thisSegmentNum = segmentNum();
int otherSegmentNum = o.segmentNum();
for (int i = 0; i < thisSegmentNum; i++) {
Expand Down Expand Up @@ -306,7 +318,16 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Arrays.hashCode(segments);
int h = hash;
if (h == 0 && !hashIsZero) {
h = Arrays.hashCode(segments);
if (h == 0) {
hashIsZero = true;
} else {
hash = h;
}
}
return h;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@

import org.apache.tsfile.common.conf.TSFileConfig;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.CompressionType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.file.metadata.statistics.Statistics;
import org.apache.tsfile.read.controller.IChunkMetadataLoader;
import org.apache.tsfile.read.reader.TsFileInput;
import org.apache.tsfile.utils.PublicBAOS;
import org.apache.tsfile.utils.RamUsageEstimator;
import org.apache.tsfile.utils.ReadWriteForEncodingUtils;
import org.apache.tsfile.utils.ReadWriteIOUtils;
import org.apache.tsfile.write.writer.LocalTsFileOutput;
import org.apache.tsfile.write.writer.tsmiterator.TSMIterator;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -394,4 +400,37 @@ public String toString() {
+ chunkMetadataList
+ '}';
}

public static void main(String[] args) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the serialization still accounts for a significant part in my experiment, so I would like to keep this a little longer in case I find some further optimizations in the future.

int deviceNum = 100;
int measurementNum = 10000;
List<TimeseriesMetadata> timeseriesMetadataList = new ArrayList<>(deviceNum * measurementNum);
for (int i = 0; i < deviceNum; i++) {
for (int j = 0; j < measurementNum; j++) {
timeseriesMetadataList.add(
TSMIterator.constructOneTimeseriesMetadata(
"s" + j,
Collections.singletonList(
new ChunkMetadata(
"s" + j,
TSDataType.INT64,
TSEncoding.PLAIN,
CompressionType.UNCOMPRESSED,
0,
Statistics.getStatsByType(TSDataType.INT64)))));
}
}

long startTime = System.currentTimeMillis();
int repeat = 100;
for (int i = 0; i < repeat; i++) {
LocalTsFileOutput tsFileOutput = new LocalTsFileOutput(new FileOutputStream("test.tsfile"));
for (int j = 0; j < timeseriesMetadataList.size(); j++) {
TimeseriesMetadata timeseriesMetadata = timeseriesMetadataList.get(j);
timeseriesMetadata.serializeTo(tsFileOutput);
}
tsFileOutput.close();
}
System.out.println(System.currentTimeMillis() - startTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ public static TsFileMetadata deserializeFrom(

// read bloom filter
if (buffer.hasRemaining()) {
byte[] bytes = ReadWriteIOUtils.readByteBufferWithSelfDescriptionLength(buffer);
if (bytes.length != 0) {
int filterSize = ReadWriteForEncodingUtils.readUnsignedVarInt(buffer);
int hashFunctionSize = ReadWriteForEncodingUtils.readUnsignedVarInt(buffer);
fileMetaData.bloomFilter =
BloomFilter.buildBloomFilter(bytes, filterSize, hashFunctionSize);
}
fileMetaData.bloomFilter = BloomFilter.deserialize(buffer);
}

fileMetaData.propertiesOffset = buffer.position() - startPos;
Expand Down Expand Up @@ -234,7 +228,7 @@ public int serializeTo(OutputStream outputStream) throws IOException {
// metaOffset
byteLen += ReadWriteIOUtils.write(metaOffset, outputStream);
if (bloomFilter != null) {
byteLen += serializeBloomFilter(outputStream, bloomFilter);
byteLen += bloomFilter.serialize(outputStream);
} else {
byteLen += ReadWriteForEncodingUtils.writeUnsignedVarInt(0, outputStream);
}
Expand All @@ -252,21 +246,6 @@ public int serializeTo(OutputStream outputStream) throws IOException {
return byteLen;
}

public int serializeBloomFilter(OutputStream outputStream, BloomFilter filter)
throws IOException {
int byteLen = 0;
byte[] bytes = filter.serialize();
byteLen += ReadWriteForEncodingUtils.writeUnsignedVarInt(bytes.length, outputStream);
if (bytes.length > 0) {
outputStream.write(bytes);
byteLen += bytes.length;
byteLen += ReadWriteForEncodingUtils.writeUnsignedVarInt(filter.getSize(), outputStream);
byteLen +=
ReadWriteForEncodingUtils.writeUnsignedVarInt(filter.getHashFunctionSize(), outputStream);
}
return byteLen;
}

public long getMetaOffset() {
return metaOffset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.apache.tsfile.fileSystem.fsFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

public interface FSFactory {
Expand Down Expand Up @@ -94,15 +94,15 @@ public interface FSFactory {
* @param filePath file path
* @return input stream
*/
BufferedInputStream getBufferedInputStream(String filePath);
InputStream getBufferedInputStream(String filePath);

/**
* get output stream
*
* @param filePath file path
* @return output stream
*/
BufferedOutputStream getBufferedOutputStream(String filePath);
OutputStream getBufferedOutputStream(String filePath);

/**
* move file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -101,13 +101,13 @@ public BufferedWriter getBufferedWriter(String filePath, boolean append) {
}

@Override
public BufferedInputStream getBufferedInputStream(String filePath) {
public InputStream getBufferedInputStream(String filePath) {
FSPath path = FSUtils.parse(filePath);
return getFSFactory(path.getFsType()).getBufferedInputStream(path.getPath());
}

@Override
public BufferedOutputStream getBufferedOutputStream(String filePath) {
public OutputStream getBufferedOutputStream(String filePath) {
FSPath path = FSUtils.parse(filePath);
return getFSFactory(path.getFsType()).getBufferedOutputStream(path.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

package org.apache.tsfile.fileSystem.fsFactory;

import org.apache.tsfile.utils.NoSyncBufferedInputStream;
import org.apache.tsfile.utils.NoSyncBufferedOutputStream;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -33,6 +34,8 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.Files;

Expand Down Expand Up @@ -91,19 +94,19 @@ public BufferedWriter getBufferedWriter(String filePath, boolean append) {
}

@Override
public BufferedInputStream getBufferedInputStream(String filePath) {
public InputStream getBufferedInputStream(String filePath) {
try {
return new BufferedInputStream(new FileInputStream(filePath));
return new NoSyncBufferedInputStream(new FileInputStream(filePath));
} catch (IOException e) {
logger.error("Failed to get buffered input stream for {}. ", filePath, e);
return null;
}
}

@Override
public BufferedOutputStream getBufferedOutputStream(String filePath) {
public OutputStream getBufferedOutputStream(String filePath) {
try {
return new BufferedOutputStream(new FileOutputStream(filePath));
return new NoSyncBufferedOutputStream(new FileOutputStream(filePath));
} catch (IOException e) {
logger.error("Failed to get buffered output stream for {}. ", filePath, e);
return null;
Expand Down
Loading
Loading