chaoyli closed pull request #470: Fixed compilation error in refactoring tablet
and tabletmeta
URL: https://github.com/apache/incubator-doris/pull/470
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h
index b5bda19d..5d45adcd 100644
--- a/be/src/olap/olap_common.h
+++ b/be/src/olap/olap_common.h
@@ -186,15 +186,6 @@ enum ReaderType {
// <start_version_id, end_version_id>, such as <100, 110>
//using Version = std::pair<TupleVersion, TupleVersion>;
typedef std::pair<int64_t, int64_t> Version;
-
-// used for hash-struct of hash_map<Version, Rowset*>.
-struct HashOfVersion {
- uint64_t operator()(const Version& version) const {
- uint64_t value = version.first ^ version.second;
- return std::hash<uint64_t>(value);
- }
-};
-
typedef std::vector<Version> Versions;
// It is used to represent Graph vertex.
diff --git a/be/src/olap/rowset_graph.cpp b/be/src/olap/rowset_graph.cpp
index fc9d7483..be0d5a8e 100644
--- a/be/src/olap/rowset_graph.cpp
+++ b/be/src/olap/rowset_graph.cpp
@@ -17,7 +17,9 @@
#include "olap/rowset_graph.h"
-NewStatus Tablet::construct_rowset_graph(const std::vector<RowsetMeta>&
rs_metas) {
+namespace doris {
+
+OLAPStatus Tablet::construct_rowset_graph(const std::vector<RowsetMeta>&
rs_metas) {
if (rs_metas.size() == 0) {
VLOG(3) << "there is no version in the header.";
return Status::OK();
@@ -43,7 +45,7 @@ NewStatus Tablet::construct_rowset_graph(const
std::vector<RowsetMeta>& rs_metas
}
// Add vertex to graph.
- NewStatus status = add_vertex_to_graph(vertex_values[i]);
+ OLAPStatus status = add_vertex_to_graph(vertex_values[i]);
if (!status.ok())
LOG(WARNING) << "fail to add vertex to version graph. vertex=" <<
vertex_values[i];
return status;
@@ -67,19 +69,19 @@ NewStatus Tablet::construct_rowset_graph(const
std::vector<RowsetMeta>& rs_metas
}
}
-NewStatus RowsetGraph::add_version_to_graph(const Version& version) {
+OLAPStatus RowsetGraph::add_version_to_graph(const Version& version) {
// Add version.first as new vertex of version graph if not exist.
int start_vertex_value = version.first;
int end_vertex_value = version.second + 1;
// Add vertex to graph.
- NewStatus status = add_vertex_to_graph(start_vertex_value);
+ OLAPStatus status = add_vertex_to_graph(start_vertex_value);
if (!status.ok()) {
LOG(WARNING) << "fail to add vertex to version graph. vertex=" <<
start_vertex_value;
return status;
}
- NewStatus status = add_vertex_to_graph(end_vertex_value);
+ OLAPStatus status = add_vertex_to_graph(end_vertex_value);
if (!status.ok()) {
LOG(WARNING) << "fail to add vertex to version graph. vertex=" <<
end_vertex_value;
return status;
@@ -100,7 +102,7 @@ NewStatus RowsetGraph::add_version_to_graph(const Version&
version) {
return Status::OK();
}
-NewStatus RowsetGraph::delete_version_from_graph(const Version& version) {
+OLAPStatus RowsetGraph::delete_version_from_graph(const Version& version) {
int start_vertex_value = version.first;
int end_vertex_value = version.second + 1;
@@ -108,7 +110,7 @@ NewStatus RowsetGraph::delete_version_from_graph(const
Version& version) {
|| _vertex_helper_map->find(end_vertex_value) ==
_vertex_helper_map->end()) {
LOG(WARNING) << "vertex for version does not exists. "
<< "version=" << version.first << "-" << version.second;
- return NewStatus::NotFound("vertex for version does not exists.");
+ return OLAPStatus::NotFound("vertex for version does not exists.");
}
int start_vertex_index = (*_vertex_helper_map)[start_vertex_value];
@@ -131,7 +133,7 @@ NewStatus RowsetGraph::delete_version_from_graph(const
Version& version) {
return Status::OK();
}
-NewStatus RowsetGraph::_add_vertex_to_graph(int vertex_value) {
+OLAPStatus RowsetGraph::_add_vertex_to_graph(int vertex_value) {
// Vertex with vertex_value already exists.
if (_vertex_index_map->find(vertex_value) != _vertex_index_map->end()) {
VLOG(3) << "vertex with vertex value already exists. value=" <<
vertex_value;
@@ -140,7 +142,7 @@ NewStatus RowsetGraph::_add_vertex_to_graph(int
vertex_value) {
list<int>* edges = new(std::nothrow) list<int>();
if (edges == NULL) {
- return NewStatus::Corruption("malloc memory failed for edge list");
+ return OLAPStatus::Corruption("malloc memory failed for edge list");
}
Vertex vertex = {vertex_value, edges};
@@ -149,7 +151,8 @@ NewStatus RowsetGraph::_add_vertex_to_graph(int
vertex_value) {
return Status::OK();
}
-NewStatus Tablet::capture_consistent_versions(const Version& spec_version,
version<Version>* version_path) {
+OLAPStatus Tablet::capture_consistent_versions(const Version& spec_version,
+ std::vector<Version>*
version_path) {
if (spec_version.first > spec_version.second) {
LOG(WARNING) << "invalid specfied version. "
<< "spec_version=" << spec_version.first << "-" <<
spec_version.second;
diff --git a/be/src/olap/rowset_graph.h b/be/src/olap/rowset_graph.h
index f39c51d2..43e90262 100644
--- a/be/src/olap/rowset_graph.h
+++ b/be/src/olap/rowset_graph.h
@@ -18,15 +18,20 @@
#ifndef DORIS_BE_SRC_OLAP_ROWSET_GRAPH_H
#define DORIS_BE_SRC_OLAP_ROWSET_GRAPH_H
+#include "olap/olap_common.h"
+#include "olap/olap_define.h"
+
+namespace doris {
+
class RowsetGraph {
public:
- NewStatus construct_rowset_graph(const std::vector<RowsetMeta>& rs_metas);
- NewStatus add_version_to_graph(const Versrion& version);
- NewStatus delete_version_from_graph(const Version& version);
- NewStatus capture_consistent_versions(const Version& spec_version,
- version<Version>* version_path);
+ OLAPStatus construct_rowset_graph(const std::vector<RowsetMeta>& rs_metas);
+ OLAPStatus add_version_to_graph(const Version& version);
+ OLAPStatus delete_version_from_graph(const Version& version);
+ OLAPStatus capture_consistent_versions(const Version& spec_version,
+ std::vector<Version>* version_path);
private:
- NewStatus _add_vertex_to_graph(int vertex_value);
+ OLAPStatus _add_vertex_to_graph(int vertex_value);
// OLAP version contains two parts, [start_version, end_version]. In order
// to construct graph, the OLAP version has two corresponding vertex, one
diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp
index f17474fb..84a7688a 100644
--- a/be/src/olap/tablet.cpp
+++ b/be/src/olap/tablet.cpp
@@ -58,12 +58,8 @@ Tablet(TabletMeta* tablet_meta, DataDir* data_dir) {
}
Tablet::~Tablet() {
- if (_tablet_meta == NULL) {
- return; // for convenience of mock test.
- }
-
// ensure that there is nobody using Tablet, like acquiring
OLAPData(SegmentGroup)
- WriteLock wrlock(_meta_lock);
+ WriteLock wrlock(&_meta_lock);
for (auto& it : _version_rowset_map) {
SAFE_DELETE(it.second);
}
@@ -87,7 +83,7 @@ bool Tablet::can_do_compaction() {
// 如果table正在做schema change,则通过选路判断数据是否转换完成
// 如果选路成功,则转换完成,可以进行BE
// 如果选路失败,则转换未完成,不能进行BE
- ReadLock rdlock(_meta_lock);
+ ReadLock rdlock(&_meta_lock);
RowsetSharedPtr lastest_rowset = lastest_version();
if (lastest_rowset == NULL) {
return false;
@@ -96,7 +92,7 @@ bool Tablet::can_do_compaction() {
Version test_version = Version(0, lastest_version->end_version());
vector<Version> path_versions;
if (OLAP_SUCCESS != _rs_graph->capture_consistent_versions(test_version,
&path_versions)) {
- LOG(WARNING) << "tablet has missed version. tablet=" <<
table->full_name();
+ LOG(WARNING) << "tablet has missed version. tablet=" << full_name();
return false;
}
@@ -132,7 +128,7 @@ OLAPStatus Tablet::capture_consistent_rowsets(const
Version& spec_version,
void Tablet::acquire_rs_reader_by_version(const vector<Version>& version_vec,
vector<std::shared_ptr<RowsetReader>>* rs_readers) const {
- DCHECK(rs_readers != NULL && rs_readers.empty());
+ DCHECK(rs_readers != NULL && rs_readers->empty());
for (auto version : version_vec) {
auto it2 = _rs_version_map.find(*it1);
if (it2 == _rs_version_map.end()) {
@@ -149,7 +145,7 @@ void Tablet::acquire_rs_reader_by_version(const
vector<Version>& version_vec,
<< ", version=" << version.first << "-" <<
version.second;
release_rs_readers(rs_readers);
}
- rs_reader.push_back(std::move(rs_reader)):
+ rs_reader->push_back(std::move(rs_reader)):
}
}
@@ -160,11 +156,11 @@ OLAPStatus
Tablet::release_rs_readers(vector<std::shared_ptr<RowsetReader>>* rs_
}
rs_readers->clear();
- return OLAP_SUCCESS;
+ return OLAP_SUCCESS;
}
OLAPStatus Tablet::add_inc_rowset(const Rowset& rowset) {
- return _table_meta->add_inc_rs_meta(rowset->get_rs_meta());
+ return _table_meta.add_inc_rs_meta(rowset->get_rs_meta());
}
OLAPStatus Tablet::delete_expired_inc_rowset() {
@@ -201,7 +197,7 @@ void Tablet::calc_missed_versions(int64_t spec_version,
DCHECK(spec_version > 0) << "invalid spec_version: " << spec_version;
std::list<Version> existing_versions;
for (RowsetMeta& rs : _tablet_meta->get_all_rs_metas()) {
- existing_versions.emplace_back(rs->version());
+ existing_versions.emplace_back(rs.version());
}
// sort the existing versions in ascending order
@@ -210,7 +206,7 @@ void Tablet::calc_missed_versions(int64_t spec_version,
return a.first < b.first;
});
- // find the missing version until until_version
+ // find the missing version until spec_version
int64_t last_version = -1;
for (const Version& version : existing_versions) {
if (version.first > last_version + 1) {
@@ -223,8 +219,8 @@ void Tablet::calc_missed_versions(int64_t spec_version,
break;
}
}
- for (int64_t i = last_version + 1; i <= until_version; ++i) {
- spec_versions->emplace_back(i, i);
+ for (int64_t i = last_version + 1; i <= spec_version; ++i) {
+ missed_versions->emplace_back(i, i);
}
}
@@ -375,7 +371,7 @@ OLAPStatus Tablet::split_range(
}
cur_start_key.attach(entry.data);
- last_start_key.allocate_memory_for_string_type(_tablet_schema);
+ last_start_key.allocate_memory_for_string_type(_schema);
last_start_key.copy_without_pool(cur_start_key);
// start_key是last start_key, 但返回的实际上是查询层给出的key
ranges->emplace_back(start_key.to_tuple());
@@ -471,7 +467,7 @@ bool Tablet::is_schema_changing() {
bool is_schema_changing = false;
ReadLock rdlock(_meta_lock);
- if (_tablet_meta->alter_state() != AlterTabletState::none) {
+ if (_tablet_meta->alter_state() != AlterTabletState::NONE) {
is_schema_changing = true;
}
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index 24934b22..c7859994 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -32,6 +32,7 @@
#include "olap/tablet_meta.h"
#include "olap/tuple.h"
#include "olap/row_cursor.h"
+#include "olap/rowset_graph.h"
#include "olap/utils.h"
namespace doris {
@@ -40,6 +41,7 @@ class Rowset;
class Tablet;
class RowBlockPosition;
class DataDir;
+class RowsetReader;
using TabletSharedPtr = std::shared_ptr<Tablet>;
@@ -59,7 +61,7 @@ class Tablet : public std::enable_shared_from_this<Tablet> {
double bloom_filter_fpp() const;
bool equal(TTabletId tablet_id, TSchemaHash schema_hash);
- Schema* schema() const;
+ TabletSchema* schema() const;
const std::string& full_name() const;
size_t num_fields() const;
size_t num_null_fields();
@@ -100,7 +102,7 @@ class Tablet : public std::enable_shared_from_this<Tablet> {
vector<std::shared_ptr<RowsetReader>>*
rs_readers) const;
OLAPStatus release_rs_readers(vector<std::shared_ptr<RowsetReader>>*
rs_readers) const;
- RMMutex* meta_lock();
+ RWMutex* meta_lock();
Mutex* ingest_lock();
Mutex* base_lock();
Mutex* cumulative_lock();
@@ -120,7 +122,7 @@ class Tablet : public std::enable_shared_from_this<Tablet> {
bool can_do_compaction();
DeletePredicatePB* add_delete_predicates() {
- return _tablet_meta->add_delete_predicates();
+ return _tablet_meta.add_delete_predicates();
}
const google::protobuf::RepeatedPtrField<DeletePredicatePB>&
@@ -151,12 +153,22 @@ class Tablet : public
std::enable_shared_from_this<Tablet> {
RowsetGraph* _rs_graph;
TabletMeta _tablet_meta;
- Schema* _schema;
- RMMutex _meta_lock;
+ TabletSchema* _schema;
+ RWMutex _meta_lock;
Mutex _ingest_lock;
Mutex _base_lock;
Mutex _cumulative_lock;
- std::unordered_map<Version, std:shared_ptr<Rowset>, HashOfVersion>
_version_rowset_map;
+
+ // used for hash-struct of hash_map<Version, Rowset*>.
+ struct HashOfVersion {
+ size_t operator()(const Version& version) const {
+ size_t seed = 0;
+ seed = HashUtil::hash64(&version.first, sizeof(version.first),
seed);
+ seed = HashUtil::hash64(&version.second, sizeof(version.second),
seed);
+ return seed;
+ }
+ };
+ std::unordered_map<Version, RowsetSharedPtr, HashOfVersion>
_version_rowset_map;
DISALLOW_COPY_AND_ASSIGN(Tablet);
};
diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp
index cb55461c..533e1bf4 100644
--- a/be/src/olap/tablet_meta.cpp
+++ b/be/src/olap/tablet_meta.cpp
@@ -30,10 +30,10 @@ OLAPStatus TabletMeta::serialize(string* meta_binary) {
OLAPStatus TabletMeta::serialize_unlock(string* meta_binary) {
_tablet_meta_pb.SerializeToString(meta_binary);
- return OLAP_SUCCESS:
+ return OLAP_SUCCESS;
};
-OLAPStatus TabletMeta::deserialize(string* meta_binary) {
+OLAPStatus TabletMeta::deserialize(const string& meta_binary) {
std::lock_guard<std::mutex> lock(_mutex);
return deserialize_unlock(meta_binary);
}
@@ -59,28 +59,28 @@ OLAPStatus TabletMeta::deserialize_unlock(const string&
meta_binary) {
// generate TabletState
switch (_tablet_meta_pb.tablet_state()) {
- case NOT_READY:
- _tablet_state = TabletState::kNotReady;
+ case PB_NOTREADY:
+ _tablet_state = TabletState::NOTREADY;
break;
- case RUNNING:
- _tablet_state = TabletState::kRunning;
+ case PB_RUNNING:
+ _tablet_state = TabletState::RUNNING;
break;
- case TOMBSTONED:
- _tablet_state = TabletState::kTombstoned;
+ case PB_TOMBSTONED:
+ _tablet_state = TabletState::TOMBSTONED;
break;
- case STOPPED:
- _tablet_state = TabletState::kStopped;
+ case PB_STOPPED:
+ _tablet_state = TabletState::STOPPED;
break;
- case SHUTDOWN:
- _tablet_state = TabletState::kShutdown;
+ case PB_SHUTDOWN:
+ _tablet_state = TabletState::SHUTDOWN;
break;
default:
- LOG(WARNNING) << "tablet has no state. tablet=" << _tablet_id
+ LOG(WARNING) << "tablet has no state. tablet=" << _tablet_id
<< ", schema_hash=" << _schema_hash;
}
// generate AlterTabletTask
-
RETURN(_alter_task.deserialize_from_pb(_tablet_meta_pb.alter_tablet_task()));
+
RETURN_NOT_OK(_alter_task.init_from_pb(_tablet_meta_pb.alter_tablet_task()));
return OLAP_SUCCESS;
}
@@ -91,7 +91,7 @@ OLAPStatus TabletMeta::save_meta() {
OLAPStatus TabletMeta::save_meta_unlock() {
string meta_binary;
- serialize_unlock(meta_binary);
+ serialize_unlock(&meta_binary);
OLAPStatus status = TabletMetaManager::save(_data_dir, _tablet_id,
_schema_hash, meta_binary);
if (status != OLAP_SUCCESS) {
LOG(WARNING) << "fail to save tablet_meta. status=" <<
status.to_string()
@@ -101,12 +101,12 @@ OLAPStatus TabletMeta::save_meta_unlock() {
return status;
}
-OLAPStatus TabletMeta::to_meta_pb(TabletMetaPB* tablet_meta_pb) {
+OLAPStatus TabletMeta::to_tablet_pb(TabletMetaPB* tablet_meta_pb) {
std::lock_guard<std::mutex> lock(_mutex);
- return to_meta_pb_unlock(tablet_meta_pb);
+ return to_tablet_pb_unlock(tablet_meta_pb);
}
-OLAPStatus TabletMeta::to_meta_pb_unlock(TabletMetaPB* tablet_meta_pb) {
+OLAPStatus TabletMeta::to_tablet_pb_unlock(TabletMetaPB* tablet_meta_pb) {
tablet_meta_pb->set_table_id(_table_id);
tablet_meta_pb->set_partition_id(_partition_id);
tablet_meta_pb->set_table_id(_tablet_id);
@@ -115,10 +115,10 @@ OLAPStatus TabletMeta::to_meta_pb_unlock(TabletMetaPB*
tablet_meta_pb) {
tablet_meta_pb->set_tablet_name(_tablet_name);
for (auto rs : _rs_metas) {
- rs->to_meta_pb(pb.add_rs_meta());
+ rs.to_rowset_pb(pb.add_rs_meta());
}
for (auto rs : _inc_rs_metas) {
- rs->to_meta_pb(pb.add_inc_rc_meta());
+ rs.to_rowset_pb(pb.add_inc_rc_meta());
}
_schema.to_schema_pb(pb.mutable_schema());
@@ -129,16 +129,16 @@ OLAPStatus TabletMeta::add_inc_rs_meta(const RowsetMeta&
rs_meta) {
std::lock_guard<std::mutex> lock(_mutex);
// check RowsetMeta is valid
- for (auts rs : _inc_rs_metas) {
- if (rs.rowset_id() == rs_meta.rowset_id()()) {
+ for (auto rs : _inc_rs_metas) {
+ if (rs.rowset_id() == rs_meta.rowset_id()) {
LOG(WARNING) << "rowset already exist. rowset_id=" <<
rs.rowset_id();
return OLAPStatus::AlreadyExist("rowset already exist.");
}
}
_inc_rs_metas.push_back(std::move(rs_meta));
- RowsetMetaPB* rs_meta_pb = _tablet_meta_pb->add_inc_rs_meta();
- RETURN_NOT_OK(rs_meta->to_meta_pb(rs_meta_pb));
+ RowsetMetaPB* rs_meta_pb = _tablet_meta_pb.add_inc_rs_meta();
+ RETURN_NOT_OK(rs_meta.to_rowset_pb(rs_meta_pb));
RETURN_NOT_OK(save_meta_unlock());
return OLAP_SUCCESS;
@@ -153,7 +153,7 @@ OLAPStatus TabletMeta::delete_inc_rs_meta_by_version(const
Version& version)
}
TabletMetaPB tablet_meta_pb;
- RETURN_NOT_OK(to_meta_pb_unlock(&tablet_meta_pb));
+ RETURN_NOT_OK(to_tablet_pb_unlock(&tablet_meta_pb));
_tablet_meta_pb = std::move(tablet_meta_pb);
RETURN_NOT_OK(save_meta_unlock());
@@ -186,7 +186,7 @@ OLAPStatus TabletMeta::modify_rowsets(const
vector<RowsetMetaSharedPtr>& to_add,
}
TabletMetaPB tablet_meta_pb;
- RETURN_NOT_OK(to_meta_pb_unlock(&tablet_meta_pb));
+ RETURN_NOT_OK(to_tablet_pb_unlock(&tablet_meta_pb));
_tablet_meta_pb = std::move(tablet_meta_pb);
RETURN_NOT_OK(save_meta_unlock());
diff --git a/be/src/olap/tablet_meta.h b/be/src/olap/tablet_meta.h
index 39d3a8e8..297c1484 100644
--- a/be/src/olap/tablet_meta.h
+++ b/be/src/olap/tablet_meta.h
@@ -18,13 +18,15 @@
#ifndef DORIS_BE_SRC_OLAP_TABLET_META_H
#define DORIS_BE_SRC_OLAP_TABLET_META_H
+#include <mutex>
#include <string>
#include <vector>
+#include "common/logging.h"
#include "gen_cpp/olap_file.pb.h"
-#include "gen_cpp/Types_types.h"
#include "olap/olap_common.h"
#include "olap/olap_define.h"
+#include "olap/tablet_schema.h"
using std::string;
using std::vector;
@@ -41,20 +43,23 @@ enum TabletState {
enum AlterTabletState {
NONE,
- RUNNING,
+ ALTERING,
FINISHED,
FAILED
};
-enum AlterTabletType {
- SCHEMA_CHANGE = 0,
- ROLLUP = 1
-}
+class Rowset;
+using RowsetSharedPtr = std::shared_ptr<Rowset>;
+
+class RowsetMeta;
+using RowsetMetaSharedPtr = std::shared_ptr<RowsetMeta>;
+
+class DataDir;
class AlterTabletTask {
public:
- OLAPStatus deserialize_from_pb(const AlterTabletPB& alter_tablet_task);
- OLAPStatus to_meta_pb(AlterTabletTaskPB* alter_task);
+ OLAPStatus init_from_pb(const AlterTabletPB& alter_tablet_task);
+ OLAPStatus to_alter_pb(AlterTabletPB* alter_task);
OLAPStatus clear();
inline int64_t related_tablet_id() { return _related_tablet_id; }
@@ -62,15 +67,15 @@ class AlterTabletTask {
vector<RowsetMeta>& rowsets_to_alter() { return _rowsets_to_alter; }
- AlterTabletState alter_state() { return _alter_state; }
- AlterTabletType { return _alter_type; }
+ const AlterTabletState& alter_state() const { return _alter_state; }
+ const AlterTabletType& alter_type() const { return _alter_type; }
private:
int64_t _related_tablet_id;
int64_t _related_schema_hash;
vector<RowsetMeta> _rowsets_to_alter;
AlterTabletState _alter_state;
AlterTabletType _alter_type;
-}
+};
class TabletMeta {
public:
@@ -85,12 +90,13 @@ class TabletMeta {
OLAPStatus save_meta();
OLAPStatus save_meta_unlock();
- OLAPStatus to_meta_pb(TabletMetaPB* tablet_meta_pb);
- OLAPStatus to_meta_pb_unlock(TabletMetaPB* tablet_meta_pb);
+ OLAPStatus to_tablet_pb(TabletMetaPB* tablet_meta_pb);
+ OLAPStatus to_tablet_pb_unlock(TabletMetaPB* tablet_meta_pb);
- Newstatus add_inc_rs_meta(const RowsetMeta& rs_meta);
+ OLAPStatus add_inc_rs_meta(const RowsetMeta& rs_meta);
OLAPStatus delete_inc_rs_meta_by_version(const Version& version);
const RowsetMetaSharedPtr get_inc_rs_meta(const Version& version) const;
+ DeletePredicatePB* add_delete_predicates();
const std::vector<RowsetMeta>& all_inc_rs_metas() const;
const std::vector<RowsetMeta>& all_rs_metas() const;
@@ -132,35 +138,35 @@ class TabletMeta {
std::mutex _mutex;
};
-inline const int64_t table_id() const {
+inline const int64_t TabletMeta::table_id() const {
return _tablet_id;
}
-inline const int64_t partition_id() const {
+inline const int64_t TabletMeta::partition_id() const {
return _partition_id;
}
-inline const int64_t tablet_id() const {
+inline const int64_t TabletMeta::tablet_id() const {
return _tablet_id;
}
-inline const int64_t schema_hash() const {
+inline const int64_t TabletMeta::schema_hash() const {
return _schema_hash;
}
-inline const int16_t shard_id() {
+inline const int16_t TabletMeta::shard_id() {
return _shard_id;
}
-inline const AlterTabletTask& alter_task() const {
+inline const AlterTabletTask& TabletMeta::alter_task() const {
return _alter_task;
}
-inline const AlterTabletState& alter_state() const {
+inline const AlterTabletState& TabletMeta::alter_state() const {
return _alter_task.alter_state();
}
-inline const TabletState& tablet_state() const {
+inline const TabletState& TabletMeta::tablet_state() const {
return _tablet_state;
}
diff --git a/be/src/olap/tablet_schema.cpp b/be/src/olap/tablet_schema.cpp
new file mode 100644
index 00000000..73914792
--- /dev/null
+++ b/be/src/olap/tablet_schema.cpp
@@ -0,0 +1,101 @@
+// 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 DORIS_BE_SRC_OLAP_TABLET_SCHEMA_H
+#define DORIS_BE_SRC_OLAP_TABLET_SCHEMA_H
+
+#include <vector>
+
+#include "runtime/tablet_schema.h"
+
+namespace doris {
+
+OLAPStatus TabletColumnSchema::init_from_pb(const TabletColumnSchema& column) {
+ _column_id = column.column_id();
+ switch (column.type()) {
+ case TINYINT:
+ _type = OLAP_FIELD_TYPE_TINYINT;
+ break;
+ case SMALLINT:
+ _type = OLAP_FIELD_TYPE_SMALLINT;
+ break;
+ case INT:
+ _type = OLAP_FIELD_TYPE_INT;
+ break;
+ case BIGINT:
+ _type = OLAP_FIELD_TYPE_BIGINT;
+ break;
+ case LARGEINT:
+ _type = OLAP_FIELD_TYPE_LARGEINT;
+ break;
+ case FLOAT:
+ _type = OLAP_FIELD_TYPE_FLOAT;
+ break;
+ case DOUBLE:
+ _type = OLAP_FIELD_TYPE_DOUBLE;
+ break;
+ case DECIMAL:
+ _type = OLAP_FIELD_TYPE_DECIMAL;
+ break;
+ case CHAR:
+ _type = OLAP_FIELD_TYPE_CHAR;
+ break;
+ case VARCHAR:
+ _type = OLAP_FIELD_TYPE_VARCHAR;
+ break;
+ case HLL:
+ _type = OLAP_FIELD_TYPE_HLL;
+ break;
+ case DATE:
+ _type = OLAP_FIELD_TYPE_DATE;
+ break;
+ case DATETIME:
+ _type = OLAP_FIELD_TYPE_DATETIME;
+ default:
+ _type = OLAP_FIELD_TYPE_UNKNOWN;
+ break;
+ }
+ _type_info = get_type_info(type);
+ _is_key = column.is_key();
+ _is_nullable = column.is_nullable();
+ _is_bf_column = column.is_bf_column();
+}
+
+TabletSchema TabletSchema()
+ : _num_columns(0),
+ _num_key_columns(0),
+ _num_null_columns(0),
+ _num_short_key_columns(0)
+
+OLAPStatus TabletSchema::init_from_pb(const TabletSchemaPB& schema) {
+ for (auto& column : schema.columns()) {
+ TabletColumnSchema column_schema;
+ column_schema.init_from_pb(column);
+ _cols.push_back(column_schema);
+ _num_columns++;
+ if (column_schema.is_key()) {
+ _num_key_columns++;
+ }
+ if (column_schema.is_nullable()) {
+ _num_null_columns++;
+ }
+ }
+}
+
+} // namespace doris
+
+#endif // DORIS_BE_SRC_OLAP_SCHEMA_H
diff --git a/be/src/olap/tablet_schema.h b/be/src/olap/tablet_schema.h
new file mode 100644
index 00000000..118a50c6
--- /dev/null
+++ b/be/src/olap/tablet_schema.h
@@ -0,0 +1,60 @@
+// 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 DORIS_BE_SRC_OLAP_TABLET_SCHEMA_H
+#define DORIS_BE_SRC_OLAP_TABLET_SCHEMA_H
+
+#include <vector>
+
+#include "gen_cpp/olap_file.pb.h"
+#include "olap/types.h"
+
+namespace doris {
+
+class TabletColumnSchema {
+public:
+ TabletColumnSchema();
+ OLAPStatus init_from_pb(const ColumnPB& column);
+
+ inline int32_t column_id() const { return _column_id; }
+ inline bool is_key() const { return _is_key; }
+ inline bool is_nullable() const { return _is_nullable; }
+ inline bool is_bf_column() const { return _is_bf_column; }
+private:
+ int32_t _column_id;
+ FieldType _type;
+ TypeInfo* _type_info;
+ bool _is_key;
+ bool _is_nullable;
+ bool _is_bf_column;
+};
+
+class TabletSchema {
+public:
+ TabletSchema();
+ OLAPStatus init_from_pb(const TabletSchemaPB& schema);
+ size_t get_row_size() const;
+private:
+ std::vector<TabletColumnSchema> _cols;
+ size_t _num_columns;
+ size_t _num_key_columns;
+ size_t _num_null_columns;
+};
+
+} // namespace doris
+
+#endif // DORIS_BE_SRC_OLAP_SCHEMA_H
diff --git a/gensrc/proto/olap_file.proto b/gensrc/proto/olap_file.proto
index 1b460055..360cc26a 100644
--- a/gensrc/proto/olap_file.proto
+++ b/gensrc/proto/olap_file.proto
@@ -55,7 +55,7 @@ message PDelta {
required int64 version_hash = 3;
required int64 creation_time = 4;
repeated SegmentGroupPB segment_group = 5;
- optional DeleteConditionMessage delete_condition = 6;
+ optional DeletePredicatePB delete_condition = 6;
}
enum RowsetTypePB {
@@ -85,7 +85,7 @@ message RowsetMetaPB {
optional int64 index_disk_size = 13;
// column min/max/null flag statistic info
repeated ColumnPruning column_statistics = 14;
- optional DeleteConditionMessage delete_predicate = 15;
+ optional DeletePredicatePB delete_predicate = 15;
optional bool empty = 16;
optional string rowset_path = 17;
// spare field id for future use
@@ -111,7 +111,7 @@ message PPendingDelta {
required int64 transaction_id = 2;
required int64 creation_time = 3;
repeated PendingSegmentGroupPB pending_segment_group = 4;
- optional DeleteConditionMessage delete_condition = 5;
+ optional DeletePredicatePB delete_condition = 5;
}
message PendingSegmentGroupPB {
@@ -144,7 +144,7 @@ enum KeysType {
AGG_KEYS = 2;
}
-message DeleteConditionMessage {
+message DeletePredicatePB {
required int32 version = 1;
repeated string sub_conditions = 2;
}
@@ -164,7 +164,7 @@ message OLAPHeaderMessage {
optional uint32 next_column_unique_id = 10 [default = 0];
optional CompressKind compress_kind = 11 [default = COMPRESS_LZO];
optional uint32 segment_size = 12 [default = 4292870144];
- repeated DeleteConditionMessage delete_data_conditions = 13;
+ repeated DeletePredicatePB delete_data_conditions = 13;
// bloom filter false positive probability
optional double bf_fpp = 14;
optional KeysType keys_type = 15;
@@ -184,9 +184,9 @@ message OLAPHeaderMessage {
}
enum AlterTabletStatePB {
- ALTERING = 0;
- FINISHED = 1;
- FAILED = 2;
+ PB_ALTERING = 0;
+ PB_FINISHED = 1;
+ PB_FAILED = 2;
}
enum AlterTabletTypePB {
@@ -202,9 +202,25 @@ message AlterTabletPB {
optional AlterTabletTypePB alter_type = 5;
}
+enum ColumnType {
+ TINYINT = 0;
+ SMALLINT = 1;
+ INT = 2;
+ BIGINT = 3;
+ LARGEINT = 4;
+ FLOAT = 5;
+ DOUBLE = 6;
+ DECIMAL = 7;
+ CHAR = 8;
+ VARCHAR = 9;
+ HLL = 10;
+ DATE = 11;
+ DATETIME = 12;
+}
+
message ColumnPB {
required int32 column_id = 1;
- required FieldType type = 2;
+ required ColumnType type = 2;
optional bool is_key = 3;
optional bool is_nullable = 4;
optional bytes default_value = 5;
@@ -222,11 +238,11 @@ message TabletSchemaPB {
}
enum TabletStatePB {
- NOTREADY = 0; // under alter table, rollup, clone
- RUNNING = 1;
- TOMBSTONED = 2;
- STOPPED = 3;
- SHUTDOWN = 4;
+ PB_NOTREADY = 0; // under alter table, rollup, clone
+ PB_RUNNING = 1;
+ PB_TOMBSTONED = 2;
+ PB_STOPPED = 3;
+ PB_SHUTDOWN = 4;
}
message TabletMetaPB {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]