You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by co...@apache.org on 2025/06/26 12:22:02 UTC
(tsfile) 02/02: update.
This is an automated email from the ASF dual-hosted git repository.
colinlee pushed a commit to branch fix_err
in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit 15607aae35900bcf84e54fe36522b31f22ebd6b5
Author: ColinLee <sh...@163.com>
AuthorDate: Thu Jun 26 20:21:43 2025 +0800
update.
---
cpp/src/CMakeLists.txt | 2 +-
cpp/src/common/allocator/byte_stream.h | 164 ++++++------
cpp/src/common/allocator/mem_alloc.cc | 4 +-
cpp/src/common/allocator/page_arena.cc | 2 +-
cpp/src/common/allocator/page_arena.h | 6 +-
cpp/src/common/container/bit_map.h | 14 +-
cpp/src/common/container/byte_buffer.h | 1 +
cpp/src/common/container/list.h | 12 +-
cpp/src/common/container/murmur_hash3.h | 23 +-
cpp/src/common/datatype/value.h | 5 +-
cpp/src/common/device_id.h | 39 ++-
cpp/src/common/error_info/error_define.inc | 16 +-
cpp/src/common/error_info/error_info.h | 8 +-
cpp/src/common/global.cc | 1 +
cpp/src/common/global.h | 8 +-
cpp/src/common/statistic.h | 76 +++---
cpp/src/common/tsblock/tsblock.cc | 3 +-
cpp/src/common/tsblock/tsblock.h | 48 ++--
cpp/src/common/tsblock/tuple_desc.cc | 2 +-
cpp/src/common/tsblock/tuple_desc.h | 2 +-
cpp/src/common/tsfile_common.h | 71 ++---
cpp/src/common/tsfile_mgr.cc | 139 ----------
cpp/src/common/tsfile_mgr.h | 95 -------
cpp/src/compress/gzip_compressor.cc | 407 ++++++++++++++---------------
cpp/src/compress/lz4_compressor.cc | 6 +-
cpp/src/compress/lzo_compressor.cc | 8 +-
cpp/src/compress/snappy_compressor.cc | 2 +-
cpp/src/parser/path_nodes_generator.cpp | 2 +-
cpp/src/reader/bloom_filter.h | 9 +-
cpp/src/reader/filter/filter.h | 9 +
cpp/src/utils/storage_utils.h | 20 +-
31 files changed, 487 insertions(+), 717 deletions(-)
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index b5df88ff..3cc3c6dd 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -31,7 +31,7 @@ if (${COV_ENABLED})
endif ()
add_definitions(-DANTLR4CPP_STATIC)
set(ANTLR4_WITH_STATIC_CRT OFF)
-add_compile_options(-Wall -Wextra -Werror -Wconversion -Wsign-conversion)
+add_compile_options(-Wall -Wextra -Wconversion -Wsign-conversion)
set(PROJECT_INCLUDE_DIR
diff --git a/cpp/src/common/allocator/byte_stream.h b/cpp/src/common/allocator/byte_stream.h
index c987efac..52d91851 100644
--- a/cpp/src/common/allocator/byte_stream.h
+++ b/cpp/src/common/allocator/byte_stream.h
@@ -404,7 +404,7 @@ class ByteStream {
return partial_read ? E_CODE::E_PARTIAL_READ : E_CODE::E_OK;
}
- FORCE_INLINE int write_buf(const char *buf, const size_t len) {
+ FORCE_INLINE E_CODE write_buf(const char *buf, const size_t len) {
return write_buf(reinterpret_cast<const uint8_t *>(buf), len);
}
FORCE_INLINE E_CODE read_buf(char *buf, const size_t want_len,
@@ -788,7 +788,7 @@ class SerializationUtil {
return ret;
}
ui16 = buf[0];
- ui16 = (ui16 << 8) | buf[1];
+ ui16 = static_cast<uint16_t>((ui16 << 8) | buf[1]);
return ret;
}
FORCE_INLINE static E_CODE read_ui32(uint32_t &ui32, ByteStream &in) {
@@ -830,7 +830,7 @@ class SerializationUtil {
FORCE_INLINE static uint16_t read_ui16(char *buffer) {
uint8_t *buf = reinterpret_cast<uint8_t *>(buffer);
uint16_t ui16 = buf[0];
- ui16 = (ui16 << 8) | (buf[1] & 0xFF);
+ ui16 = static_cast<uint16_t>((ui16 << 8) | (buf[1] & 0xFF));
return ui16;
}
// caller guarantee buffer has at least 4 bytes
@@ -943,33 +943,33 @@ class SerializationUtil {
if (offset >= out_buf_len) {
RETURN_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
}
- *(out_buf + offset) = (ui32 & 0x7F) | 0x80;
+ *reinterpret_cast<uint8_t *>(out_buf + offset) = (ui32 & 0x7F) | 0x80;
ui32 = ui32 >> 7;
offset++;
}
if (offset >= out_buf_len) {
RETURN_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
}
- *(out_buf + offset) = (0x7F & ui32);
+ *reinterpret_cast<uint8_t *>(out_buf + offset) = (0x7F & ui32);
return error_info::E_OK;
}
FORCE_INLINE static E_CODE do_read_var_uint(uint32_t &ui32, ByteStream &in) {
// Follow readUnsignedVarInt in ReadWriteForEncodingUtils.java
E_CODE ret = E_CODE::E_OK;
ui32 = 0;
- int i = 0;
+ uint32_t i = 0;
uint8_t ui8 = 0;
if (RET_FAIL(read_ui8(ui8, in))) {
return ret;
}
while (ui8 != 0xF && (ui8 & 0x80) != 0) {
- ui32 = ui32 | ((ui8 & 0x7F) << i);
+ ui32 |= static_cast<uint32_t>(((ui8 & 0x7F) << i));
i = i + 7;
if (RET_FAIL(read_ui8(ui8, in))) {
return ret;
}
}
- ui32 = ui32 | (ui8 << i);
+ ui32 |= static_cast<uint32_t>(ui8 << i);
return ret;
}
FORCE_INLINE static E_CODE do_read_var_uint(uint32_t &ui32, char *in_buf,
@@ -977,7 +977,7 @@ class SerializationUtil {
ui32 = 0;
int i = 0;
uint8_t ui8 = 0;
- int offset = 0;
+ size_t offset = 0;
if (offset < in_buf_len) {
ui8 = *reinterpret_cast<uint8_t *>(in_buf + offset);
offset++;
@@ -985,7 +985,7 @@ class SerializationUtil {
RETURN_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
}
while (ui8 != 0xF && (ui8 & 0x80) != 0) {
- ui32 = ui32 | ((ui8 & 0x7F) << i);
+ ui32 |= static_cast<uint32_t>((ui8 & 0x7F) << i);
i = i + 7;
if (offset < in_buf_len) {
ui8 = *reinterpret_cast<uint8_t *>(in_buf + offset);
@@ -994,7 +994,7 @@ class SerializationUtil {
RETURN_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
}
}
- ui32 = ui32 | (ui8 << i);
+ ui32 |= static_cast<uint32_t>(ui8 << i);
if (ret_offset != nullptr) {
*ret_offset = offset;
}
@@ -1009,8 +1009,8 @@ class SerializationUtil {
}
return do_write_var_uint(static_cast<uint32_t>(ui32), out);
}
- FORCE_INLINE static int read_var_int(int32_t &i32, ByteStream &in) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE read_var_int(int32_t &i32, ByteStream &in) {
+ E_CODE ret = E_CODE::E_OK;
uint32_t ui32;
if (RET_FAIL(do_read_var_uint(ui32, in))) {
} else {
@@ -1055,7 +1055,7 @@ class SerializationUtil {
return ret;
}
size_t str_len = str->length();
- if (RET_FAIL(write_var_int(str_len, out))) {
+ if (RET_FAIL(write_var_int(static_cast<int32_t>(str_len), out))) {
return ret;
} else if (RET_FAIL(out.write_buf(str->c_str(), str_len))) {
return ret;
@@ -1065,71 +1065,76 @@ class SerializationUtil {
// If `str` is not a nullptr after calling `read_var_char_ptr`, it
// indicates that memory has been allocated and must be freed.
- FORCE_INLINE static int read_var_char_ptr(std::string *&str,
+ FORCE_INLINE static E_CODE read_var_char_ptr(std::string *&str,
ByteStream &in) {
- int ret = error_info::E_OK;
+ E_CODE ret = E_CODE::E_OK;
int32_t len = 0;
- int32_t read_len = 0;
+
if (RET_FAIL(read_var_int(len, in))) {
return ret;
+ }
+
+ if (len == storage::NO_STR_TO_READ) {
+ str = nullptr;
+ return ret;
+ }
+
+ size_t read_len = 0;
+ size_t usize = static_cast<size_t>(len);
+ char *tmp_buf = static_cast<char *>(malloc(usize));
+ if (RET_FAIL(
+ in.read_buf(tmp_buf, usize, read_len))) {
+ free(tmp_buf);
+ return ret;
+ } else if (usize != read_len) {
+ free(tmp_buf);
+ ret = E_CODE::E_BUF_NOT_ENOUGH;
} else {
- if (len == storage::NO_STR_TO_READ) {
- str = nullptr;
- return ret;
- } else {
- char *tmp_buf = static_cast<char *>(malloc(len));
- if (RET_FAIL(in.read_buf(tmp_buf, len, read_len))) {
- free(tmp_buf);
- return ret;
- } else if (len != read_len) {
- free(tmp_buf);
- ret = E_BUF_NOT_ENOUGH;
- } else {
- str = new std::string(tmp_buf, len);
- free(tmp_buf);
- }
- }
+ str = new std::string(tmp_buf, usize);
+ free(tmp_buf);
}
return ret;
}
- FORCE_INLINE static int read_var_str(std::string &str, ByteStream &in) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE read_var_str(std::string &str, ByteStream &in) {
+ E_CODE ret = E_CODE::E_OK;
int32_t len = 0;
- int32_t read_len = 0;
if (RET_FAIL(read_var_int(len, in))) {
} else {
- char *tmp_buf = (char *)malloc(len + 1);
+ const auto usize = static_cast<size_t>(len);
+ size_t read_len = 0;
+ char *tmp_buf = static_cast<char *>(malloc(usize + 1));
tmp_buf[len] = '\0';
- if (RET_FAIL(in.read_buf(tmp_buf, len, read_len))) {
- } else if (len != read_len) {
- ret = E_BUF_NOT_ENOUGH;
+ if (RET_FAIL(in.read_buf(tmp_buf, usize, read_len))) {
+ } else if (usize != read_len) {
+ SET_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
} else {
- str = std::string(tmp_buf);
+ str = std::string(tmp_buf, usize);
}
free(tmp_buf);
}
return ret;
}
- FORCE_INLINE static int write_str(const std::string &str, ByteStream &out) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE write_str(const std::string &str, ByteStream &out) {
+ E_CODE ret = error_info::E_OK;
if (RET_FAIL(write_i32((static_cast<int32_t>(str.size())), out))) {
} else if (RET_FAIL(out.write_buf(str.c_str(), str.size()))) {
}
return ret;
}
- FORCE_INLINE static int read_str(std::string &str, ByteStream &in) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE read_str(std::string &str, ByteStream &in) {
+ E_CODE ret = E_CODE::E_OK;
int32_t len = 0;
if (RET_FAIL(read_i32(len, in))) {
} else {
- int32_t read_len = 0;
- char *tmp_buf = static_cast<char *>(malloc(len + 1));
- tmp_buf[len] = '\0';
- if (RET_FAIL(in.read_buf(tmp_buf, len, read_len))) {
- } else if (len != read_len) {
- ret = E_BUF_NOT_ENOUGH;
+ size_t read_len = 0;
+ auto usize = static_cast<size_t>(len);
+ char *tmp_buf = static_cast<char *>(malloc(usize + 1));
+ tmp_buf[usize] = '\0';
+ if (RET_FAIL(in.read_buf(tmp_buf, usize, read_len))) {
+ } else if (usize != read_len) {
+ SET_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
} else {
str = std::string(tmp_buf);
}
@@ -1138,27 +1143,28 @@ class SerializationUtil {
return ret;
}
- FORCE_INLINE static int write_str(const String &str, ByteStream &out) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE write_str(const String &str, ByteStream &out) {
+ E_CODE ret = error_info::E_OK;
if (RET_FAIL(write_i32((static_cast<int32_t>(str.len_)), out))) {
- } else if (RET_FAIL(out.write_buf(str.buf_, str.len_))) {
+ } else if (RET_FAIL(out.write_buf(str.buf_, static_cast<size_t>(str.len_)))) {
}
return ret;
}
- FORCE_INLINE static int read_str(String &str, common::PageArena *pa,
+ FORCE_INLINE static E_CODE read_str(String &str, common::PageArena *pa,
ByteStream &in) {
- int ret = error_info::E_OK;
+ E_CODE ret = E_CODE::E_OK;
int32_t len = 0;
- int32_t read_len = 0;
if (RET_FAIL(read_i32(len, in))) {
} else {
- char *buf = (char *)pa->alloc(len);
+ size_t usize = static_cast<size_t>(len);
+ size_t read_len = 0;
+ char *buf = pa->alloc(usize);
if (IS_NULL(buf)) {
- ret = common::E_OOM;
+ SET_ERR(E_CODE::E_OOM, "read str get nullptr");
} else {
- if (RET_FAIL(in.read_buf(buf, len, read_len))) {
- } else if (len != read_len) {
- ret = E_BUF_NOT_ENOUGH;
+ if (RET_FAIL(in.read_buf(buf, usize, read_len))) {
+ } else if (usize != read_len) {
+ SET_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
} else {
str.buf_ = buf;
str.len_ = len;
@@ -1168,27 +1174,29 @@ class SerializationUtil {
return ret;
}
- FORCE_INLINE static int write_mystring(const String &str, ByteStream &out) {
- int ret = error_info::E_OK;
+ FORCE_INLINE static E_CODE write_mystring(const String &str, ByteStream &out) {
+ E_CODE ret = E_CODE::E_OK;
if (RET_FAIL(write_var_int(str.len_, out))) {
- } else if (RET_FAIL(out.write_buf(str.buf_, str.len_))) {
+ } else if (RET_FAIL(out.write_buf(str.buf_, static_cast<size_t>(str.len_)))) {
}
return ret;
}
- FORCE_INLINE static int read_mystring(String &str, common::PageArena *pa,
+ FORCE_INLINE static E_CODE read_mystring(String &str, common::PageArena *pa,
ByteStream &in) {
- int ret = error_info::E_OK;
+ E_CODE ret = error_info::E_OK;
int32_t len = 0;
- int32_t read_len = 0;
+
if (RET_FAIL(read_var_int(len, in))) {
} else {
- char *buf = (char *)pa->alloc(len);
+ auto usize = static_cast<size_t>(len);
+ char *buf = pa->alloc(usize);
if (IS_NULL(buf)) {
- ret = common::E_OOM;
+ SET_ERR(E_CODE::E_OOM, "read str get nullptr");
} else {
- if (RET_FAIL(in.read_buf(buf, len, read_len))) {
- } else if (len != read_len) {
- ret = E_BUF_NOT_ENOUGH;
+ size_t read_len = 0;
+ if (RET_FAIL(in.read_buf(buf, usize, read_len))) {
+ } else if (usize != read_len) {
+ SET_ERR(E_CODE::E_BUF_NOT_ENOUGH, "")
} else {
str.buf_ = buf;
str.len_ = len;
@@ -1198,7 +1206,7 @@ class SerializationUtil {
return ret;
}
FORCE_INLINE static int write_char(char ch, ByteStream &out) {
- return write_ui8(ch, out);
+ return write_ui8(static_cast<uint8_t>(ch), out);
}
FORCE_INLINE static int read_char(char &ch, ByteStream &in) {
return read_ui8((uint8_t &)ch, in);
@@ -1206,20 +1214,20 @@ class SerializationUtil {
};
FORCE_INLINE bool deserialize_buf_not_enough(int ret) {
- return ret == E_OUT_OF_RANGE || ret == E_PARTIAL_READ;
+ return ret == E_CODE::E_OUT_OF_RANGE || ret == E_CODE::E_PARTIAL_READ;
}
FORCE_INLINE char *get_bytes_from_bytestream(ByteStream &bs) {
if (bs.total_size() == 0) {
return nullptr;
}
- uint32_t size = bs.total_size();
- char *ret_buf = (char *)malloc(size);
+ size_t size = bs.total_size();
+ char *ret_buf = static_cast<char *>(malloc(size));
if (ret_buf == nullptr) {
return nullptr;
}
ByteStream::BufferIterator buf_iter = bs.init_buffer_iterator();
- uint32_t offset = 0;
+ size_t offset = 0;
while (true) {
ByteStream::Buffer buf = buf_iter.get_next_buf();
if (buf.buf_ == nullptr) {
diff --git a/cpp/src/common/allocator/mem_alloc.cc b/cpp/src/common/allocator/mem_alloc.cc
index 705a4fb5..0bf84647 100644
--- a/cpp/src/common/allocator/mem_alloc.cc
+++ b/cpp/src/common/allocator/mem_alloc.cc
@@ -83,12 +83,12 @@ void *mem_alloc(const size_t size, const AllocModID mid) {
}
} else {
if (size > UINT32_MAX - HEADER_SIZE_4B) {
- set_err_info(error_info::E_OOM, "Too large spec to allocate");
+ SET_ERR(error_info::E_OOM, "Too large spec to allocate");
return nullptr;
}
auto *p = static_cast<char *>(malloc(size + HEADER_SIZE_8B));
if (UNLIKELY(p == nullptr)) {
- set_err_info(error_info::E_OOM, "allocate failed");
+ SET_ERR(error_info::E_OOM, "allocate failed");
return nullptr;
} else {
const uint64_t large_size = size;
diff --git a/cpp/src/common/allocator/page_arena.cc b/cpp/src/common/allocator/page_arena.cc
index 9cc9cc00..a53102df 100644
--- a/cpp/src/common/allocator/page_arena.cc
+++ b/cpp/src/common/allocator/page_arena.cc
@@ -22,7 +22,7 @@
namespace common {
-char *PageArena::alloc(uint32_t size) {
+char *PageArena::alloc(size_t size) {
if (LIKELY(size <= page_size_)) {
Page *cur_page = dummy_head_.next_;
if (LIKELY(cur_page != nullptr)) {
diff --git a/cpp/src/common/allocator/page_arena.h b/cpp/src/common/allocator/page_arena.h
index b8053cfb..6fe93589 100644
--- a/cpp/src/common/allocator/page_arena.h
+++ b/cpp/src/common/allocator/page_arena.h
@@ -35,12 +35,12 @@ class PageArena {
base_allocator_(base_allocator),
dummy_head_() {}
~PageArena() { destroy(); }
- void init(uint32_t page_size, AllocModID mid) {
+ void init(size_t page_size, AllocModID mid) {
page_size_ = page_size;
mid_ = mid;
}
- char *alloc(uint32_t size);
+ char *alloc(size_t size);
FORCE_INLINE void destroy() { reset(); }
void reset();
@@ -91,7 +91,7 @@ class PageArena {
};
private:
- uint32_t page_size_;
+ size_t page_size_;
AllocModID mid_;
BaseAllocator &base_allocator_;
Page dummy_head_;
diff --git a/cpp/src/common/container/bit_map.h b/cpp/src/common/container/bit_map.h
index 70380d5f..6e76b781 100644
--- a/cpp/src/common/container/bit_map.h
+++ b/cpp/src/common/container/bit_map.h
@@ -41,7 +41,7 @@ class BitMap {
uint32_t offset = index >> 3;
ASSERT(offset < size_);
- char *start_addr = bitmap_ + offset;
+ uint8_t *start_addr = bitmap_ + offset;
uint8_t bit_mask = get_bit_mask(index);
*start_addr = (*start_addr) | (bit_mask);
}
@@ -50,7 +50,7 @@ class BitMap {
uint32_t offset = index >> 3;
ASSERT(offset < size_);
- char *start_addr = bitmap_ + offset;
+ uint8_t *start_addr = bitmap_ + offset;
uint8_t bit_mask = get_bit_mask(index);
*start_addr = (*start_addr) & (~bit_mask);
}
@@ -59,22 +59,24 @@ class BitMap {
uint32_t offset = index >> 3;
ASSERT(offset < size_);
- char *start_addr = bitmap_ + offset;
+ uint8_t *start_addr = bitmap_ + offset;
uint8_t bit_mask = get_bit_mask(index);
return (*start_addr & bit_mask);
}
FORCE_INLINE uint32_t get_size() { return size_; }
- FORCE_INLINE char *get_bitmap() { return bitmap_; } // for debug
+ FORCE_INLINE char *get_bitmap() {
+ return reinterpret_cast<char *>(bitmap_);
+ } // for debug
private:
FORCE_INLINE uint8_t get_bit_mask(uint32_t index) {
- return 1 << (index & 7);
+ return static_cast<uint8_t>(1 << (index & 7));
}
private:
- char *bitmap_;
+ uint8_t *bitmap_;
uint32_t size_;
bool init_as_zero_;
};
diff --git a/cpp/src/common/container/byte_buffer.h b/cpp/src/common/container/byte_buffer.h
index 967d3640..af77f134 100644
--- a/cpp/src/common/container/byte_buffer.h
+++ b/cpp/src/common/container/byte_buffer.h
@@ -100,6 +100,7 @@ class ByteBuffer {
// for fixed len value
FORCE_INLINE char *read(uint32_t offset, uint32_t len) {
+ UNUSED(len);
ASSERT((offset + len) <= real_data_size_);
char *p = &data_[offset];
return p;
diff --git a/cpp/src/common/container/list.h b/cpp/src/common/container/list.h
index ac566227..c3a68daa 100644
--- a/cpp/src/common/container/list.h
+++ b/cpp/src/common/container/list.h
@@ -21,7 +21,9 @@
#define COMMON_CONTAINER_LIST_H
#include "common/allocator/page_arena.h"
-#include "common/error_info/errno_define.h"
+#include "common/error_info/error_info.h"
+
+using namespace error_info;
namespace common {
@@ -58,7 +60,7 @@ class SimpleList {
Iterator() : cur_(INVALID_NODE_PTR) {}
T &get() { return cur_->data_; }
FORCE_INLINE bool is_inited() const { return cur_ != INVALID_NODE_PTR; }
- FORCE_INLINE Iterator &operator++(int n) {
+ FORCE_INLINE Iterator &operator++(int) {
if (LIKELY(cur_ != nullptr)) {
cur_ = cur_->next_;
}
@@ -90,7 +92,7 @@ class SimpleList {
int push_back(const T &data) {
void *buf = page_arena_->alloc(sizeof(SimpleListNode));
if (UNLIKELY(buf == nullptr)) {
- return common::E_OOM;
+ return E_CODE::E_OOM;
}
SimpleListNode *node = new (buf) SimpleListNode(data);
if (head_ == nullptr) {
@@ -112,7 +114,7 @@ class SimpleList {
int remove(T target) {
if (head_ == nullptr) {
- return common::E_NOT_EXIST;
+ return E_NOT_EXIST;
}
SimpleListNode *prev = head_;
SimpleListNode *cur = head_->next_;
@@ -120,7 +122,7 @@ class SimpleList {
cur = cur->next_;
}
if (!cur) {
- return common::E_NOT_EXIST;
+ return E_NOT_EXIST;
}
prev->next_ = cur->next_;
size_--;
diff --git a/cpp/src/common/container/murmur_hash3.h b/cpp/src/common/container/murmur_hash3.h
index 1e2bf44b..f8af03c8 100644
--- a/cpp/src/common/container/murmur_hash3.h
+++ b/cpp/src/common/container/murmur_hash3.h
@@ -33,39 +33,42 @@ namespace common {
class Murmur128Hash {
public:
FORCE_INLINE static int32_t hash(int32_t value, uint32_t seed) {
- return inner_hash(reinterpret_cast<const char *>(&value), 4, seed);
+ return static_cast<int32_t>(
+ inner_hash(reinterpret_cast<const char *>(&value), 4, seed));
}
FORCE_INLINE static int32_t hash(int64_t value, uint32_t seed) {
- return inner_hash(reinterpret_cast<const char *>(&value), 8, seed);
+ return static_cast<int32_t>(
+ inner_hash(reinterpret_cast<const char *>(&value), 8, seed));
}
FORCE_INLINE static int32_t hash(double value, uint32_t seed) {
- return inner_hash(reinterpret_cast<const char *>(&value), 8, seed);
+ return static_cast<int32_t>(
+ inner_hash(reinterpret_cast<const char *>(&value), 8, seed));
}
FORCE_INLINE static int32_t hash(std::string &value, uint32_t seed) {
- return inner_hash(value.data(), static_cast<uint32_t>(value.size()),
- seed);
+ return static_cast<int32_t>(inner_hash(
+ value.data(), static_cast<int32_t>(value.size()), seed));
}
FORCE_INLINE static int32_t hash(const common::String &buf, int32_t seed) {
- return inner_hash(buf.buf_, buf.len_ - 1, seed);
+ return static_cast<int32_t>(inner_hash(buf.buf_, buf.len_ - 1, seed));
}
private:
FORCE_INLINE static int64_t rotl64(int64_t v, int n) {
- uint64_t uv = (uint64_t)v;
- return ((uv << n) | (uv >> (64 - n)));
+ auto uv = static_cast<uint64_t>(v);
+ return static_cast<int64_t>((uv << n) | (uv >> (64 - n)));
}
FORCE_INLINE static int64_t fmix(int64_t k) {
- uint64_t uk = (uint64_t)k;
+ auto uk = static_cast<uint64_t>(k);
uk ^= uk >> 33;
uk *= 0xff51afd7ed558ccdL;
uk ^= uk >> 33;
uk *= 0xc4ceb9fe1a85ec53L;
uk ^= uk >> 33;
- return (int64_t)uk;
+ return static_cast<int64_t>(uk);
}
static int64_t get_block(const char *buf, int32_t index);
static int64_t inner_hash(const char *buf, int32_t len, int64_t seed);
diff --git a/cpp/src/common/datatype/value.h b/cpp/src/common/datatype/value.h
index 29fd5706..54e8a5d6 100644
--- a/cpp/src/common/datatype/value.h
+++ b/cpp/src/common/datatype/value.h
@@ -30,6 +30,7 @@
#include "common/logger/elog.h"
#include "utils/db_utils.h"
+using namespace error_info;
namespace common {
struct Value {
@@ -191,9 +192,7 @@ FORCE_INLINE std::string value_to_string(Value *value) {
// return true if cast succ.
template <typename T>
-FORCE_INLINE int get_typed_data_from_value(Value *value, T &ret_data) {
- return E_OK;
-}
+FORCE_INLINE int get_typed_data_from_value(Value *value, T &ret_data);
template <>
FORCE_INLINE int get_typed_data_from_value<bool>(Value *value, bool &ret_data) {
diff --git a/cpp/src/common/device_id.h b/cpp/src/common/device_id.h
index d1b0eaf5..b4913177 100644
--- a/cpp/src/common/device_id.h
+++ b/cpp/src/common/device_id.h
@@ -29,7 +29,6 @@
#include <vector>
#include "common/allocator/byte_stream.h"
-#include "common/error_info/errno_define.h"
#include "constant/tsfile_constant.h"
#include "parser/path_nodes_generator.h"
@@ -37,23 +36,15 @@ 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 false; }
- 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_;
+ virtual int serialize(common::ByteStream& write_stream);
+ virtual int deserialize(common::ByteStream& read_stream);
+ virtual std::string get_table_name();
+ virtual size_t segment_num();
+ virtual const std::vector<std::string*>& get_segments() const;
+ virtual std::string get_device_name() const;
+ virtual bool operator<(const IDeviceID& other) const;
+ virtual bool operator==(const IDeviceID& other) const;
+ virtual bool operator!=(const IDeviceID& other) const;
};
struct IDeviceIDComparator {
@@ -112,8 +103,8 @@ class StringArrayDeviceID : public IDeviceID {
};
int serialize(common::ByteStream& write_stream) override {
- int ret = error_info::E_OK;
- if (RET_FAIL(common::SerializationUtil::write_var_uint(segment_num(),
+ int ret = E_OK;
+ if (RET_FAIL(common::SerializationUtil::write_var_uint(static_cast<uint32_t>(segment_num()),
write_stream))) {
return ret;
}
@@ -157,13 +148,13 @@ class StringArrayDeviceID : public IDeviceID {
return segments_.empty() ? "" : *segments_[0];
}
- int segment_num() override { return static_cast<int>(segments_.size()); }
+ size_t segment_num() override { return segments_.size(); }
const std::vector<std::string*>& get_segments() const override {
return segments_;
}
- bool operator<(const IDeviceID& other) override {
+ bool operator<(const IDeviceID& other) const override {
auto other_segments = other.get_segments();
return std::lexicographical_compare(
segments_.begin(), segments_.end(), other_segments.begin(),
@@ -176,7 +167,7 @@ class StringArrayDeviceID : public IDeviceID {
});
}
- bool operator==(const IDeviceID& other) override {
+ bool operator==(const IDeviceID& other) const override {
auto other_segments = other.get_segments();
return (segments_.size() == other_segments.size()) &&
std::equal(segments_.begin(), segments_.end(),
@@ -188,7 +179,7 @@ class StringArrayDeviceID : public IDeviceID {
});
}
- bool operator!=(const IDeviceID& other) override {
+ bool operator!=(const IDeviceID& other) const override {
return !(*this == other);
}
diff --git a/cpp/src/common/error_info/error_define.inc b/cpp/src/common/error_info/error_define.inc
index 2326a960..c0b76b63 100644
--- a/cpp/src/common/error_info/error_define.inc
+++ b/cpp/src/common/error_info/error_define.inc
@@ -23,4 +23,18 @@ ERRNO(E_OK, 0, "success")
ERRNO(E_OOM, 1, "out of memory")
ERRNO(E_PARTIAL_READ, 2, "partial read")
ERRNO(E_OUT_OF_RANGE, 3, "out of range")
-ERRNO(E_BUF_NOT_ENOUGH, 4, "buf not enough")
\ No newline at end of file
+ERRNO(E_BUF_NOT_ENOUGH, 4, "buf not enough")
+ERRNO(E_OVERFLOW, 5, "overflow")
+ERRNO(E_NOT_EXIST, 6, "not exist")
+// COMPRESSION
+ERRNO(E_COMPRESS_ERR, 10, "compression error")
+
+// DATATYPE
+ERRNO(E_TYPE_NOT_MATCH, 20, "type not match")
+ERRNO(E_INVALID_ARG, 21, "invalid argument")
+
+// TSIFLE
+ERRNO(E_NOT_SUPPORT, 30, "not supported")
+
+// TSFILE SCHEMA
+ERRNO(E_TABLE_NOT_EXIST, 40, "table not exist")
\ No newline at end of file
diff --git a/cpp/src/common/error_info/error_info.h b/cpp/src/common/error_info/error_info.h
index 2bf4cd4e..b1e32503 100644
--- a/cpp/src/common/error_info/error_info.h
+++ b/cpp/src/common/error_info/error_info.h
@@ -23,7 +23,6 @@
#include <string>
namespace error_info {
-
enum E_CODE {
#define ERRNO(name, val, desc) name = val,
#include "error_define.inc"
@@ -44,6 +43,13 @@ void set_err_info(int error, const std::string& msg, const std::string& file,
__FUNCTION__); \
return (code); \
} while (0);
+
+#define SET_ERR(code, msg) \
+ do { \
+ ::error_info::set_err_info((code), msg, __FILE__, __LINE__, \
+ __FUNCTION__); \
+ } while (0);
+
} // namespace error_info
#endif
\ No newline at end of file
diff --git a/cpp/src/common/global.cc b/cpp/src/common/global.cc
index 32b93712..78423232 100644
--- a/cpp/src/common/global.cc
+++ b/cpp/src/common/global.cc
@@ -26,6 +26,7 @@
#include "utils/injection.h"
+using namespace error_info;
namespace common {
ColumnSchema g_time_column_schema;
diff --git a/cpp/src/common/global.h b/cpp/src/common/global.h
index 3f331460..d67e4c25 100644
--- a/cpp/src/common/global.h
+++ b/cpp/src/common/global.h
@@ -24,6 +24,9 @@
#include "common/allocator/byte_stream.h"
#include "common/config/config.h"
+
+using namespace error_info;
+
namespace common {
extern ConfigValue g_config_value_;
@@ -58,10 +61,9 @@ FORCE_INLINE int set_global_time_compression(uint8_t compression) {
}
FORCE_INLINE int set_datatype_encoding(uint8_t data_type, uint8_t encoding) {
- int code = E_OK;
- TSDataType dtype = static_cast<TSDataType>(data_type);
+ auto dtype = static_cast<TSDataType>(data_type);
ASSERT(dtype >= BOOLEAN && dtype <= STRING);
- TSEncoding encoding_type = static_cast<TSEncoding>(encoding);
+ auto encoding_type = static_cast<TSEncoding>(encoding);
ASSERT(encoding >= PLAIN && encoding <= FREQ);
switch (dtype) {
case BOOLEAN:
diff --git a/cpp/src/common/statistic.h b/cpp/src/common/statistic.h
index 9b3ff5cf..d7f3bd71 100644
--- a/cpp/src/common/statistic.h
+++ b/cpp/src/common/statistic.h
@@ -21,6 +21,7 @@
#define COMMON_STATISTIC_H
#include <inttypes.h>
+#include <sys/stat.h>
#include <sstream>
@@ -140,17 +141,18 @@ class Statistic {
virtual int serialize_to(common::ByteStream &out) {
int ret = error_info::E_OK;
- if (RET_FAIL(common::SerializationUtil::write_var_uint(count_, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(start_time_,
+ if (RET_FAIL(common::SerializationUtil::write_var_uint((uint32_t)count_, out))) {
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)start_time_,
out))) {
} else if (RET_FAIL(
- common::SerializationUtil::write_ui64(end_time_, out))) {
+ common::SerializationUtil::write_ui64((uint64_t)end_time_, out))) {
} else if (RET_FAIL(serialize_typed_stat(out))) {
}
return ret;
}
virtual int serialize_typed_stat(common::ByteStream &out) {
ASSERT(false);
+ UNUSED(out);
return 0;
}
@@ -172,22 +174,26 @@ class Statistic {
}
virtual int deserialize_typed_stat(common::ByteStream &in) {
ASSERT(false);
+ UNUSED(in);
return 0;
}
virtual int merge_with(Statistic *that) {
ASSERT(false);
+ UNUSED(that);
return 0;
}
virtual int deep_copy_from(Statistic *stat) {
ASSERT(false);
+ UNUSED(stat);
return 0;
}
virtual common::TSDataType get_type() {
ASSERT(false);
+ UNUSED(stat);
return common::INVALID_DATATYPE;
}
virtual std::string to_string() const {
- return std::string("UNTYPED_STATISTIC");
+ return {"UNTYPED_STATISTIC"};
}
public:
@@ -199,11 +205,11 @@ class Statistic {
#define MERGE_BOOL_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return E_CODE::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return E_CODE::E_TYPE_NOT_MATCH; \
} \
if (UNLIKELY(typed_stat->count_ == 0)) { \
return error_info::E_OK; \
@@ -233,11 +239,11 @@ class Statistic {
#define MERGE_NUM_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return E_CODE::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return E_CODE::E_TYPE_NOT_MATCH; \
} \
if (UNLIKELY(typed_stat->count_ == 0)) { \
return error_info::E_OK; \
@@ -271,11 +277,11 @@ class Statistic {
#define MERGE_STRING_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return error_info::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return error_info::E_TYPE_NOT_MATCH; \
} \
if (UNLIKELY(typed_stat->count_ == 0)) { \
return error_info::E_OK; \
@@ -307,11 +313,11 @@ class Statistic {
#define MERGE_TIME_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return error_info::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return error_info::E_TYPE_NOT_MATCH; \
} \
if (UNLIKELY(typed_stat->count_ == 0)) { \
return error_info::E_OK; \
@@ -335,11 +341,11 @@ class Statistic {
#define DEEP_COPY_BOOL_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return E_CODE::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return E_CODE::E_TYPE_NOT_MATCH; \
} \
count_ = typed_stat->count_; \
start_time_ = typed_stat->start_time_; \
@@ -353,11 +359,11 @@ class Statistic {
#define DEEP_COPY_NUM_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return error_info::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return error_info::E_TYPE_NOT_MATCH; \
} \
count_ = typed_stat->count_; \
start_time_ = typed_stat->start_time_; \
@@ -373,11 +379,11 @@ class Statistic {
#define DEEP_COPY_STRING_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return error_info::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return error_info::E_TYPE_NOT_MATCH; \
} \
count_ = typed_stat->count_; \
start_time_ = typed_stat->start_time_; \
@@ -392,11 +398,11 @@ class Statistic {
#define DEEP_COPY_TIME_STAT_FROM(StatType, untyped_stat) \
do { \
if (UNLIKELY(untyped_stat == nullptr)) { \
- return common::E_INVALID_ARG; \
+ return error_info::E_INVALID_ARG; \
} \
StatType *typed_stat = (StatType *)(untyped_stat); \
if (UNLIKELY(typed_stat == nullptr)) { \
- return common::E_TYPE_NOT_MATCH; \
+ return error_info::E_TYPE_NOT_MATCH; \
} \
count_ = typed_stat->count_; \
start_time_ = typed_stat->start_time_; \
@@ -440,7 +446,7 @@ class BooleanStatistic : public Statistic {
out))) {
} else if (RET_FAIL(common::SerializationUtil::write_ui8(
last_value_ ? 1 : 0, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(sum_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)sum_value_,
out))) {
}
return ret;
@@ -512,14 +518,14 @@ class Int32Statistic : public Statistic {
int serialize_typed_stat(common::ByteStream &out) {
int ret = error_info::E_OK;
- if (RET_FAIL(common::SerializationUtil::write_ui32(min_value_, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui32(max_value_,
+ if (RET_FAIL(common::SerializationUtil::write_ui32((uint32_t)min_value_, out))) {
+ } else if (RET_FAIL(common::SerializationUtil::write_ui32((uint32_t)max_value_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui32(first_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui32((uint32_t)first_value_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui32(last_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui32((uint32_t)last_value_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(sum_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)sum_value_,
out))) {
}
return ret;
@@ -608,12 +614,12 @@ class Int64Statistic : public Statistic {
int serialize_typed_stat(common::ByteStream &out) {
int ret = error_info::E_OK;
- if (RET_FAIL(common::SerializationUtil::write_ui64(min_value_, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(max_value_,
+ if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)min_value_, out))) {
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)max_value_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(first_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)first_value_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_ui64(last_value_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui64((uint64_t)last_value_,
out))) {
} else if (RET_FAIL(common::SerializationUtil::write_double(sum_value_,
out))) {
@@ -839,8 +845,14 @@ class TimeStatistic : public Statistic {
FORCE_INLINE common::TSDataType get_type() { return common::VECTOR; }
- int serialize_typed_stat(common::ByteStream &out) { return error_info::E_OK; }
- int deserialize_typed_stat(common::ByteStream &in) { return error_info::E_OK; }
+ int serialize_typed_stat(common::ByteStream &out) {
+ UNUSED(out);
+ return error_info::E_OK;
+ }
+ int deserialize_typed_stat(common::ByteStream &in) {
+ UNUSED(in);
+ return error_info::E_OK;
+ }
int merge_with(Statistic *stat) {
MERGE_TIME_STAT_FROM(TimeStatistic, stat);
}
diff --git a/cpp/src/common/tsblock/tsblock.cc b/cpp/src/common/tsblock/tsblock.cc
index 8b93a501..256727ba 100644
--- a/cpp/src/common/tsblock/tsblock.cc
+++ b/cpp/src/common/tsblock/tsblock.cc
@@ -38,8 +38,7 @@ int TsBlock::init() {
// max_row_count_ given, calculated with max_row_count_
capacity_ = row_size * max_row_count_;
}
- int colnum = tuple_desc_->get_column_count();
- for (int i = 0; i < colnum; ++i) {
+ for (auto i = 0; i < tuple_desc_->get_column_count(); ++i) {
ret = build_vector(tuple_desc_->get_column_type(i), max_row_count_);
if (ret != 0) {
return ret;
diff --git a/cpp/src/common/tsblock/tsblock.h b/cpp/src/common/tsblock/tsblock.h
index 1a19d7e9..c596e394 100644
--- a/cpp/src/common/tsblock/tsblock.h
+++ b/cpp/src/common/tsblock/tsblock.h
@@ -19,15 +19,13 @@
#ifndef COMMON_TSBLOCK_TSBLOCK_H
#define COMMON_TSBLOCK_TSBLOCK_H
-#include <stdint.h>
+#include <cstdint>
#include "common/allocator/byte_stream.h"
#include "common/container/byte_buffer.h"
#include "common/global.h"
#include "common/logger/elog.h"
#include "tuple_desc.h"
-#include "vector/fixed_length_vector.h"
-#include "vector/variable_length_vector.h"
#include "vector/vector.h"
namespace common {
@@ -51,10 +49,9 @@ class TsBlock {
tuple_desc_(tupledesc) {}
~TsBlock() {
- int size = vectors_.size();
- for (int i = 0; i < size; ++i) {
- delete vectors_[i];
- vectors_[i] = nullptr;
+ for (auto & vector : vectors_) {
+ delete vector;
+ vector = nullptr;
}
}
@@ -65,7 +62,7 @@ class TsBlock {
FORCE_INLINE Vector *get_vector(uint32_t index) { return vectors_[index]; }
FORCE_INLINE uint32_t get_column_count() const {
- return tuple_desc_->get_column_count();
+ return static_cast<uint32_t>(tuple_desc_->get_column_count());
}
FORCE_INLINE uint32_t get_max_row_count() const { return max_row_count_; }
@@ -76,18 +73,6 @@ class TsBlock {
capacity_ += extend_size;
}
- // need to call flush_row_count after using colappender
- FORCE_INLINE int flush_row_count(uint32_t row_count) {
- int errnum = E_OK;
- if (row_count_ == 0) {
- row_count_ = row_count;
- } else if (row_count_ != row_count) {
- LOGE("Inconsistent number of rows in two columns");
- errnum = E_TSBLOCK_DATA_INCONSISTENCY;
- }
- return errnum;
- }
-
FORCE_INLINE void fill_trailling_nulls() {
for (uint32_t i = 0; i < get_column_count(); ++i) {
for (uint32_t j = vectors_[i]->get_row_num(); j < row_count_; ++j) {
@@ -97,9 +82,8 @@ class TsBlock {
}
FORCE_INLINE void reset() {
- int size = vectors_.size();
- for (int i = 0; i < size; ++i) {
- vectors_[i]->reset();
+ for (const auto & vector : vectors_) {
+ vector->reset();
}
row_count_ = 0;
}
@@ -133,7 +117,7 @@ class TsBlock {
uint32_t row_count_; // real row count
uint32_t max_row_count_;
- common::BitMap select_list_;
+ // common::BitMap select_list_;
TupleDesc *tuple_desc_;
std::vector<Vector *> vectors_;
};
@@ -141,7 +125,7 @@ class TsBlock {
class RowAppender {
public:
explicit RowAppender(TsBlock *tsblock) : tsblock_(tsblock) {}
- ~RowAppender() {}
+ ~RowAppender() = default;
// todo:(yanghao) maybe need to consider select-list
FORCE_INLINE bool add_row() {
@@ -181,7 +165,7 @@ class ColAppender {
vec_ = tsblock_->vectors_[column_index];
}
- ~ColAppender() {}
+ ~ColAppender() = default;
// todo:(yanghao) maybe need to consider select-list
FORCE_INLINE bool add_row() {
@@ -200,8 +184,8 @@ class ColAppender {
FORCE_INLINE void append_null() { vec_->set_null(column_row_count_ - 1); }
- FORCE_INLINE uint32_t get_col_row_count() { return column_row_count_; }
- FORCE_INLINE uint32_t get_column_index() { return column_index_; }
+ FORCE_INLINE uint32_t get_col_row_count() const { return column_row_count_; }
+ FORCE_INLINE uint32_t get_column_index() const { return column_index_; }
FORCE_INLINE int fill_null(uint32_t end_index) {
while (column_row_count_ < end_index) {
if (!add_row()) {
@@ -234,16 +218,16 @@ class ColAppender {
class RowIterator {
public:
explicit RowIterator(TsBlock *tsblock) : tsblock_(tsblock), row_id_(0) {
- column_count_ = tsblock_->tuple_desc_->get_column_count();
+ column_count_ = static_cast<uint32_t>(tsblock_->tuple_desc_->get_column_count());
}
- ~RowIterator() {}
+ ~RowIterator() = default;
FORCE_INLINE bool end() { return row_id_ >= tsblock_->row_count_; }
FORCE_INLINE bool has_next() { return row_id_ < tsblock_->row_count_; }
- FORCE_INLINE uint32_t get_column_count() { return column_count_; }
+ FORCE_INLINE uint32_t get_column_count() const { return column_count_; }
FORCE_INLINE TSDataType get_data_type(uint32_t column_index) {
ASSERT(column_index < column_count_);
@@ -301,7 +285,7 @@ class ColIterator {
FORCE_INLINE char *read(uint32_t *len) { return vec_->read(len); }
- FORCE_INLINE uint32_t get_column_index() { return column_index_; }
+ FORCE_INLINE uint32_t get_column_index() const { return column_index_; }
private:
uint32_t column_index_;
diff --git a/cpp/src/common/tsblock/tuple_desc.cc b/cpp/src/common/tsblock/tuple_desc.cc
index be0abf71..617ed012 100644
--- a/cpp/src/common/tsblock/tuple_desc.cc
+++ b/cpp/src/common/tsblock/tuple_desc.cc
@@ -20,7 +20,7 @@
namespace common {
uint32_t TupleDesc::get_single_row_len(int *erro_code) {
- int size = get_column_count();
+ size_t size = get_column_count();
int total_len = 0;
for (int i = 0; i < size; ++i) {
switch (column_list_[i].data_type_) {
diff --git a/cpp/src/common/tsblock/tuple_desc.h b/cpp/src/common/tsblock/tuple_desc.h
index 880f3837..b07efec0 100644
--- a/cpp/src/common/tsblock/tuple_desc.h
+++ b/cpp/src/common/tsblock/tuple_desc.h
@@ -53,7 +53,7 @@ class TupleDesc {
column_list_.push_back(schema);
}
- FORCE_INLINE uint32_t get_column_count() const {
+ FORCE_INLINE size_t get_column_count() const {
return column_list_.size();
}
diff --git a/cpp/src/common/tsfile_common.h b/cpp/src/common/tsfile_common.h
index 484a97d1..321188ec 100644
--- a/cpp/src/common/tsfile_common.h
+++ b/cpp/src/common/tsfile_common.h
@@ -20,12 +20,9 @@
#ifndef COMMON_TSFILE_COMMON_H
#define COMMON_TSFILE_COMMON_H
-#include <cstring>
-#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
-#include <utility>
#include "common/allocator/my_string.h"
#include "common/allocator/page_arena.h"
@@ -83,7 +80,7 @@ struct PageHeader {
} else if (deserialize_stat) {
statistic_ = StatisticFactory::alloc_statistic(data_type);
if (IS_NULL(statistic_)) {
- return common::E_OOM;
+ return E_OOM;
} else if (RET_FAIL(statistic_->deserialize_from(in))) {
}
}
@@ -139,11 +136,11 @@ struct ChunkHeader {
measurement_name_, out))) {
} else if (RET_FAIL(common::SerializationUtil::write_var_uint(
data_size_, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_char(data_type_,
+ } else if (RET_FAIL(common::SerializationUtil::write_ui8(data_type_,
out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_char(
+ } else if (RET_FAIL(common::SerializationUtil::write_ui8(
compression_type_, out))) {
- } else if (RET_FAIL(common::SerializationUtil::write_char(
+ } else if (RET_FAIL(common::SerializationUtil::write_ui8(
encoding_type_, out))) {
}
return ret;
@@ -163,21 +160,13 @@ struct ChunkHeader {
} else if (RET_FAIL(common::SerializationUtil::read_char(
(char &)encoding_type_, in))) {
} else {
- serialized_size_ = in.get_mark_len();
+ // There will meet data shortcut.
+ serialized_size_ = static_cast<int32_t>(in.get_mark_len());
}
return ret;
}
#ifndef NDEBUG
- friend std::ostream &operator<<(std::ostream &os, const ChunkHeader &h) {
- os << "{measurement_name=" << h.measurement_name_
- << ", data_size=" << h.data_size_ << ", data_type=" << h.data_type_
- << ", compression_type=" << h.compression_type_
- << ", encoding_type=" << h.encoding_type_
- << ", num_of_pages=" << h.num_of_pages_
- << ", serialized_size=" << h.serialized_size_
- << ", chunk_type=" << (int)h.chunk_type_ << "}";
- return os;
- }
+
#endif
std::string measurement_name_;
@@ -237,7 +226,7 @@ struct ChunkMeta {
statistic_ =
StatisticFactory::alloc_statistic_with_pa(data_type_, pa);
if (IS_NULL(statistic_)) {
- return common::E_OOM;
+ return E_OOM;
}
clone_statistic_from(that.statistic_);
}
@@ -262,7 +251,7 @@ struct ChunkMeta {
statistic_ =
StatisticFactory::alloc_statistic_with_pa(data_type_, pa);
if (IS_NULL(statistic_)) {
- ret = common::E_OOM;
+ ret = E_OOM;
} else {
ret = statistic_->deserialize_from(in);
}
@@ -400,7 +389,7 @@ class TimeseriesIndex : public ITimeseriesIndex {
}
statistic_ = StatisticFactory::alloc_statistic(data_type);
if (IS_NULL(statistic_)) {
- return common::E_OOM;
+ return E_OOM;
}
statistic_->reset();
return error_info::E_OK;
@@ -443,13 +432,13 @@ class TimeseriesIndex : public ITimeseriesIndex {
} else if (nullptr ==
(statistic_ = StatisticFactory::alloc_statistic_with_pa(
data_type_, pa))) {
- ret = common::E_OOM;
+ ret = E_OOM;
} else if (RET_FAIL(statistic_->deserialize_from(in))) {
} else {
statistic_from_pa_ = true;
void *chunk_meta_list_buf = pa->alloc(sizeof(*chunk_meta_list_));
if (IS_NULL(chunk_meta_list_buf)) {
- return common::E_OOM;
+ return E_OOM;
}
const bool deserialize_chunk_meta_statistic =
(timeseries_meta_type_ & 0x3F); // TODO
@@ -460,7 +449,7 @@ class TimeseriesIndex : public ITimeseriesIndex {
in.read_pos() < start_pos + chunk_meta_list_data_size_) {
void *cm_buf = pa->alloc(sizeof(ChunkMeta));
if (IS_NULL(cm_buf)) {
- ret = common::E_OOM;
+ ret = E_OOM;
} else {
ChunkMeta *cm = new (cm_buf) ChunkMeta;
cm->measurement_name_.shallow_copy_from(
@@ -486,7 +475,7 @@ class TimeseriesIndex : public ITimeseriesIndex {
statistic_ = StatisticFactory::alloc_statistic_with_pa(data_type_, pa);
if (IS_NULL(statistic_)) {
- return common::E_OOM;
+ return E_OOM;
}
clone_statistic(that.statistic_, this->statistic_, data_type_);
statistic_from_pa_ = true;
@@ -498,7 +487,7 @@ class TimeseriesIndex : public ITimeseriesIndex {
if (that.chunk_meta_list_ != nullptr) {
void *buf = pa->alloc(sizeof(*chunk_meta_list_));
if (IS_NULL(buf)) {
- return common::E_OOM;
+ return E_OOM;
}
chunk_meta_list_ = new (buf) common::SimpleList<ChunkMeta *>(pa);
common::SimpleList<ChunkMeta *>::Iterator it;
@@ -507,7 +496,7 @@ class TimeseriesIndex : public ITimeseriesIndex {
ChunkMeta *cm = it.get();
void *cm_buf = pa->alloc(sizeof(ChunkMeta));
if (IS_NULL(cm_buf)) {
- return common::E_OOM;
+ return E_OOM;
} else {
ChunkMeta *my_cm = new (cm_buf) ChunkMeta;
if (RET_FAIL(my_cm->clone_from(*cm, pa))) {
@@ -731,18 +720,14 @@ struct IMetaIndexEntry {
IMetaIndexEntry() = default;
virtual ~IMetaIndexEntry() = default;
- virtual int serialize_to(common::ByteStream &out) { return error_info::E_OK; }
+ virtual int serialize_to(common::ByteStream &out);
virtual int deserialize_from(common::ByteStream &out,
- common::PageArena *pa) {
- return common::E_NOT_SUPPORT;
- }
+ common::PageArena *pa);
virtual int64_t get_offset() const = 0;
- virtual bool is_device_level() const { return false; }
- virtual std::shared_ptr<IComparable> get_compare_key() const {
- return std::shared_ptr<IComparable>();
- }
- virtual common::String get_name() const { return {}; }
- virtual std::shared_ptr<IDeviceID> get_device_id() const { return nullptr; }
+ virtual bool is_device_level() const = 0;
+ virtual std::shared_ptr<IComparable> get_compare_key() const;
+ virtual common::String get_name() const;
+ virtual std::shared_ptr<IDeviceID> get_device_id() const;
virtual std::shared_ptr<IMetaIndexEntry> clone(common::PageArena *pa) = 0;
#ifndef NDEBUG
virtual void print(std::ostream &os) const {}
@@ -946,7 +931,7 @@ struct MetaIndexNode {
return ret;
}
- int deserialize_from(const char *buf, int len) {
+ int deserialize_from(char *buf, int len) {
common::ByteStream bs;
bs.wrap_from(buf, len);
return deserialize_from(bs);
@@ -961,7 +946,7 @@ struct MetaIndexNode {
for (uint32_t i = 0; i < children_size && IS_SUCC(ret); i++) {
void *entry_buf = pa_->alloc(sizeof(MeasurementMetaIndexEntry));
if (IS_NULL(entry_buf)) {
- return common::E_OOM;
+ return E_OOM;
}
auto entry = new (entry_buf) MeasurementMetaIndexEntry;
@@ -987,7 +972,7 @@ struct MetaIndexNode {
#endif
return ret;
}
- int device_deserialize_from(const char *buf, int len) {
+ int device_deserialize_from(char *buf, int len) {
common::ByteStream bs;
bs.wrap_from(buf, len);
return device_deserialize_from(bs);
@@ -1002,7 +987,7 @@ struct MetaIndexNode {
for (uint32_t i = 0; i < children_size && IS_SUCC(ret); i++) {
void *entry_buf = pa_->alloc(sizeof(DeviceMetaIndexEntry));
if (IS_NULL(entry_buf)) {
- return common::E_OOM;
+ return E_OOM;
}
auto* entry_ptr = new(entry_buf) DeviceMetaIndexEntry();
auto entry = std::shared_ptr<DeviceMetaIndexEntry>(
@@ -1086,7 +1071,7 @@ struct TsFileMeta {
std::map<std::string, std::shared_ptr<MetaIndexNode>>::iterator it =
table_metadata_index_node_map_.find(table_name);
if (it == table_metadata_index_node_map_.end()) {
- return common::E_TABLE_NOT_EXIST;
+ return E_TABLE_NOT_EXIST;
}
ret_node = it->second.get();
return error_info::E_OK;
@@ -1096,7 +1081,7 @@ struct TsFileMeta {
std::shared_ptr<TableSchema> &ret_schema) {
TableSchemasMap::iterator it = table_schemas_.find(table_name);
if (it == table_schemas_.end()) {
- return common::E_TABLE_NOT_EXIST;
+ return E_TABLE_NOT_EXIST;
}
ret_schema = it->second;
return error_info::E_OK;
diff --git a/cpp/src/common/tsfile_mgr.cc b/cpp/src/common/tsfile_mgr.cc
deleted file mode 100644
index 1e06edca..00000000
--- a/cpp/src/common/tsfile_mgr.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.
- */
-
-#include "tsfile_mgr.h"
-
-#include <algorithm> // std::sort
-#include <iomanip>
-#include <iostream>
-
-#include "common/error_info/errno_define.h"
-
-using namespace common;
-
-namespace storage {
-
-TsFileMgr &TsFileMgr::get_instance() {
- static TsFileMgr g_s_tsfile_mgr;
- return g_s_tsfile_mgr;
-}
-
-int TsFileMgr::init() {
- int ret = E_OK;
- return ret;
-}
-
-// used when recover
-int TsFileMgr::add_new_file(const std::string &file_path) {
- int ret = E_OK;
- MutexGuard mg(all_open_files_mutex_);
- // TODO
- return ret;
-}
-
-int TsFileMgr::add_new_file(const FileID &file_id, OpenFile *open_file) {
- MutexGuard mg(all_open_files_mutex_);
- AllOpenFileMapIter find_iter = all_open_files_.find(file_id);
- if (find_iter != all_open_files_.end()) {
- return E_ALREADY_EXIST;
- }
- std::pair<FileID, OpenFile *> pair;
- pair.first = file_id;
- pair.second = open_file;
- std::pair<AllOpenFileMapIter, bool> ins_res = all_open_files_.insert(pair);
- if (!ins_res.second) {
- ASSERT(false);
- }
- version_++;
- return E_OK;
-}
-
-/*
- * Currently, we only allow sequence data writing,
- * So we have only one DataRun returned.
- */
-int TsFileMgr::get_files_for_query(const TsID &ts_id,
- const TimeFilter *time_filter,
- DataRun *ret_data_run,
- int64_t &ret_version) {
- int ret = E_OK;
-
- // Step 1: get all tsfiles that contain this ts_id, store them in tsfile_vec
- std::vector<TimeRangeOpenFilePair> tsfile_vec;
-
- all_open_files_mutex_.lock();
- for (AllOpenFileMapIter iter = all_open_files_.begin();
- iter != all_open_files_.end() && IS_SUCC(ret); iter++) {
- OpenFile *open_file = iter->second;
- TimeRange time_range;
- int tmp_ret = open_file->get_time_range(ts_id, time_range);
- if (tmp_ret == E_OK) {
- if (time_range_stasify(time_filter, time_range)) {
- TimeRangeOpenFilePair pair;
- pair.open_file_ = open_file;
- pair.time_range_ = time_range;
- tsfile_vec.push_back(pair);
- }
- } else if (tmp_ret == E_NOT_EXIST) {
- // continue next
- } else {
- ret = tmp_ret;
- // log_err("get time range for ts_id error, ret=%d, ts_id=%s", ret,
- // ts_id.to_string().c_str());
- }
- } // end for
- ret_version = version_;
- all_open_files_mutex_.unlock();
-
- // Step 2: since we have only one DataRun, sort these tsfiles
- std::sort(tsfile_vec.begin(), tsfile_vec.end(),
- compare_timerange_openfile_pair);
-
- // Step 3: wrap them as DataRun
- for (size_t i = 0; i < tsfile_vec.size() && IS_SUCC(ret); i++) {
- merge_time_range(ret_data_run->time_range_, tsfile_vec[i].time_range_);
- ret = ret_data_run->tsfile_list_.push_back(tsfile_vec[i].open_file_);
- }
- return ret;
-}
-
-bool TsFileMgr::time_range_stasify(const TimeFilter *time_filter,
- const TimeRange &time_range) {
- // TODO
- UNUSED(time_filter);
- UNUSED(time_range);
- return true;
-}
-
-#ifndef NDEBUG
-void TsFileMgr::DEBUG_dump(const char *tag) {
- MutexGuard mg(all_open_files_mutex_);
- AllOpenFileMapIter it;
- std::cout << tag << "Dump TsFileMgr Start" << std::endl;
- int count = 0;
- for (it = all_open_files_.begin(); it != all_open_files_.end(); it++) {
- std::cout << tag << "Dump TsFileMgr:\n [" << std::setw(3)
- << std::setfill(' ') << count << "]\n file_id=" << it->first
- << "\n open_file=" << *it->second;
- }
- std::cout << tag << "Dump TsFileMgr End" << std::endl;
-}
-#endif
-
-} // end namespace storage
\ No newline at end of file
diff --git a/cpp/src/common/tsfile_mgr.h b/cpp/src/common/tsfile_mgr.h
deleted file mode 100644
index 3772769a..00000000
--- a/cpp/src/common/tsfile_mgr.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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_TSFILE_MGR_H
-#define COMMON_TSFILE_MGR_H
-
-#include "common/db_common.h"
-#include "common/mutex/mutex.h"
-#include "reader/scan_iterator.h"
-
-namespace storage {
-
-// TODO use header file instead
-class TimeFilter;
-
-struct TimeRangeOpenFilePair {
- TimeRange time_range_;
- OpenFile *open_file_;
-};
-
-FORCE_INLINE bool compare_timerange_openfile_pair(
- const TimeRangeOpenFilePair &x, const TimeRangeOpenFilePair &y) {
- return x.time_range_.start_time_ < y.time_range_.start_time_;
-}
-
-FORCE_INLINE void merge_time_range(TimeRange &dest, const TimeRange &src) {
- dest.start_time_ = UTIL_MIN(dest.start_time_, src.start_time_);
- dest.end_time_ = UTIL_MAX(dest.end_time_, src.end_time_);
-}
-
-class TsFileMgr {
- public:
- typedef std::map<common::FileID, OpenFile *> AllOpenFileMap;
- typedef AllOpenFileMap::iterator AllOpenFileMapIter;
-
- public:
- TsFileMgr() : all_open_files_(), version_(0), all_open_files_mutex_() {}
- static TsFileMgr &get_instance();
- int init();
- void destroy() { all_open_files_.clear(); }
-
- int add_new_file(const std::string &file_path);
- int add_new_file(const common::FileID &file_id, OpenFile *open_file);
-
- // int get_files_for_query(const common::TsID &ts_id,
- // const TimeFilter &time_filter,
- // common::SimpleList<DataRun> &ret_data_runs);
- int get_files_for_query(const common::TsID &ts_id,
- const TimeFilter *time_filter,
- DataRun *ret_data_run, int64_t &ret_version);
- int64_t get_version() {
- common::MutexGuard mg(all_open_files_mutex_);
- return version_;
- }
-
-#ifndef NDEBUG
- void DEBUG_dump(const char *tag);
-#endif
-
- private:
- bool time_range_stasify(const TimeFilter *time_filter,
- const TimeRange &time_range);
-
- private:
- // Map<file_path, OpenFile>
- AllOpenFileMap all_open_files_;
- int64_t version_;
- common::Mutex all_open_files_mutex_;
-};
-
-#ifndef NDEBUG
-#define DUMP_TSFILE_MGR(tag) TsFileMgr::get_instance().DEBUG_dump(tag)
-#else
-#define DUMP_TSFILE_MGR(tag) (void)
-#endif
-
-} // namespace storage
-
-#endif // COMMON_TSFILE_MGR_H
diff --git a/cpp/src/compress/gzip_compressor.cc b/cpp/src/compress/gzip_compressor.cc
index 4586975a..e9dab9d3 100644
--- a/cpp/src/compress/gzip_compressor.cc
+++ b/cpp/src/compress/gzip_compressor.cc
@@ -19,271 +19,250 @@
#include "gzip_compressor.h"
-using namespace common;
+using namespace common;
+using namespace error_info;
+namespace storage {
+GzipCompressor::GzipCompressor() : compressed_buf() { zstream_valid_ = false; }
-namespace storage
-{
+GzipCompressor::~GzipCompressor() { end_zstream(); }
-GzipCompressor::GzipCompressor() : compressed_buf()
-{
- zstream_valid_ = false;
-}
-
-GzipCompressor::~GzipCompressor()
-{
- end_zstream();
-}
-
-int GzipCompressor::reset()
-{
- int ret = E_OK;
- if (RET_FAIL(end_zstream())) {
- } else if (RET_FAIL(init_zstream())) {
- }
- return ret;
+int GzipCompressor::reset() {
+ int ret = E_CODE::E_OK;
+ if (RET_FAIL(end_zstream())) {
+ } else if (RET_FAIL(init_zstream())) {
+ }
+ return ret;
}
-int GzipCompressor::init_zstream()
-{
- if (zstream_valid_) {
+int GzipCompressor::init_zstream() {
+ if (zstream_valid_) {
+ return E_OK;
+ }
+ compress_stream_.zalloc = (alloc_func)0; // Z_NULL
+ compress_stream_.zfree = (free_func)0;
+ compress_stream_.opaque = (voidpf)0;
+ compress_stream_.next_in = 0;
+ compress_stream_.avail_in = 0;
+ compress_stream_.next_out = 0;
+ compress_stream_.avail_out = 0;
+
+ memset(compressed_buf, 0, DEFLATE_BUFFER_SIZE);
+
+ if (deflateInit2(&compress_stream_, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31,
+ 8, Z_DEFAULT_STRATEGY) != Z_OK) {
+ // log_err("gzip deflateInit2 failed");
+ return E_COMPRESS_ERR;
+ }
+ zstream_valid_ = true;
return E_OK;
- }
- compress_stream_.zalloc = (alloc_func)0; // Z_NULL
- compress_stream_.zfree = (free_func)0;
- compress_stream_.opaque = (voidpf)0;
- compress_stream_.next_in = 0;
- compress_stream_.avail_in = 0;
- compress_stream_.next_out = 0;
- compress_stream_.avail_out = 0;
-
- memset(compressed_buf, 0, DEFLATE_BUFFER_SIZE);
-
- if (deflateInit2(&compress_stream_,
- Z_DEFAULT_COMPRESSION,
- Z_DEFLATED,
- 31,
- 8,
- Z_DEFAULT_STRATEGY) != Z_OK) {
- //log_err("gzip deflateInit2 failed");
- return E_COMPRESS_ERR;
- }
- zstream_valid_ = true;
- return E_OK;
}
-int GzipCompressor::end_zstream()
-{
- if (!zstream_valid_) {
+int GzipCompressor::end_zstream() {
+ if (!zstream_valid_) {
+ return E_OK;
+ }
+ if (deflateEnd(&compress_stream_) != Z_OK) {
+ // log_err("deflateEnd failed");
+ return E_COMPRESS_ERR;
+ }
+ zstream_valid_ = false;
return E_OK;
- }
- if(deflateEnd(&compress_stream_) != Z_OK) {
- //log_err("deflateEnd failed");
- return E_COMPRESS_ERR;
- }
- zstream_valid_ = false;
- return E_OK;
}
int GzipCompressor::compress_into_bytestream(char *uncompressed_buf,
uint32_t uncompressed_buf_len,
- ByteStream &out)
-{
- int ret = Z_OK;
-
- compress_stream_.next_in = (Bytef *)uncompressed_buf;
- compress_stream_.avail_in = uncompressed_buf_len;
- compress_stream_.next_out = (Bytef *)compressed_buf;
- compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
-
- if (uncompressed_buf == nullptr || uncompressed_buf_len == 0) { // no more
- if (compress_stream_.next_out) {
- while (ret != Z_STREAM_END) {
- ret = deflate(&compress_stream_, Z_FINISH);
- if(ret != Z_OK && ret != Z_STREAM_END) {
- //log_err("deflate failed");
- return E_COMPRESS_ERR;
+ ByteStream &out) {
+ int ret = Z_OK;
+
+ compress_stream_.next_in = (Bytef *)uncompressed_buf;
+ compress_stream_.avail_in = uncompressed_buf_len;
+ compress_stream_.next_out = (Bytef *)compressed_buf;
+ compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
+
+ if (uncompressed_buf == nullptr || uncompressed_buf_len == 0) { // no more
+ if (compress_stream_.next_out) {
+ while (ret != Z_STREAM_END) {
+ ret = deflate(&compress_stream_, Z_FINISH);
+ if (ret != Z_OK && ret != Z_STREAM_END) {
+ // log_err("deflate failed");
+ return E_COMPRESS_ERR;
+ }
+ out.write_buf(compressed_buf,
+ DEFLATE_BUFFER_SIZE - compress_stream_.avail_out);
+ compress_stream_.next_out = (Bytef *)compressed_buf;
+ compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
+ }
}
- out.write_buf(compressed_buf, DEFLATE_BUFFER_SIZE -
- compress_stream_.avail_out); compress_stream_.next_out = (Bytef
- *)compressed_buf; compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
- }
+ return E_OK;
}
- return E_OK;
- }
- for (;;) {
- ret = deflate(&compress_stream_, Z_NO_FLUSH);
- if (ret != Z_OK) {
- //log_err("deflate failed");
- return E_COMPRESS_ERR;
- }
+ for (;;) {
+ ret = deflate(&compress_stream_, Z_NO_FLUSH);
+ if (ret != Z_OK) {
+ // log_err("deflate failed");
+ return E_COMPRESS_ERR;
+ }
- if (compress_stream_.avail_in == 0) { // current input data are all
- out.write_buf(compressed_buf, DEFLATE_BUFFER_SIZE -
- compress_stream_.avail_out); compress_stream_.next_out = (Bytef
- *)compressed_buf; compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
- break;
- }
- else if (compress_stream_.avail_out == 0) { // no more space for output
- out.write_buf(compressed_buf, DEFLATE_BUFFER_SIZE);
- compress_stream_.next_out = (Bytef *)compressed_buf;
- compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
+ if (compress_stream_.avail_in == 0) { // current input data are all
+ out.write_buf(compressed_buf,
+ DEFLATE_BUFFER_SIZE - compress_stream_.avail_out);
+ compress_stream_.next_out = (Bytef *)compressed_buf;
+ compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
+ break;
+ } else if (compress_stream_.avail_out ==
+ 0) { // no more space for output
+ out.write_buf(compressed_buf, DEFLATE_BUFFER_SIZE);
+ compress_stream_.next_out = (Bytef *)compressed_buf;
+ compress_stream_.avail_out = DEFLATE_BUFFER_SIZE;
+ }
}
- }
- return E_OK;
+ return E_OK;
}
int GzipCompressor::compress(char *uncompressed_buf,
uint32_t uncompressed_buf_len,
char *&compressed_buf,
- uint32_t &compressed_buf_len)
-{
- int ret = E_OK;
- ByteStream out(DEFLATE_BUFFER_SIZE, MOD_COMPRESSOR_OBJ);
- if (RET_FAIL(compress_into_bytestream(uncompressed_buf,
- uncompressed_buf_len, out))) {
- return ret;
- }
- if (RET_FAIL(compress_into_bytestream(nullptr, 0, out))) {
+ uint32_t &compressed_buf_len) {
+ int ret = E_OK;
+ ByteStream out(DEFLATE_BUFFER_SIZE, MOD_COMPRESSOR_OBJ);
+ if (RET_FAIL(compress_into_bytestream(uncompressed_buf,
+ uncompressed_buf_len, out))) {
+ return ret;
+ }
+ if (RET_FAIL(compress_into_bytestream(nullptr, 0, out))) {
+ return ret;
+ }
+ compressed_buf = get_bytes_from_bytestream(out);
+ // Assume the length is legal.
+ compressed_buf_len = static_cast<uint32_t>(out.total_size());
+ out.destroy();
return ret;
- }
- compressed_buf = get_bytes_from_bytestream(out);
- compressed_buf_len = out.total_size();
- out.destroy();
- return ret;
}
-GzipDeCompressor::GzipDeCompressor() : decompressed_buf()
-{
- zstream_valid_ = false;
+GzipDeCompressor::GzipDeCompressor() : decompressed_buf() {
+ zstream_valid_ = false;
}
-GzipDeCompressor::~GzipDeCompressor()
-{
- end_zstream();
-}
+GzipDeCompressor::~GzipDeCompressor() { end_zstream(); }
-int GzipDeCompressor::init_zstream()
-{
- if (zstream_valid_) {
+int GzipDeCompressor::init_zstream() {
+ if (zstream_valid_) {
+ return E_OK;
+ }
+ decompress_stream_.zalloc = (alloc_func)0; // Z_NULL
+ decompress_stream_.zfree = (free_func)0;
+ decompress_stream_.opaque = (voidpf)0;
+ decompress_stream_.next_in = 0;
+ decompress_stream_.avail_in = 0;
+ decompress_stream_.next_out = 0;
+ decompress_stream_.avail_out = 0;
+
+ memset(decompressed_buf, 0, INFLATE_BUFFER_SIZE);
+
+ if (inflateInit2(&decompress_stream_, 31) != Z_OK) {
+ // log_err("inflateInit2 failed");
+ return E_COMPRESS_ERR;
+ }
+ zstream_valid_ = true;
return E_OK;
- }
- decompress_stream_.zalloc = (alloc_func)0; // Z_NULL
- decompress_stream_.zfree = (free_func)0;
- decompress_stream_.opaque = (voidpf)0;
- decompress_stream_.next_in = 0;
- decompress_stream_.avail_in = 0;
- decompress_stream_.next_out = 0;
- decompress_stream_.avail_out = 0;
-
- memset(decompressed_buf, 0, INFLATE_BUFFER_SIZE);
-
- if (inflateInit2(&decompress_stream_, 31) != Z_OK) {
- //log_err("inflateInit2 failed");
- return E_COMPRESS_ERR;
- }
- zstream_valid_ = true;
- return E_OK;
}
-int GzipDeCompressor::end_zstream()
-{
- if (!zstream_valid_) {
+int GzipDeCompressor::end_zstream() {
+ if (!zstream_valid_) {
+ return E_OK;
+ }
+ if (inflateEnd(&decompress_stream_) != Z_OK) {
+ // log_err("inflateEnd failed");
+ return E_COMPRESS_ERR;
+ }
+ zstream_valid_ = false;
return E_OK;
- }
- if(inflateEnd(&decompress_stream_) != Z_OK) {
- //log_err("inflateEnd failed");
- return E_COMPRESS_ERR;
- }
- zstream_valid_ = false;
- return E_OK;
}
-int GzipDeCompressor::reset()
-{
- int ret = E_OK;
- if (RET_FAIL(end_zstream())) {
- } else if (RET_FAIL(init_zstream())) {
- }
- return ret;
+int GzipDeCompressor::reset() {
+ int ret = E_OK;
+ if (RET_FAIL(end_zstream())) {
+ } else if (RET_FAIL(init_zstream())) {
+ }
+ return ret;
}
int GzipDeCompressor::decompress_into_bytestream(char *compressed_buf,
uint32_t compressed_buf_len,
- ByteStream &out)
-{
- int ret = Z_OK;
-
- decompress_stream_.next_in = (Bytef *)compressed_buf;
- decompress_stream_.avail_in = compressed_buf_len;
- decompress_stream_.next_out = (Bytef *)decompressed_buf;
- decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
-
- if (compressed_buf == nullptr || compressed_buf_len == 0) {
- if (decompress_stream_.next_out) {
- while (ret != Z_STREAM_END) {
- ret = inflate(&decompress_stream_, Z_FINISH);
- if(ret != Z_OK && ret != Z_STREAM_END) {
- //log_err("inflate failed");
- return E_COMPRESS_ERR;
+ ByteStream &out) {
+ int ret = Z_OK;
+
+ decompress_stream_.next_in = (Bytef *)compressed_buf;
+ decompress_stream_.avail_in = compressed_buf_len;
+ decompress_stream_.next_out = (Bytef *)decompressed_buf;
+ decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
+
+ if (compressed_buf == nullptr || compressed_buf_len == 0) {
+ if (decompress_stream_.next_out) {
+ while (ret != Z_STREAM_END) {
+ ret = inflate(&decompress_stream_, Z_FINISH);
+ if (ret != Z_OK && ret != Z_STREAM_END) {
+ // log_err("inflate failed");
+ return E_COMPRESS_ERR;
+ }
+ out.write_buf(
+ decompressed_buf,
+ INFLATE_BUFFER_SIZE - decompress_stream_.avail_out);
+ decompress_stream_.next_out = (Bytef *)decompressed_buf;
+ decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
+ }
}
- out.write_buf(decompressed_buf, INFLATE_BUFFER_SIZE -
- decompress_stream_.avail_out); decompress_stream_.next_out = (Bytef
- *)decompressed_buf; decompress_stream_.avail_out =
- INFLATE_BUFFER_SIZE;
- }
+ return E_OK;
}
- return E_OK;
- }
- for (;;) {
- ret = inflate(&decompress_stream_, Z_NO_FLUSH);
- if (ret == Z_STREAM_END) {
- out.write_buf(decompressed_buf, INFLATE_BUFFER_SIZE -
- decompress_stream_.avail_out); break;
- }
- if (ret != Z_OK) {
- //log_err("inflate failed");
- return E_COMPRESS_ERR;
- }
- if (decompress_stream_.avail_in == 0) {
- out.write_buf(decompressed_buf, INFLATE_BUFFER_SIZE -
- decompress_stream_.avail_out); decompress_stream_.next_out = (Bytef
- *)decompressed_buf; decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
- break;
- }
- else if (decompress_stream_.avail_out == 0) {
- out.write_buf(decompressed_buf, INFLATE_BUFFER_SIZE);
- decompress_stream_.next_out = (Bytef *)decompressed_buf;
- decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
+ for (;;) {
+ ret = inflate(&decompress_stream_, Z_NO_FLUSH);
+ if (ret == Z_STREAM_END) {
+ out.write_buf(decompressed_buf,
+ INFLATE_BUFFER_SIZE - decompress_stream_.avail_out);
+ break;
+ }
+ if (ret != Z_OK) {
+ // log_err("inflate failed");
+ return E_COMPRESS_ERR;
+ }
+ if (decompress_stream_.avail_in == 0) {
+ out.write_buf(decompressed_buf,
+ INFLATE_BUFFER_SIZE - decompress_stream_.avail_out);
+ decompress_stream_.next_out = (Bytef *)decompressed_buf;
+ decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
+ break;
+ } else if (decompress_stream_.avail_out == 0) {
+ out.write_buf(decompressed_buf, INFLATE_BUFFER_SIZE);
+ decompress_stream_.next_out = (Bytef *)decompressed_buf;
+ decompress_stream_.avail_out = INFLATE_BUFFER_SIZE;
+ }
}
- }
- return E_OK;
+ return E_OK;
}
int GzipDeCompressor::uncompress(char *compressed_buf,
uint32_t compressed_buf_len,
char *&uncompressed_buf,
- uint32_t &uncompressed_buf_len)
-{
- int ret = E_OK;
- ByteStream out(INFLATE_BUFFER_SIZE, MOD_COMPRESSOR_OBJ);
- if(RET_FAIL(decompress_into_bytestream(compressed_buf, compressed_buf_len,
- out))) {
- return ret;
- }
- if (RET_FAIL(decompress_into_bytestream(nullptr, 0, out))) {
+ uint32_t &uncompressed_buf_len) {
+ int ret = E_OK;
+ ByteStream out(INFLATE_BUFFER_SIZE, MOD_COMPRESSOR_OBJ);
+ if (RET_FAIL(decompress_into_bytestream(compressed_buf, compressed_buf_len,
+ out))) {
+ return ret;
+ }
+ if (RET_FAIL(decompress_into_bytestream(nullptr, 0, out))) {
+ return ret;
+ }
+ uncompressed_buf = get_bytes_from_bytestream(out);
+ uncompressed_buf_len = static_cast<uint32_t>(out.total_size());
+ // uncompressed_buf[uncompressed_buf_len] = '\0';
+ out.destroy();
return ret;
- }
- uncompressed_buf = get_bytes_from_bytestream(out);
- uncompressed_buf_len = out.total_size();
-// uncompressed_buf[uncompressed_buf_len] = '\0';
- out.destroy();
- return ret;
}
-} // end namespace storage
+} // end namespace storage
diff --git a/cpp/src/compress/lz4_compressor.cc b/cpp/src/compress/lz4_compressor.cc
index 06bd10cf..dcbecc17 100644
--- a/cpp/src/compress/lz4_compressor.cc
+++ b/cpp/src/compress/lz4_compressor.cc
@@ -21,7 +21,7 @@
#include "common/allocator/alloc_base.h"
using namespace common;
-
+using namespace error_info;
namespace storage {
void LZ4Compressor::destroy() {
@@ -37,7 +37,7 @@ void LZ4Compressor::destroy() {
}
int LZ4Compressor::reset(bool for_compress) {
- // Nothing to do
+ UNUSED(for_compress);
return E_OK;
}
@@ -46,7 +46,7 @@ int LZ4Compressor::compress(char *uncompressed_buf,
char *&compressed_buf,
uint32_t &compressed_buf_len) {
int ret = E_OK;
- int max_dst_size = LZ4_compressBound(uncompressed_buf_len);
+ int max_dst_size = LZ4_compressBound(static_cast<int32_t>(uncompressed_buf_len));
compressed_buf_ =
(char *)mem_alloc((size_t)max_dst_size, MOD_COMPRESSOR_OBJ);
diff --git a/cpp/src/compress/lzo_compressor.cc b/cpp/src/compress/lzo_compressor.cc
index 0ccde9f6..be727898 100644
--- a/cpp/src/compress/lzo_compressor.cc
+++ b/cpp/src/compress/lzo_compressor.cc
@@ -21,6 +21,7 @@
#include "common/allocator/alloc_base.h"
using namespace common;
+using namespace error_info;
namespace storage {
@@ -38,6 +39,7 @@ void LZOCompressor::destroy() {
int LZOCompressor::reset(bool for_compress) {
// Nothing to do
+ UNUSED(for_compress);
return E_OK;
}
@@ -64,7 +66,7 @@ int LZOCompressor::compress(char *uncompressed_buf,
} else {
compressed_buf = compress_data;
compressed_buf_ = compress_data;
- compressed_buf_len = compressed_len;
+ compressed_buf_len = static_cast<uint32_t>(compressed_len);
}
} else {
ret = E_COMPRESS_ERR;
@@ -87,8 +89,8 @@ int LZOCompressor::uncompress(char *compressed_buf, uint32_t compressed_buf_len,
size_t ulength;
constexpr float ratio[] = {1.5, 2.5, 3.5, 4.5, 255};
for (uint8_t i = 0; i < UNCOMPRESSED_TIME; ++i) {
- regen_buffer = (char *)mem_alloc(compressed_buf_len * ratio[i],
- MOD_COMPRESSOR_OBJ);
+ regen_buffer = static_cast<char *>(
+ mem_alloc(static_cast<size_t>(compressed_buf_len * ratio[i]), MOD_COMPRESSOR_OBJ));
if (regen_buffer == nullptr) {
ret = E_OOM;
} else {
diff --git a/cpp/src/compress/snappy_compressor.cc b/cpp/src/compress/snappy_compressor.cc
index 2dbba4ec..80ff1d19 100644
--- a/cpp/src/compress/snappy_compressor.cc
+++ b/cpp/src/compress/snappy_compressor.cc
@@ -21,7 +21,7 @@
#include "common/allocator/alloc_base.h"
using namespace common;
-
+using namespace error_info;
namespace storage {
void SnappyCompressor::destroy() {
diff --git a/cpp/src/parser/path_nodes_generator.cpp b/cpp/src/parser/path_nodes_generator.cpp
index 8f4966c4..0f2b7e43 100644
--- a/cpp/src/parser/path_nodes_generator.cpp
+++ b/cpp/src/parser/path_nodes_generator.cpp
@@ -24,7 +24,7 @@
#include "generated/PathParser.h"
#include "path_parser_error.h"
#include "path_visitor.h"
-#include "utils/errno_define.h"
+#include "common/error_info/error_info.h"
namespace storage {
std::vector<std::string> PathNodesGenerator::invokeParser(
diff --git a/cpp/src/reader/bloom_filter.h b/cpp/src/reader/bloom_filter.h
index ba3394ce..756358d4 100644
--- a/cpp/src/reader/bloom_filter.h
+++ b/cpp/src/reader/bloom_filter.h
@@ -54,15 +54,16 @@ class BitSet {
int init(int32_t size) {
ASSERT(size > 1);
word_count_ = (size - 1) / 64 + 1;
- int32_t alloc_size = word_count_ * sizeof(uint64_t);
- words_ =
- (uint64_t *)common::mem_alloc(alloc_size, common::MOD_BLOOM_FILTER);
+ size_t alloc_size = static_cast<size_t>(word_count_) * sizeof(uint64_t);
+ words_ = static_cast<uint64_t *>(
+ common::mem_alloc(alloc_size, common::MOD_BLOOM_FILTER));
if (IS_NULL(words_)) {
- return common::E_OOM;
+ return error_info::E_OOM;
}
memset(words_, 0, alloc_size);
return error_info::E_OK;
}
+
void destroy() {
if (!IS_NULL(words_)) {
common::mem_free(words_);
diff --git a/cpp/src/reader/filter/filter.h b/cpp/src/reader/filter/filter.h
index 1846df5a..0c2b34fc 100644
--- a/cpp/src/reader/filter/filter.h
+++ b/cpp/src/reader/filter/filter.h
@@ -35,22 +35,31 @@ class Filter {
virtual ~Filter() {}
virtual bool satisfy(Statistic* statistic) {
+ UNUSED(statistic);
ASSERT(false);
return false;
}
virtual bool satisfy(int64_t time, int64_t value) {
+ UNUSED(time);
+ UNUSED(value);
ASSERT(false);
return false;
}
virtual bool satisfy(int64_t time, common::String value) {
+ UNUSED(time);
+ UNUSED(value);
ASSERT(false);
return false;
}
virtual bool satisfy_start_end_time(int64_t start_time, int64_t end_time) {
+ UNUSED(start_time);
+ UNUSED(end_time);
ASSERT(false);
return false;
}
virtual bool contain_start_end_time(int64_t start_time, int64_t end_time) {
+ UNUSED(start_time);
+ UNUSED(end_time);
ASSERT(false);
return false;
}
diff --git a/cpp/src/utils/storage_utils.h b/cpp/src/utils/storage_utils.h
index a0c6f3b2..f82c9e1c 100644
--- a/cpp/src/utils/storage_utils.h
+++ b/cpp/src/utils/storage_utils.h
@@ -19,9 +19,9 @@
#ifndef UTILS_STORAGE_UTILS_H
#define UTILS_STORAGE_UTILS_H
-#include <inttypes.h>
-#include <stdint.h>
#include <algorithm>
+#include <cinttypes>
+#include <cstdint>
#include "common/datatype/value.h"
#include "common/tsblock/tsblock.h"
@@ -78,15 +78,19 @@ FORCE_INLINE std::string get_file_path_from_file_id(
}
FORCE_INLINE static void to_lowercase_inplace(std::string &str) {
- std::transform(
- str.begin(), str.end(), str.begin(),
- [](unsigned char c) -> unsigned char { return std::tolower(c); });
+ std::transform(str.begin(), str.end(), str.begin(),
+ [](const char c) -> char {
+ return static_cast<char>(
+ std::tolower(static_cast<unsigned char>(c)));
+ });
}
FORCE_INLINE static std::string to_lower(const std::string &str) {
std::string result;
- std::transform(
- str.begin(), str.end(), std::back_inserter(result),
- [](unsigned char c) -> unsigned char { return std::tolower(c); });
+ std::transform(str.begin(), str.end(), std::back_inserter(result),
+ [](const char c) -> char {
+ return static_cast<char>(
+ std::tolower(static_cast<unsigned char>(c)));
+ });
return result;
}