Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions be/src/olap/rowset/rowset_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "olap/olap_common.h"
#include "google/protobuf/util/message_differencer.h"
#include "json2pb/json_to_pb.h"
#include "json2pb/pb_to_json.h"
#include "common/logging.h"
Expand Down Expand Up @@ -392,6 +393,17 @@ class RowsetMeta {
}
}

friend bool operator==(const RowsetMeta& a, const RowsetMeta& b) {
if (a._rowset_id != b._rowset_id) return false;
if (a._is_removed_from_rowset_meta != b._is_removed_from_rowset_meta) return false;
if (!google::protobuf::util::MessageDifferencer::Equals(a._rowset_meta_pb, b._rowset_meta_pb)) return false;
return true;
}

friend bool operator!=(const RowsetMeta& a, const RowsetMeta& b) {
return !(a == b);
}

private:
RowsetMetaPB _rowset_meta_pb;
RowsetId _rowset_id;
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,8 @@ OLAPStatus TabletManager::_create_tablet_meta_unlocked(const TCreateTabletReq& r
// TODO(lingbin): when beta-rowset is default, should remove it
if (request.__isset.storage_format && request.storage_format == TStorageFormat::V2) {
(*tablet_meta)->set_preferred_rowset_type(BETA_ROWSET);
} else {
(*tablet_meta)->set_preferred_rowset_type(ALPHA_ROWSET);
}
return res;
}
Expand Down
42 changes: 42 additions & 0 deletions be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,46 @@ OLAPStatus TabletMeta::set_partition_id(int64_t partition_id) {
return OLAP_SUCCESS;
}

bool operator==(const AlterTabletTask& a, const AlterTabletTask& b) {
if (a._alter_state != b._alter_state) return false;
if (a._related_tablet_id != b._related_tablet_id) return false;
if (a._related_schema_hash != b._related_schema_hash) return false;
if (a._alter_type != b._alter_type) return false;
return true;
}

bool operator!=(const AlterTabletTask& a, const AlterTabletTask& b) {
return !(a == b);
}

bool operator==(const TabletMeta& a, const TabletMeta& b) {
if (a._table_id != b._table_id) return false;
if (a._partition_id != b._partition_id) return false;
if (a._tablet_id != b._tablet_id) return false;
if (a._schema_hash != b._schema_hash) return false;
if (a._shard_id != b._shard_id) return false;
if (a._creation_time != b._creation_time) return false;
if (a._cumulative_layer_point != b._cumulative_layer_point) return false;
if (a._tablet_uid != b._tablet_uid) return false;
if (a._tablet_type != b._tablet_type) return false;
if (a._tablet_state != b._tablet_state) return false;
if (a._schema != b._schema) return false;
if (a._rs_metas.size() != b._rs_metas.size()) return false;
for (int i = 0; i < a._rs_metas.size(); ++i) {
if (a._rs_metas[i] != b._rs_metas[i]) return false;
}
if (a._inc_rs_metas.size() != b._inc_rs_metas.size()) return false;
for (int i = 0; i < a._inc_rs_metas.size(); ++i) {
if (a._inc_rs_metas[i] != b._inc_rs_metas[i]) return false;
}
if (a._alter_task != b._alter_task) return false;
if (a._in_restore_mode != b._in_restore_mode) return false;
if (a._preferred_rowset_type != b._preferred_rowset_type) return false;
return true;
}

bool operator!=(const TabletMeta& a, const TabletMeta& b) {
return !(a == b);
}

} // namespace doris
24 changes: 19 additions & 5 deletions be/src/olap/tablet_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,19 @@ class AlterTabletTask {
inline const AlterTabletType& alter_type() const { return _alter_type; }
inline void set_alter_type(AlterTabletType alter_type) { _alter_type = alter_type; }

friend bool operator==(const AlterTabletTask& a, const AlterTabletTask& b);
friend bool operator!=(const AlterTabletTask& a, const AlterTabletTask& b);

private:
AlterTabletState _alter_state;
int64_t _related_tablet_id;
int32_t _related_schema_hash;
AlterTabletType _alter_type;
AlterTabletState _alter_state = ALTER_PREPARED;
int64_t _related_tablet_id = 0;
int32_t _related_schema_hash = 0;
AlterTabletType _alter_type = SCHEMA_CHANGE;
};

bool operator==(const AlterTabletTask& a, const AlterTabletTask& b);
bool operator!=(const AlterTabletTask& a, const AlterTabletTask& b);

typedef std::shared_ptr<AlterTabletTask> AlterTabletTaskSharedPtr;

// Class encapsulates meta of tablet.
Expand Down Expand Up @@ -196,6 +202,10 @@ class TabletMeta {
private:
OLAPStatus _save_meta(DataDir* data_dir);

// _del_pred_array is ignored to compare.
friend bool operator==(const TabletMeta& a, const TabletMeta& b);
friend bool operator!=(const TabletMeta& a, const TabletMeta& b);

private:
int64_t _table_id = 0;
int64_t _partition_id = 0;
Expand All @@ -214,7 +224,7 @@ class TabletMeta {
DelPredicateArray _del_pred_array;
AlterTabletTaskSharedPtr _alter_task;
bool _in_restore_mode = false;
RowsetTypePB _preferred_rowset_type;
RowsetTypePB _preferred_rowset_type = ALPHA_ROWSET;

RWMutex _meta_lock;
};
Expand Down Expand Up @@ -315,6 +325,10 @@ inline const std::vector<RowsetMetaSharedPtr>& TabletMeta::all_inc_rs_metas() co
return _inc_rs_metas;
}

// Only for unit test now.
bool operator==(const TabletMeta& a, const TabletMeta& b);
bool operator!=(const TabletMeta& a, const TabletMeta& b);

} // namespace doris

#endif // DORIS_BE_SRC_OLAP_OLAP_TABLET_META_H
67 changes: 61 additions & 6 deletions be/src/olap/tablet_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,12 @@ void TabletColumn::to_schema_pb(ColumnPB* column) {
}
}

TabletSchema::TabletSchema()
: _num_columns(0),
_num_key_columns(0),
_num_null_columns(0),
_num_short_key_columns(0) { }

void TabletSchema::init_from_pb(const TabletSchemaPB& schema) {
_keys_type = schema.keys_type();
_num_columns = 0;
_num_key_columns = 0;
_num_null_columns = 0;
_cols.clear();
for (auto& column_pb : schema.column()) {
TabletColumn column;
column.init_from_pb(column_pb);
Expand Down Expand Up @@ -420,4 +418,61 @@ const TabletColumn& TabletSchema::column(size_t ordinal) const {
return _cols[ordinal];
}

bool operator==(const TabletColumn& a, const TabletColumn& b) {
if (a._unique_id != b._unique_id) return false;
if (a._col_name != b._col_name) return false;
if (a._type != b._type) return false;
if (a._is_key != b._is_key) return false;
if (a._aggregation != b._aggregation) return false;
if (a._is_nullable != b._is_nullable) return false;
if (a._has_default_value != b._has_default_value) return false;
if (a._has_default_value) {
if (a._default_value != b._default_value) return false;
}
if (a._is_decimal != b._is_decimal) return false;
if (a._is_decimal) {
if (a._precision != b._precision) return false;
if (a._frac != b._frac) return false;
}
if (a._length != b._length) return false;
if (a._index_length != b._index_length) return false;
if (a._is_bf_column != b._is_bf_column) return false;
if (a._has_referenced_column != b._has_referenced_column) return false;
if (a._has_referenced_column) {
if (a._referenced_column_id != b._referenced_column_id) return false;
if (a._referenced_column != b._referenced_column) return false;
}
if (a._has_bitmap_index != b._has_bitmap_index) return false;
return true;
}

bool operator!=(const TabletColumn& a, const TabletColumn& b) {
return !(a == b);
}

bool operator==(const TabletSchema& a, const TabletSchema& b) {
if (a._keys_type != b._keys_type) return false;
if (a._cols.size() != b._cols.size()) return false;
for (int i = 0; i < a._cols.size(); ++i) {
if (a._cols[i] != b._cols[i]) return false;
}
if (a._num_columns != b._num_columns) return false;
if (a._num_key_columns != b._num_key_columns) return false;
if (a._num_null_columns != b._num_null_columns) return false;
if (a._num_short_key_columns != b._num_short_key_columns) return false;
if (a._num_rows_per_row_block != b._num_rows_per_row_block) return false;
if (a._compress_kind != b._compress_kind) return false;
if (a._next_column_unique_id != b._next_column_unique_id) return false;
if (a._has_bf_fpp != b._has_bf_fpp) return false;
if (a._has_bf_fpp) {
if (std::abs(a._bf_fpp - b._bf_fpp) > 1e-6) return false;
}
if (a._is_in_memory != b._is_in_memory) return false;
return true;
}

bool operator!=(const TabletSchema& a, const TabletSchema& b) {
return !(a == b);
}

} // namespace doris
32 changes: 23 additions & 9 deletions be/src/olap/tablet_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class TabletColumn {
int precision() const { return _precision; }
int frac() const { return _frac; }

friend bool operator==(const TabletColumn& a, const TabletColumn& b);
friend bool operator!=(const TabletColumn& a, const TabletColumn& b);

static std::string get_string_by_field_type(FieldType type);
static std::string get_string_by_aggregation_type(FieldAggregationMethod aggregation_type);
static FieldType get_field_type_by_string(const std::string& str);
Expand Down Expand Up @@ -85,9 +88,12 @@ class TabletColumn {
bool _has_bitmap_index = false;
};

bool operator==(const TabletColumn& a, const TabletColumn& b);
bool operator!=(const TabletColumn& a, const TabletColumn& b);

class TabletSchema {
public:
TabletSchema();
TabletSchema() = default;
void init_from_pb(const TabletSchemaPB& schema);
void to_schema_pb(TabletSchemaPB* tablet_meta_pb);
size_t row_size() const;
Expand All @@ -107,22 +113,30 @@ class TabletSchema {
inline void set_is_in_memory (bool is_in_memory) {
_is_in_memory = is_in_memory;
}

private:
KeysType _keys_type;
friend bool operator==(const TabletSchema& a, const TabletSchema& b);
friend bool operator!=(const TabletSchema& a, const TabletSchema& b);

private:
KeysType _keys_type = DUP_KEYS;
std::vector<TabletColumn> _cols;
size_t _num_columns;
size_t _num_key_columns;
size_t _num_null_columns;
size_t _num_short_key_columns;
size_t _num_rows_per_row_block;
CompressKind _compress_kind;
size_t _next_column_unique_id;
size_t _num_columns = 0;
size_t _num_key_columns = 0;
size_t _num_null_columns = 0;
size_t _num_short_key_columns = 0;
size_t _num_rows_per_row_block = 0;
CompressKind _compress_kind = COMPRESS_NONE;
size_t _next_column_unique_id = 0;

bool _has_bf_fpp = false;
double _bf_fpp = 0;
bool _is_in_memory = false;
};

bool operator==(const TabletSchema& a, const TabletSchema& b);
bool operator!=(const TabletSchema& a, const TabletSchema& b);

} // namespace doris

#endif // DORIS_BE_SRC_OLAP_TABLET_SCHEMA_H
4 changes: 2 additions & 2 deletions be/src/util/uid_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ inline void from_hex(T* ret, const std::string& buf) {
}

struct UniqueId {
int64_t hi;
int64_t lo;
int64_t hi = 0;
int64_t lo = 0;

UniqueId(int64_t hi_, int64_t lo_) : hi(hi_), lo(lo_) { }
UniqueId(const TUniqueId& tuid) : hi(tuid.hi), lo(tuid.lo) { }
Expand Down
1 change: 1 addition & 0 deletions be/test/olap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ADD_BE_TEST(rowset/segment_v2/frame_of_reference_page_test)
ADD_BE_TEST(rowset/segment_v2/block_bloom_filter_test)
ADD_BE_TEST(rowset/segment_v2/bloom_filter_index_reader_writer_test)
ADD_BE_TEST(rowset/segment_v2/zone_map_index_test)
ADD_BE_TEST(tablet_meta_test)
ADD_BE_TEST(tablet_meta_manager_test)
ADD_BE_TEST(tablet_mgr_test)
ADD_BE_TEST(rowset/rowset_meta_manager_test)
Expand Down
48 changes: 48 additions & 0 deletions be/test/olap/tablet_meta_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 <string>

#include <gtest/gtest.h>

#include "olap/tablet_meta.h"

namespace doris {

TEST(TabletMetaTest, SaveAndParse) {
std::string meta_path = "./be/test/olap/test_data/tablet_meta_test.hdr";

TabletMeta old_tablet_meta(1, 2, 3, 4, 5, TTabletSchema(), 6, {{7, 8}}, UniqueId(9, 10), TTabletType::TABLET_TYPE_DISK);
ASSERT_EQ(OLAP_SUCCESS, old_tablet_meta.save(meta_path));

{
// Just to make stack space dirty
TabletMeta new_tablet_meta;
new_tablet_meta._preferred_rowset_type = BETA_ROWSET;
}
TabletMeta new_tablet_meta;
new_tablet_meta.create_from_file(meta_path);

ASSERT_EQ(old_tablet_meta, new_tablet_meta);
}

} // namespace doris

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}