Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
e9fb2d2
v4 writer
hongzhi-gao Dec 9, 2024
2fe33ee
tmp
hongzhi-gao Dec 9, 2024
a6d212b
tmp
hongzhi-gao Dec 10, 2024
0c0e51e
write table
hongzhi-gao Dec 10, 2024
94fa48e
fix device_id.h
hongzhi-gao Dec 10, 2024
b21d479
write table, split deviceid
hongzhi-gao Dec 11, 2024
a92ae2c
fix get_device_id
hongzhi-gao Dec 11, 2024
1ffa310
fix tablet get_value
hongzhi-gao Dec 12, 2024
67b4db9
fix device id
hongzhi-gao Dec 12, 2024
dc8ba7d
complete the develop of the registration and writing process
hongzhi-gao Dec 12, 2024
87ca0cf
fix tablet
hongzhi-gao Dec 13, 2024
50fe3f4
fix v4 write
hongzhi-gao Dec 16, 2024
f6764ee
fix device_id.h
hongzhi-gao Dec 16, 2024
349c129
fix flush()
hongzhi-gao Dec 21, 2024
2924a72
Implement the Table Model Write Process
hongzhi-gao Dec 23, 2024
402bc9c
Implement the Table Model Write Process
hongzhi-gao Dec 23, 2024
dc9b350
Implement the Table Model Write Process
hongzhi-gao Dec 23, 2024
7ac7233
fix mem leak
hongzhi-gao Dec 23, 2024
142217a
try to fix mem leak
hongzhi-gao Dec 24, 2024
59095f3
try to fix mem leak
hongzhi-gao Dec 24, 2024
358a71b
try to fix mem leak
hongzhi-gao Dec 24, 2024
03d4b10
try to fix mem leak
hongzhi-gao Dec 24, 2024
810bf12
try to fix mem leak
hongzhi-gao Dec 24, 2024
64d04e4
Merge remote-tracking branch 'origin/develop' into feature/v4-write
hongzhi-gao Dec 24, 2024
77c4149
try to fix men leak
hongzhi-gao Dec 24, 2024
7038d0d
fix men leak
hongzhi-gao Dec 25, 2024
a9438c4
Implement the v4 writing process
hongzhi-gao Dec 25, 2024
90485b1
tmp
hongzhi-gao Dec 29, 2024
386c675
fix some issues
hongzhi-gao Dec 29, 2024
5ebc731
fix some issues
hongzhi-gao Jan 1, 2025
df95653
Merge branch 'feature/v4-write-fix' of github.com:761417898/tsfile in…
hongzhi-gao 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
hongzhi-gao Jan 2, 2025
ded900e
tmp
hongzhi-gao Jan 2, 2025
797b562
try to fix the index area of generated file
hongzhi-gao Jan 2, 2025
0d2be78
tmp
hongzhi-gao Jan 3, 2025
e819de1
Merge remote-tracking branch 'upstream/develop' into tmp
zwhzzz0821 Jan 6, 2025
67c22fd
fix for merge
zwhzzz0821 Jan 6, 2025
636794e
tmp
hongzhi-gao Jan 6, 2025
3b9a3c5
try to fix the index area of generated file
hongzhi-gao Jan 7, 2025
a8e81c5
tmp
hongzhi-gao Jan 8, 2025
371c16c
save work
zwhzzz0821 Jan 9, 2025
b23f819
Implement read process of index area
hongzhi-gao Jan 10, 2025
0304010
bug fix
hongzhi-gao Jan 10, 2025
e44e992
tmp
hongzhi-gao Jan 13, 2025
03e7078
tmp
hongzhi-gao Jan 13, 2025
fac57f4
tmp
hongzhi-gao Jan 14, 2025
fc93f42
tmp
hongzhi-gao Jan 14, 2025
bd8d016
tmp
hongzhi-gao Jan 15, 2025
7b10696
save work
zwhzzz0821 Jan 16, 2025
0d54705
tmp
hongzhi-gao Jan 16, 2025
d5f3ab2
fix
zwhzzz0821 Jan 16, 2025
0296de3
tmp
hongzhi-gao Jan 16, 2025
eed8618
fix mem leak
hongzhi-gao Jan 16, 2025
89771d4
fix mem leak
hongzhi-gao Jan 16, 2025
2390bba
fix compilation error
hongzhi-gao Jan 17, 2025
c7b5bbe
fix compilation error
hongzhi-gao Jan 17, 2025
8098038
fix compilation error
hongzhi-gao Jan 17, 2025
9882039
fix compilation error
hongzhi-gao Jan 17, 2025
9986dbf
bugfix
hongzhi-gao Jan 17, 2025
c602470
merge develop
hongzhi-gao Jan 17, 2025
5bd2c0d
bugfix
hongzhi-gao Jan 17, 2025
bd3e16e
fix LZ4 compressor
hongzhi-gao Jan 18, 2025
36efa31
tmp
hongzhi-gao Jan 18, 2025
717cb2d
Implemented the V4 tree model and table model write processes; Suppor…
hongzhi-gao Jan 18, 2025
5faebb7
Implemented the V4 tree model and table model write processes; Suppor…
hongzhi-gao Jan 18, 2025
4284302
Implemented the V4 tree model and table model write processes; Suppor…
hongzhi-gao Jan 18, 2025
6bfb461
save work
zwhzzz0821 Jan 20, 2025
fc96b23
Merge branch 'feature/v4-write' into tmp
zwhzzz0821 Jan 20, 2025
35f95f0
save work
zwhzzz0821 Jan 21, 2025
1a7ba69
fix for include circle
zwhzzz0821 Jan 21, 2025
d59d635
save work
zwhzzz0821 Jan 25, 2025
be8e9f0
save work
zwhzzz0821 Jan 27, 2025
1501c29
save work
zwhzzz0821 Feb 5, 2025
de4a810
save work
zwhzzz0821 Feb 13, 2025
e65da59
save work
zwhzzz0821 Feb 13, 2025
afba08c
fix memleak
zwhzzz0821 Feb 13, 2025
3d43d21
fix mem leak
zwhzzz0821 Feb 13, 2025
d84bcdd
save work
zwhzzz0821 Feb 14, 2025
5a03ca8
remove some files
zwhzzz0821 Feb 14, 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
1 change: 0 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(TsFile_CPP_VERSION 2.0.0.dev)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -Werror")
message("cmake using: USE_CPP11=${USE_CPP11}")


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if(DEFINED ENV{CXX})
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/common/allocator/alloc_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ enum AllocModID {
MOD_BITENCODE_OBJ = 30,
MOD_DICENCODE_OBJ = 31,
MOD_ZIGZAG_OBJ = 32,
__LAST_MOD_ID = 33, // prev + 1,
MOD_DEVICE_META_ITER = 33,
MOD_DEVICE_TASK_ITER = 34,
MOD_DEVICE_ORDER_TSBLOCK_READER = 35,
__LAST_MOD_ID = 36, // prev + 1,
__MAX_MOD_ID = 127, // leave 1 bit to detect header size
};

Expand Down
21 changes: 20 additions & 1 deletion cpp/src/common/allocator/my_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ struct String {

String() : buf_(nullptr), len_(0) {}
String(char *buf, uint32_t len) : buf_(buf), len_(len) {}
String(const std::string& str, common::PageArena& pa) : buf_(nullptr), len_(0) {
dup_from(str, pa);
}
String(const std::string& str) {
buf_ = (char*)str.c_str();
len_ = str.size();
}
FORCE_INLINE bool is_null() const { return buf_ == nullptr && len_ == 0; }
FORCE_INLINE void reset() {
len_ = 0;
Expand Down Expand Up @@ -128,6 +135,18 @@ struct String {
}
}

FORCE_INLINE void max(const String &that, common::PageArena &pa) {
if (compare(that) < 0) {
this->dup_from(that, pa);
}
}

FORCE_INLINE void min(const String &that, common::PageArena &pa) {
if (compare(that) > 0) {
this->dup_from(that, pa);
}
}

bool operator<(const String &other) const {
if (this->is_null() && other.is_null()) {
return false;
Expand All @@ -147,7 +166,7 @@ struct String {

return this->len_ < other.len_;
}
std::string to_std_string() { return std::string(buf_, len_); }
std::string to_std_string() const { return std::string(buf_, len_); }

#ifndef NDEBUG
friend std::ostream &operator<<(std::ostream &os, const String &s) {
Expand Down
20 changes: 20 additions & 0 deletions cpp/src/common/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[[
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

https://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.
]]


226 changes: 226 additions & 0 deletions cpp/src/common/cache/lru_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*
* 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_CACHE_LRU_CACHE_H
#define COMMON_CACHE_LRU_CACHE_H

#include <unordered_map>
#include <list>
#include <mutex>
#include <algorithm>

#include "utils/errno_define.h"

namespace common {
/*
* a noop lockable concept that can be used in place of std::mutex
*/
class NullLock {
public:
void lock() {}
void unlock() {}
bool try_lock() { return true; }
};

template <typename K, typename V>
struct KeyValuePair {
public:
K key;
V value;

KeyValuePair(K k, V v) : key(std::move(k)), value(std::move(v)) {}
};

/**
* The LRU Cache class templated by
* Key - key type
* Value - value type
* MapType - an associative container like std::unordered_map
* LockType - a lock type derived from the Lock class (default:
*NullLock = no synchronization)
*
* The default NullLock based template is not thread-safe, however passing
*Lock=std::mutex will make it
* thread-safe
*/
template <class Key, class Value, class Lock = NullLock,
class Map = std::unordered_map<
Key, typename std::list<KeyValuePair<Key, Value>>::iterator>>
class Cache {
public:
typedef KeyValuePair<Key, Value> node_type;
typedef std::list<KeyValuePair<Key, Value>> list_type;
typedef Map map_type;
typedef Lock lock_type;
using Guard = std::lock_guard<lock_type>;
/**
* the maxSize is the soft limit of keys and (maxSize + elasticity) is the
* hard limit
* the cache is allowed to grow till (maxSize + elasticity) and is pruned
* back to maxSize keys set maxSize = 0 for an unbounded cache (but in that
* case, you're better off using a std::unordered_map directly anyway! :)
*/
explicit Cache(size_t maxSize = 64, size_t elasticity = 10)
: maxSize_(maxSize), elasticity_(elasticity) {}
virtual ~Cache() = default;
size_t size() const {
Guard g(lock_);
return cache_.size();
}
bool empty() const {
Guard g(lock_);
return cache_.empty();
}
void clear() {
Guard g(lock_);
cache_.clear();
keys_.clear();
}
void insert(const Key& k, Value v) {
Guard g(lock_);
const auto iter = cache_.find(k);
if (iter != cache_.end()) {
iter->second->value = v;
keys_.splice(keys_.begin(), keys_, iter->second);
return;
}

keys_.emplace_front(k, std::move(v));
cache_[k] = keys_.begin();
prune();
}
void emplace(const Key& k, Value&& v) {
Guard g(lock_);
keys_.emplace_front(k, std::move(v));
cache_[k] = keys_.begin();
prune();
}
/**
for backward compatibity. redirects to tryGetCopy()
*/
bool tryGet(const Key& kIn, Value& vOut) { return tryGetCopy(kIn, vOut); }

bool tryGetCopy(const Key& kIn, Value& vOut) {
Guard g(lock_);
Value tmp;
if (!tryGetRef_nolock(kIn, tmp)) {
return false;
}
vOut = tmp;
return true;
}

bool tryGetRef(const Key& kIn, Value& vOut) {
Guard g(lock_);
return tryGetRef_nolock(kIn, vOut);
}
/**
* The const reference returned here is only
* guaranteed to be valid till the next insert/delete
* in multi-threaded apps use getCopy() to be threadsafe
*/
const Value& getRef(const Key& k) {
Guard g(lock_);
return get_nolock(k);
}

/**
added for backward compatibility
*/
Value get(const Key& k) { return getCopy(k); }
/**
* returns a copy of the stored object (if found)
* safe to use/recommended in multi-threaded apps
*/
Value getCopy(const Key& k) {
Guard g(lock_);
return get_nolock(k);
}

bool remove(const Key& k) {
Guard g(lock_);
auto iter = cache_.find(k);
if (iter == cache_.end()) {
return false;
}
keys_.erase(iter->second);
cache_.erase(iter);
return true;
}
bool contains(const Key& k) const {
Guard g(lock_);
return cache_.find(k) != cache_.end();
}

size_t getMaxSize() const { return maxSize_; }
size_t getElasticity() const { return elasticity_; }
size_t getMaxAllowedSize() const { return maxSize_ + elasticity_; }
template <typename F>
void cwalk(F& f) const {
Guard g(lock_);
std::for_each(keys_.begin(), keys_.end(), f);
}

protected:
const int get_nolock(const Key& k, Value& vOut) {
const auto iter = cache_.find(k);
if (iter == cache_.end()) {
return E_NOT_EXIST;
}
keys_.splice(keys_.begin(), keys_, iter->second);
vOut = iter->second->value;
return E_OK;
}
bool tryGetRef_nolock(const Key& kIn, Value& vOut) {
const auto iter = cache_.find(kIn);
if (iter == cache_.end()) {
return false;
}
keys_.splice(keys_.begin(), keys_, iter->second);
vOut = iter->second->value;
return true;
}
size_t prune() {
size_t maxAllowed = maxSize_ + elasticity_;
if (maxSize_ == 0 || cache_.size() < maxAllowed) {
return 0;
}
size_t count = 0;
while (cache_.size() > maxSize_) {
cache_.erase(keys_.back().key);
keys_.pop_back();
++count;
}
return count;
}

private:
// Disallow copying.
Cache(const Cache&) = delete;
Cache& operator=(const Cache&) = delete;

mutable Lock lock_;
Map cache_;
list_type keys_;
size_t maxSize_;
size_t elasticity_;
};
} // namespace common

#endif // COMMON_CACHE_LRU_CACHE_H
6 changes: 4 additions & 2 deletions 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,10 +46,12 @@ 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);
extern CompressionType get_default_compressor();
// In the future, configuration items need to be dynamically adjusted according
// to the level
extern void set_config_value();
Expand Down
16 changes: 11 additions & 5 deletions cpp/src/common/db_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@
#include <iostream>

#include "utils/util_define.h"
#include "common/allocator/my_string.h"

namespace common {

enum TSDataType {
enum TSDataType : uint8_t {
BOOLEAN = 0,
INT32 = 1,
INT64 = 2,
FLOAT = 3,
DOUBLE = 4,
TEXT = 5,
VECTOR = 6,
STRING = 11,
NULL_TYPE = 254,
INVALID_DATATYPE = 255
};

enum TSEncoding {
enum TSEncoding : uint8_t {
PLAIN = 0,
DICTIONARY = 1,
RLE = 2,
Expand All @@ -53,7 +55,7 @@ enum TSEncoding {
INVALID_ENCODING = 255
};

enum CompressionType {
enum CompressionType : uint8_t {
UNCOMPRESSED = 0,
SNAPPY = 1,
GZIP = 2,
Expand All @@ -65,12 +67,12 @@ enum CompressionType {
INVALID_COMPRESSION = 255
};

extern const char* s_data_type_names[7];
extern const char* s_data_type_names[8];
extern const char* s_encoding_names[12];
extern const char* s_compression_names[8];

FORCE_INLINE const char* get_data_type_name(TSDataType type) {
ASSERT(type >= BOOLEAN && type <= VECTOR);
ASSERT(type >= BOOLEAN && type <= STRING);
return s_data_type_names[type];
}

Expand Down Expand Up @@ -148,6 +150,10 @@ template <>
FORCE_INLINE common::TSDataType GetDataTypeFromTemplateType<double>() {
return common::DOUBLE;
}
template <>
FORCE_INLINE common::TSDataType GetDataTypeFromTemplateType<common::String>() {
return common::STRING;
}

FORCE_INLINE size_t get_data_type_size(TSDataType data_type) {
switch (data_type) {
Expand Down
Loading