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

v4-write-process #345

Merged
merged 75 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
e9fb2d2
v4 writer
761417898 Dec 9, 2024
2fe33ee
tmp
761417898 Dec 9, 2024
a6d212b
tmp
761417898 Dec 10, 2024
0c0e51e
write table
761417898 Dec 10, 2024
94fa48e
fix device_id.h
761417898 Dec 10, 2024
b21d479
write table, split deviceid
761417898 Dec 11, 2024
a92ae2c
fix get_device_id
761417898 Dec 11, 2024
1ffa310
fix tablet get_value
761417898 Dec 12, 2024
67b4db9
fix device id
761417898 Dec 12, 2024
dc8ba7d
complete the develop of the registration and writing process
761417898 Dec 12, 2024
87ca0cf
fix tablet
761417898 Dec 13, 2024
50fe3f4
fix v4 write
761417898 Dec 16, 2024
f6764ee
fix device_id.h
761417898 Dec 16, 2024
349c129
fix flush()
761417898 Dec 21, 2024
2924a72
Implement the Table Model Write Process
761417898 Dec 23, 2024
402bc9c
Implement the Table Model Write Process
761417898 Dec 23, 2024
dc9b350
Implement the Table Model Write Process
761417898 Dec 23, 2024
7ac7233
fix mem leak
761417898 Dec 23, 2024
142217a
try to fix mem leak
761417898 Dec 24, 2024
59095f3
try to fix mem leak
761417898 Dec 24, 2024
358a71b
try to fix mem leak
761417898 Dec 24, 2024
03d4b10
try to fix mem leak
761417898 Dec 24, 2024
810bf12
try to fix mem leak
761417898 Dec 24, 2024
64d04e4
Merge remote-tracking branch 'origin/develop' into feature/v4-write
761417898 Dec 24, 2024
77c4149
try to fix men leak
761417898 Dec 24, 2024
7038d0d
fix men leak
761417898 Dec 25, 2024
a9438c4
Implement the v4 writing process
761417898 Dec 25, 2024
90485b1
tmp
761417898 Dec 29, 2024
386c675
fix some issues
761417898 Dec 29, 2024
5ebc731
fix some issues
761417898 Jan 1, 2025
df95653
Merge branch 'feature/v4-write-fix' of github.com:761417898/tsfile in…
761417898 Jan 1, 2025
acd110d
add String type
zwhzzz0821 Jan 1, 2025
b3b3159
Merge branch 'feature/v4-write-fix' of github.com:761417898/tsfile in…
zwhzzz0821 Jan 1, 2025
a80d498
fix mem leak
zwhzzz0821 Jan 2, 2025
052a24a
fix format
zwhzzz0821 Jan 2, 2025
d33d13a
fix mingw compilation
761417898 Jan 2, 2025
ded900e
tmp
761417898 Jan 2, 2025
797b562
try to fix the index area of generated file
761417898 Jan 2, 2025
0d2be78
tmp
761417898 Jan 3, 2025
636794e
tmp
761417898 Jan 6, 2025
3b9a3c5
try to fix the index area of generated file
761417898 Jan 7, 2025
a8e81c5
tmp
761417898 Jan 8, 2025
b23f819
Implement read process of index area
761417898 Jan 10, 2025
0304010
bug fix
761417898 Jan 10, 2025
e44e992
tmp
761417898 Jan 13, 2025
03e7078
tmp
761417898 Jan 13, 2025
fac57f4
tmp
761417898 Jan 14, 2025
fc93f42
tmp
761417898 Jan 14, 2025
bd8d016
tmp
761417898 Jan 15, 2025
0d54705
tmp
761417898 Jan 16, 2025
0296de3
tmp
761417898 Jan 16, 2025
eed8618
fix mem leak
761417898 Jan 16, 2025
89771d4
fix mem leak
761417898 Jan 16, 2025
2390bba
fix compilation error
761417898 Jan 17, 2025
c7b5bbe
fix compilation error
761417898 Jan 17, 2025
8098038
fix compilation error
761417898 Jan 17, 2025
9882039
fix compilation error
761417898 Jan 17, 2025
9986dbf
bugfix
761417898 Jan 17, 2025
c602470
merge develop
761417898 Jan 17, 2025
5bd2c0d
bugfix
761417898 Jan 17, 2025
bd3e16e
fix LZ4 compressor
761417898 Jan 18, 2025
36efa31
tmp
761417898 Jan 18, 2025
717cb2d
Implemented the V4 tree model and table model write processes; Suppor…
761417898 Jan 18, 2025
5faebb7
Implemented the V4 tree model and table model write processes; Suppor…
761417898 Jan 18, 2025
4284302
Implemented the V4 tree model and table model write processes; Suppor…
761417898 Jan 18, 2025
01cee15
Implemented the V4 tree model and table model write processes; Suppor…
761417898 Jan 18, 2025
f899bdd
Fix some issues
761417898 Jan 21, 2025
79dc252
Fix some issues
761417898 Jan 21, 2025
79e14e3
Fix some issues
761417898 Jan 21, 2025
cefc80c
Fix some issues
761417898 Jan 21, 2025
b01ffe6
try to fix compilation error
761417898 Jan 21, 2025
54da3ab
try to fix compilation error
761417898 Jan 22, 2025
9e6cd21
fix some issues
761417898 Jan 22, 2025
2ab81f0
fix some issues
761417898 Jan 22, 2025
2f80ca9
Merge pull request #3 from 761417898/feature/v4
761417898 Jan 22, 2025
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
3 changes: 3 additions & 0 deletions cpp/src/common/allocator/my_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct String {
len_ = 0;
buf_ = nullptr;
}
std::string to_string() {
return std::string(buf_, len_);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already one such method. You can view the develop branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

FORCE_INLINE int dup_from(const std::string &str, common::PageArena &pa) {
len_ = str.size();
if (UNLIKELY(len_ == 0)) {
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/common/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef COMMON_CONFIG_CONFIG_H
#define COMMON_CONFIG_CONFIG_H

#include <stdint.h>
#include <cstdint>

#include "common/mutex/mutex.h"
#include "utils/db_utils.h"
Expand All @@ -46,9 +46,11 @@ typedef struct ConfigValue {
CompressionType time_compress_type_;
int32_t chunk_group_size_threshold_;
int32_t record_count_for_next_mem_check_;
bool encrypt_flag_ = false;
} ConfigValue;

extern void init_config_value();
extern TSEncoding get_value_encoder(TSDataType data_type);

// In the future, configuration items need to be dynamically adjusted according
// to the level
Expand Down
1 change: 1 addition & 0 deletions cpp/src/common/db_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum TSDataType {
DOUBLE = 4,
TEXT = 5,
VECTOR = 6,
STRING = 11,
NULL_TYPE = 254,
INVALID_DATATYPE = 255
};
Expand Down
212 changes: 212 additions & 0 deletions cpp/src/common/device_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* 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.
*/

#ifndef COMMON_DEVICE_ID_H
#define COMMON_DEVICE_ID_H

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iostream>
#include <memory>
#include <numeric>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

#include "common/allocator/byte_stream.h"
#include "utils/errno_define.h"

class IDeviceID {
public:
virtual ~IDeviceID() = default;
virtual int serialize(common::ByteStream& write_stream) { return 0; }
virtual std::string get_table_name() { return ""; }
virtual int segment_num() { return 0; }
virtual std::vector<std::string> get_segments() const { return {}; }
virtual std::string get_device_name() const { return ""; };
virtual bool operator<(const IDeviceID& other) { return 0; }
virtual bool operator==(const IDeviceID& other) { return false; }
virtual bool operator!=(const IDeviceID& other) { return false; }
};

struct IDeviceIDComparator {
bool operator()(const std::shared_ptr<IDeviceID>& lhs,
const std::shared_ptr<IDeviceID>& rhs) const {
return *lhs < *rhs;
}
};

class StringArrayDeviceID : public IDeviceID {
public:
explicit StringArrayDeviceID(const std::vector<std::string>& segments)
: segments_(formalize(segments)) {}

explicit StringArrayDeviceID(const std::string& device_id_string)
: segments_(split_device_id_string(device_id_string)) {}

~StringArrayDeviceID() override = default;

std::string get_device_name() const override {
return std::accumulate(std::next(segments_.begin()), segments_.end(),
segments_.front(),
[](std::string a, const std::string& b) {
return std::move(a) + "." + b;
});
};

int serialize(common::ByteStream& write_stream) override {
int ret = common::E_OK;
if (RET_FAIL(common::SerializationUtil::write_var_int(segment_num(),
write_stream))) {
return ret;
}
for (const auto& segment : segments_) {
if (RET_FAIL(common::SerializationUtil::write_var_int(
segment.size(), write_stream))) {
return ret;
} else if (RET_FAIL(write_stream.write_buf(segment.c_str(),
segment.size()))) {
return ret;
}
}
return ret;
}

std::string get_table_name() override {
return segments_.empty() ? "" : segments_[0];
}

int segment_num() override { return static_cast<int>(segments_.size()); }

std::vector<std::string> get_segments() const override { return segments_; }
Copy link
Contributor

Choose a reason for hiding this comment

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

If read only
you can return const std::vector<std::string>& to avoid copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


virtual bool operator<(const IDeviceID& other) override {
auto other_segments = other.get_segments();
return std::lexicographical_compare(segments_.begin(), segments_.end(),
other_segments.begin(),
other_segments.end());
}

bool operator==(const IDeviceID& other) override {
auto other_segments = other.get_segments();
return (segments_.size() == other_segments.size()) &&
std::equal(segments_.begin(), segments_.end(),
other_segments.begin());
}

bool operator!=(const IDeviceID& other) override {
return !(*this == other);
}

private:
std::vector<std::string> segments_;

static std::vector<std::string> formalize(
const std::vector<std::string>& segments) {
auto it =
std::find_if(segments.rbegin(), segments.rend(),
[](const std::string& seg) { return !seg.empty(); });
return std::vector<std::string>(segments.begin(), it.base());
}

static std::vector<std::string> split_device_id_string(
std::basic_string<char> device_id_string) {
std::vector<std::string> splits;
std::istringstream stream(device_id_string);
std::string segment;
while (std::getline(stream, segment, '.')) {
splits.push_back(segment);
}
return splits;
}
jt2594838 marked this conversation as resolved.
Show resolved Hide resolved
};

class PlainDeviceID : public IDeviceID {
jt2594838 marked this conversation as resolved.
Show resolved Hide resolved
public:
explicit PlainDeviceID(const std::string& deviceID)
: device_id_(deviceID), tableName_(), segments_() {}

~PlainDeviceID() override = default;

bool operator==(const IDeviceID& other) override {
return device_id_ == other.get_device_name();
}

bool operator!=(const IDeviceID& other) override {
return device_id_ != other.get_device_name();
}

int serialize(common::ByteStream& write_stream) override {
int ret = common::E_OK;
if (RET_FAIL(common::SerializationUtil::write_var_int(device_id_.size(),
write_stream))) {
return ret;
} else if (RET_FAIL(write_stream.write_buf(device_id_.c_str(),
device_id_.size()))) {
return ret;
}
return ret;
}

std::string get_device_name() const override { return device_id_; };

std::string get_table_name() override {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can verify that you need to return a copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if (!tableName_.empty()) {
return tableName_;
}

size_t lastSeparatorPos = device_id_.find_last_of('.');
Copy link
Contributor

Choose a reason for hiding this comment

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

use PATH_SEPARATOR_CHAR instead of '.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if (lastSeparatorPos == std::string::npos) {
tableName_ = device_id_; // Use entire deviceID as tableName
} else {
tableName_ = device_id_.substr(0, lastSeparatorPos);
}
return tableName_;
}

int segment_num() override {
if (!segments_.empty()) {
return static_cast<int>(segments_.size());
}
split_segments();
return static_cast<int>(segments_.size());
}

bool operator<(const IDeviceID& other) override {
return device_id_ < other.get_device_name();
}

private:
std::string device_id_;
std::string tableName_;
std::vector<std::string> segments_;

void split_segments() {
std::istringstream stream(device_id_);
std::string segment;
while (std::getline(stream, segment, '.')) {
segments_.push_back(segment);
}
}
};

#endif
26 changes: 26 additions & 0 deletions cpp/src/common/global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ void init_config_value() {
g_config_value_.time_compress_type_ = LZ4;
}

extern TSEncoding get_value_encoder(TSDataType data_type) {
switch (data_type) {
case BOOLEAN:
return TSEncoding::RLE;
case INT32:
return TSEncoding::TS_2DIFF;
case INT64:
return TSEncoding::TS_2DIFF;
case FLOAT:
return TSEncoding::GORILLA;
case DOUBLE:
return TSEncoding::GORILLA;
case TEXT:
return TSEncoding::PLAIN;
case VECTOR:
break;
case NULL_TYPE:
break;
case INVALID_DATATYPE:
break;
default:
break;
}
return TSEncoding::PLAIN;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that silently converting unsupported encoding formats to PLAIN may cause issues. Some form of feedback or notification is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

void config_set_page_max_point_count(uint32_t page_max_ponint_count) {
g_config_value_.page_writer_max_point_num_ = page_max_ponint_count;
}
Expand Down
Loading
Loading