Skip to content

Commit

Permalink
update ut
Browse files Browse the repository at this point in the history
Signed-off-by: sevev <[email protected]>
  • Loading branch information
sevev committed Sep 24, 2024
1 parent 7f29104 commit 16f0b0d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions be/src/storage/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ class Tablet : public BaseTablet {
void set_is_dropping(bool is_dropping) { _is_dropping = is_dropping; }

[[nodiscard]] bool is_update_schema_running() const { return _update_schema_running.load(); }
void set_update_schema_running(bool is_running) { _update_schema_running.store(is_running); }
std::shared_mutex& get_schema_lock() { return _schema_lock; }
bool add_committed_rowset(const RowsetSharedPtr& rowset);
void erase_committed_rowset(const RowsetSharedPtr& rowset);
Expand Down
2 changes: 0 additions & 2 deletions be/src/storage/txn_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,11 @@ Status TxnManager::commit_txn(KVStore* meta, TPartitionId partition_id, TTransac
bool skip_schema = config::skip_schema_in_rowset_meta &&
!rowset_ptr->rowset_meta()->get_meta_pb_without_schema().has_txn_meta() &&
!tablet->is_update_schema_running();
LOG(INFO) << "skip_schema: " << skip_schema;
if (skip_schema) {
// avoid `update_max_version_schema` and `commit_txn` run concurrency, so hold a read
// lock for `schema_lock` is enough
std::shared_lock l(tablet->get_schema_lock());
skip_schema = tablet->add_committed_rowset(rowset_ptr);
LOG(INFO) << "skip_schema: " << skip_schema;
if (skip_schema) {
rowset_ptr->rowset_meta()->set_skip_tablet_schema(true);
rowset_meta_pb = rowset_ptr->rowset_meta()->get_meta_pb_without_schema();
Expand Down
55 changes: 54 additions & 1 deletion be/test/storage/tablet_updates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3734,7 +3734,7 @@ TEST_F(TabletUpdatesTest, test_drop_tablet_with_keep_meta_and_files) {
TEST_F(TabletUpdatesTest, test_skip_schema) {
int N = 100;
srand(GetCurrentTimeMicros());
_tablet = create_tablet(rand(), rand());
_tablet = create_tablet(rand(), rand(), false, rand(), 0);
std::vector<int64_t> keys;
for (int i = 0; i < N; i++) {
keys.push_back(i);
Expand Down Expand Up @@ -3827,6 +3827,59 @@ TEST_F(TabletUpdatesTest, test_skip_schema) {
ASSERT_EQ(true, parse_ok);
ASSERT_TRUE(rs2_meta.tablet_schema() != nullptr);
}

auto rs3 = create_rowset(_tablet, keys);
ASSERT_EQ(false, rs3->rowset_meta()->skip_tablet_schema());
_tablet->set_update_schema_running(true);
load_id.set_hi(1002);
load_id.set_lo(1002);
ASSERT_TRUE(StorageEngine::instance()
->txn_manager()
->commit_txn(_tablet->data_dir()->get_meta(), 102, 102, _tablet->tablet_id(),
_tablet->schema_hash(), _tablet->tablet_uid(), load_id, rs3, false)
.ok());
ASSERT_EQ(false, rs3->rowset_meta()->skip_tablet_schema());
ASSERT_EQ(0, _tablet->committed_rowset_size());
ASSERT_TRUE(rs3->tablet_schema() != nullptr);
{
std::string meta_value;
ASSERT_TRUE(RowsetMetaManager::get_rowset_meta_value(_tablet->data_dir()->get_meta(), _tablet->tablet_uid(),
rs3->rowset_id(), &meta_value)
.ok());
bool parse_ok = false;
auto rs_meta = RowsetMeta(meta_value, &parse_ok);
ASSERT_EQ(true, parse_ok);
ASSERT_TRUE(rs_meta.tablet_schema() != nullptr);
}
ASSERT_TRUE(StorageEngine::instance()->txn_manager()->publish_txn(102, _tablet, 102, 3, rs3, 0, false).ok());

_tablet->set_update_schema_running(false);
auto rs4 = create_rowset(_tablet, keys);
ASSERT_EQ(false, rs4->rowset_meta()->skip_tablet_schema());
load_id.set_hi(1003);
load_id.set_lo(1003);
ASSERT_TRUE(StorageEngine::instance()
->txn_manager()
->commit_txn(_tablet->data_dir()->get_meta(), 103, 103, _tablet->tablet_id(),
_tablet->schema_hash(), _tablet->tablet_uid(), load_id, rs4, false)
.ok());
ASSERT_EQ(true, rs4->rowset_meta()->skip_tablet_schema());
ASSERT_EQ(1, _tablet->committed_rowset_size());
ASSERT_TRUE(rs4->tablet_schema() != nullptr);

{
auto tmp_tablet = create_tablet(rand(), rand(), false, _tablet->tablet_schema()->id() + 1,
_tablet->tablet_schema()->schema_version() + 1);
auto new_schema = tmp_tablet->tablet_schema();
auto old_schema_id = _tablet->tablet_schema()->id();
_tablet->update_max_version_schema(new_schema);
ASSERT_EQ(0, _tablet->committed_rowset_size());
ASSERT_EQ(false, rs4->rowset_meta()->skip_tablet_schema());
ASSERT_EQ(rs4->tablet_schema()->id(), old_schema_id);
ASSERT_EQ(rs3->tablet_schema()->id(), old_schema_id);
ASSERT_EQ(rs2->tablet_schema()->id(), old_schema_id);
ASSERT_EQ(rs1->tablet_schema()->id(), old_schema_id);
}
}

} // namespace starrocks
6 changes: 4 additions & 2 deletions be/test/storage/tablet_updates_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ class TabletUpdatesTest : public testing::Test {
return *writer->build();
}

TabletSharedPtr create_tablet(int64_t tablet_id, int32_t schema_hash, bool multi_column_pk = false) {
TabletSharedPtr create_tablet(int64_t tablet_id, int32_t schema_hash, bool multi_column_pk = false,
int64_t schema_id = 0, int32_t schema_version = 0) {
srand(GetCurrentTimeMicros());
TCreateTabletReq request;
request.tablet_id = tablet_id;
Expand All @@ -387,7 +388,8 @@ class TabletUpdatesTest : public testing::Test {
request.tablet_schema.short_key_column_count = 1;
request.tablet_schema.keys_type = TKeysType::PRIMARY_KEYS;
request.tablet_schema.storage_type = TStorageType::COLUMN;
request.tablet_schema.__set_id(rand());
request.tablet_schema.__set_id(schema_id);
request.tablet_schema.__set_schema_version(schema_version);

if (multi_column_pk) {
TColumn pk1;
Expand Down

0 comments on commit 16f0b0d

Please sign in to comment.