-
Notifications
You must be signed in to change notification settings - Fork 60
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
v4-write-process #345
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
e9fb2d2
v4 writer
761417898 2fe33ee
tmp
761417898 a6d212b
tmp
761417898 0c0e51e
write table
761417898 94fa48e
fix device_id.h
761417898 b21d479
write table, split deviceid
761417898 a92ae2c
fix get_device_id
761417898 1ffa310
fix tablet get_value
761417898 67b4db9
fix device id
761417898 dc8ba7d
complete the develop of the registration and writing process
761417898 87ca0cf
fix tablet
761417898 50fe3f4
fix v4 write
761417898 f6764ee
fix device_id.h
761417898 349c129
fix flush()
761417898 2924a72
Implement the Table Model Write Process
761417898 402bc9c
Implement the Table Model Write Process
761417898 dc9b350
Implement the Table Model Write Process
761417898 7ac7233
fix mem leak
761417898 142217a
try to fix mem leak
761417898 59095f3
try to fix mem leak
761417898 358a71b
try to fix mem leak
761417898 03d4b10
try to fix mem leak
761417898 810bf12
try to fix mem leak
761417898 64d04e4
Merge remote-tracking branch 'origin/develop' into feature/v4-write
761417898 77c4149
try to fix men leak
761417898 7038d0d
fix men leak
761417898 a9438c4
Implement the v4 writing process
761417898 90485b1
tmp
761417898 386c675
fix some issues
761417898 5ebc731
fix some issues
761417898 df95653
Merge branch 'feature/v4-write-fix' of github.com:761417898/tsfile in…
761417898 acd110d
add String type
zwhzzz0821 b3b3159
Merge branch 'feature/v4-write-fix' of github.com:761417898/tsfile in…
zwhzzz0821 a80d498
fix mem leak
zwhzzz0821 052a24a
fix format
zwhzzz0821 d33d13a
fix mingw compilation
761417898 ded900e
tmp
761417898 797b562
try to fix the index area of generated file
761417898 0d2be78
tmp
761417898 636794e
tmp
761417898 3b9a3c5
try to fix the index area of generated file
761417898 a8e81c5
tmp
761417898 b23f819
Implement read process of index area
761417898 0304010
bug fix
761417898 e44e992
tmp
761417898 03e7078
tmp
761417898 fac57f4
tmp
761417898 fc93f42
tmp
761417898 bd8d016
tmp
761417898 0d54705
tmp
761417898 0296de3
tmp
761417898 eed8618
fix mem leak
761417898 89771d4
fix mem leak
761417898 2390bba
fix compilation error
761417898 c7b5bbe
fix compilation error
761417898 8098038
fix compilation error
761417898 9882039
fix compilation error
761417898 9986dbf
bugfix
761417898 c602470
merge develop
761417898 5bd2c0d
bugfix
761417898 bd3e16e
fix LZ4 compressor
761417898 36efa31
tmp
761417898 717cb2d
Implemented the V4 tree model and table model write processes; Suppor…
761417898 5faebb7
Implemented the V4 tree model and table model write processes; Suppor…
761417898 4284302
Implemented the V4 tree model and table model write processes; Suppor…
761417898 01cee15
Implemented the V4 tree model and table model write processes; Suppor…
761417898 f899bdd
Fix some issues
761417898 79dc252
Fix some issues
761417898 79e14e3
Fix some issues
761417898 cefc80c
Fix some issues
761417898 b01ffe6
try to fix compilation error
761417898 54da3ab
try to fix compilation error
761417898 9e6cd21
fix some issues
761417898 2ab81f0
fix some issues
761417898 2f80ca9
Merge pull request #3 from 761417898/feature/v4
761417898 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
* 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 <memory> | ||
#include <numeric> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "common/allocator/byte_stream.h" | ||
#include "constant/tsfile_constant.h" | ||
#include "parser/path_nodes_generator.h" | ||
#include "utils/errno_define.h" | ||
|
||
namespace storage { | ||
class IDeviceID { | ||
public: | ||
virtual ~IDeviceID() = default; | ||
virtual int serialize(common::ByteStream& write_stream) { return 0; } | ||
virtual int deserialize(common::ByteStream& read_stream) { return 0; } | ||
virtual std::string get_table_name() { return ""; } | ||
virtual int segment_num() { return 0; } | ||
virtual const std::vector<std::string>& get_segments() const { | ||
return empty_segments_; | ||
} | ||
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; } | ||
|
||
protected: | ||
IDeviceID() : empty_segments_() {} | ||
|
||
private: | ||
const std::vector<std::string> empty_segments_; | ||
}; | ||
|
||
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_uint(segment_num(), | ||
write_stream))) { | ||
return ret; | ||
} | ||
for (const auto& segment : segments_) { | ||
if (RET_FAIL(common::SerializationUtil::write_str(segment, | ||
write_stream))) { | ||
return ret; | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
int deserialize(common::ByteStream& read_stream) override { | ||
int ret = common::E_OK; | ||
uint32_t num_segments; | ||
if (RET_FAIL(common::SerializationUtil::read_var_uint(num_segments, read_stream))) { | ||
return ret; | ||
} | ||
segments_.clear(); | ||
for (uint32_t i = 0; i < num_segments; ++i) { | ||
std::string segment; | ||
if (RET_FAIL(common::SerializationUtil::read_str(segment, read_stream))) { | ||
return ret; | ||
} | ||
segments_.push_back(segment); | ||
} | ||
return ret; | ||
} | ||
|
||
std::string get_table_name() override { | ||
return segments_.empty() ? "" : segments_[0]; | ||
} | ||
|
||
int segment_num() override { return static_cast<int>(segments_.size()); } | ||
|
||
const std::vector<std::string>& get_segments() const override { | ||
return segments_; | ||
} | ||
|
||
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_; | ||
|
||
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()); | ||
} | ||
|
||
std::vector<std::string> split_device_id_string( | ||
const std::string& device_id_string) { | ||
auto splits = | ||
storage::PathNodesGenerator::invokeParser(device_id_string); | ||
return split_device_id_string(splits); | ||
} | ||
|
||
std::vector<std::string> split_device_id_string( | ||
const std::vector<std::string>& splits) { | ||
size_t segment_cnt = splits.size(); | ||
std::vector<std::string> final_segments; | ||
|
||
if (segment_cnt == 0) { | ||
return final_segments; | ||
} | ||
|
||
if (segment_cnt == 1) { | ||
// "root" -> {"root"} | ||
final_segments.push_back(splits[0]); | ||
} else if (segment_cnt < static_cast<size_t>( | ||
storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME + 1)) { | ||
// "root.a" -> {"root", "a"} | ||
// "root.a.b" -> {"root.a", "b"} | ||
std::string table_name = std::accumulate( | ||
splits.begin(), splits.end() - 1, std::string(), | ||
[](const std::string& a, const std::string& b) { | ||
return a.empty() ? b : a + storage::PATH_SEPARATOR + b; | ||
}); | ||
final_segments.push_back(table_name); | ||
final_segments.push_back(splits.back()); | ||
} else { | ||
// "root.a.b.c" -> {"root.a.b", "c"} | ||
// "root.a.b.c.d" -> {"root.a.b", "c", "d"} | ||
std::string table_name = std::accumulate( | ||
splits.begin(), | ||
splits.begin() + storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME, | ||
std::string(), [](const std::string& a, const std::string& b) { | ||
return a.empty() ? b : a + storage::PATH_SEPARATOR + b; | ||
}); | ||
|
||
final_segments.emplace_back(std::move(table_name)); | ||
final_segments.insert( | ||
final_segments.end(), | ||
splits.begin() + storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME, | ||
splits.end()); | ||
} | ||
|
||
return final_segments; | ||
} | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.