add some small sstable operations tools
This commit is contained in:
@ -101,7 +101,7 @@ TEST_F(TestSharedMacroBlk, test_rebuild_sstable)
|
||||
// rebuild sstable
|
||||
tablet_handle.get_obj()->tablet_meta_.snapshot_version_ = 12;
|
||||
ASSERT_EQ(OB_SUCCESS, shared_blk_mgr->rebuild_sstable(
|
||||
*(tablet_handle.get_obj()), sstable_, *sstable_index_builder, *index_block_rebuilder, table_handle));
|
||||
*(tablet_handle.get_obj()), sstable_, 0, *sstable_index_builder, *index_block_rebuilder, table_handle));
|
||||
ASSERT_EQ(OB_SUCCESS, table_handle.get_sstable(sstable));
|
||||
ASSERT_EQ(true, sstable_.meta_.basic_meta_ == sstable->meta_.basic_meta_);
|
||||
|
||||
|
||||
@ -458,14 +458,14 @@ void ObSSTableDataBlockReader::reset()
|
||||
is_inited_ = false;
|
||||
}
|
||||
|
||||
int ObSSTableDataBlockReader::dump()
|
||||
int ObSSTableDataBlockReader::dump(const uint64_t tablet_id, const int64_t scn)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObSSTableDataBlockReader is not inited", K(ret));
|
||||
} else {
|
||||
} else if (check_need_print(tablet_id, scn)) {
|
||||
ObSSTablePrinter::print_common_header(&common_header_);
|
||||
switch (common_header_.get_type()) {
|
||||
case ObMacroBlockCommonHeader::SSTableData:
|
||||
@ -504,6 +504,19 @@ int ObSSTableDataBlockReader::dump()
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObSSTableDataBlockReader::check_need_print(const uint64_t tablet_id, const int64_t scn)
|
||||
{
|
||||
bool need_print = true;
|
||||
if (ObMacroBlockCommonHeader::SSTableData == common_header_.get_type()) {
|
||||
if ((0 != tablet_id && tablet_id != macro_header_.fixed_header_.tablet_id_)
|
||||
|| (-1 != scn && scn != macro_header_.fixed_header_.logical_version_)) {
|
||||
// tablet id or logical version doesn't match, skip print
|
||||
need_print = false;
|
||||
}
|
||||
}
|
||||
return need_print;
|
||||
}
|
||||
|
||||
int ObSSTableDataBlockReader::dump_sstable_macro_block(const bool is_index_block)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
|
||||
int init(const char *data, const int64_t size, const bool hex_print = false);
|
||||
void reset();
|
||||
int dump();
|
||||
int dump(const uint64_t tablet_id, const int64_t scn);
|
||||
private:
|
||||
int dump_sstable_macro_block(const bool is_index_block);
|
||||
int dump_bloom_filter_data_block();
|
||||
@ -129,6 +129,7 @@ private:
|
||||
ObMacroBlockRowBareIterator ¯o_bare_iter);
|
||||
int dump_sstable_micro_data(const ObMicroBlockData µ_data, const bool is_index_block);
|
||||
int dump_column_info(const int64_t col_cnt);
|
||||
bool check_need_print(const uint64_t tablet_id, const int64_t scn);
|
||||
private:
|
||||
// raw data
|
||||
const char *data_;
|
||||
|
||||
@ -458,9 +458,12 @@ int ObSharedMacroBlockMgr::update_tablet(
|
||||
ObSArray<ObTableHandleV2> table_handles;
|
||||
ObTableHandleV2 sstable_handle;
|
||||
ObSArray<ObITable *> sstables;
|
||||
uint64_t data_version = 0;
|
||||
|
||||
if (OB_FAIL(tablet_handle.get_obj()->get_all_sstables(sstables))) {
|
||||
LOG_WARN("fail to get sstables of this tablet", K(ret));
|
||||
} else if (OB_FAIL(GET_MIN_DATA_VERSION(MTL_ID(), data_version))) {
|
||||
LOG_WARN("fail to get data version", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; i < sstables.count() && OB_SUCC(ret); i++) {
|
||||
const ObSSTable *sstable = static_cast<ObSSTable *>(sstables.at(i));
|
||||
@ -476,6 +479,7 @@ int ObSharedMacroBlockMgr::update_tablet(
|
||||
if (OB_FAIL(rebuild_sstable(
|
||||
*(tablet_handle.get_obj()),
|
||||
*sstable,
|
||||
data_version,
|
||||
sstable_index_builder,
|
||||
index_block_rebuilder,
|
||||
sstable_handle))) {
|
||||
@ -514,6 +518,7 @@ int ObSharedMacroBlockMgr::update_tablet(
|
||||
int ObSharedMacroBlockMgr::rebuild_sstable(
|
||||
const ObTablet &tablet,
|
||||
const ObSSTable &old_sstable,
|
||||
const uint64_t data_version,
|
||||
ObSSTableIndexBuilder &sstable_index_builder,
|
||||
ObIndexBlockRebuilder &index_block_rebuilder,
|
||||
ObTableHandleV2 &table_handle)
|
||||
@ -538,7 +543,7 @@ int ObSharedMacroBlockMgr::rebuild_sstable(
|
||||
old_sstable.get_meta().get_basic_meta(),
|
||||
merge_type,
|
||||
tablet.get_snapshot_version(),
|
||||
GET_MIN_CLUSTER_VERSION(),
|
||||
data_version,
|
||||
data_desc))) {
|
||||
LOG_WARN("fail to prepare data desc", K(ret), K(merge_type), K(tablet.get_snapshot_version()));
|
||||
} else if (OB_FAIL(sstable_index_builder.init(data_desc, nullptr, ObSSTableIndexBuilder::DISABLE))) {
|
||||
@ -569,6 +574,8 @@ int ObSharedMacroBlockMgr::rebuild_sstable(
|
||||
|| OB_FAIL(ObSSTableMetaChecker::check_sstable_meta_strict_equality(old_sstable.get_meta(), new_sstable->get_meta()))) {
|
||||
ret = OB_INVALID_DATA;
|
||||
LOG_WARN("new sstable is not equal to old sstable", K(ret), KPC(new_sstable), K(old_sstable));
|
||||
} else {
|
||||
FLOG_INFO("successfully rebuild one sstable", K(ret), K(block_info), K(new_sstable->get_key()), K(new_sstable->get_meta()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -135,6 +135,7 @@ private:
|
||||
int rebuild_sstable(
|
||||
const ObTablet &tablet,
|
||||
const ObSSTable &old_sstable,
|
||||
const uint64_t data_version,
|
||||
ObSSTableIndexBuilder &sstable_index_builder,
|
||||
ObIndexBlockRebuilder &index_block_rebuilder,
|
||||
ObTableHandleV2 &table_handle);
|
||||
|
||||
@ -137,7 +137,7 @@ int ObAdminDumpsstExecutor::parse_cmd(int argc, char *argv[])
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
int opt = 0;
|
||||
const char* opt_string = "d:hf:a:i:n:qxk:m:";
|
||||
const char* opt_string = "d:hf:a:i:n:qxk:m:t:s:";
|
||||
|
||||
struct option longopts[] = {
|
||||
// commands
|
||||
@ -151,7 +151,9 @@ int ObAdminDumpsstExecutor::parse_cmd(int argc, char *argv[])
|
||||
{ "quiet", 0, NULL, 'q' },
|
||||
{ "hex-print", 0, NULL, 'x' },
|
||||
{ "master_key", 1, NULL, 'k'},
|
||||
{ "master_key_id", 1, NULL, 'm'}
|
||||
{ "master_key_id", 1, NULL, 'm'},
|
||||
{ "tablet_id", 1, NULL, 't'},
|
||||
{ "scn", 1, NULL, 's'}
|
||||
};
|
||||
|
||||
int index = -1;
|
||||
@ -209,6 +211,14 @@ int ObAdminDumpsstExecutor::parse_cmd(int argc, char *argv[])
|
||||
key_hex_str_ = optarg;
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
dump_macro_context_.tablet_id_ = strtoll(optarg, NULL, 10);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
dump_macro_context_.scn_ = strtoll(optarg, NULL, 10);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
print_usage();
|
||||
exit(1);
|
||||
@ -238,9 +248,10 @@ int ObAdminDumpsstExecutor::dump_single_macro_block(const char* buf, const int64
|
||||
STORAGE_LOG(ERROR, "invalid argument", K(ret), KP(buf), K(size));
|
||||
} else if (OB_FAIL(macro_reader.init(buf, size, hex_print_))) {
|
||||
STORAGE_LOG(ERROR, "failed to init macro reader", K(ret), KP(buf), K(size));
|
||||
} else if (OB_FAIL(macro_reader.dump())) {
|
||||
STORAGE_LOG(ERROR, "failed dump macro block", K(ret), KP(buf), K(size));
|
||||
} else if (OB_FAIL(macro_reader.dump(dump_macro_context_.tablet_id_, dump_macro_context_.scn_))) {
|
||||
STORAGE_LOG(ERROR, "failed dump macro block", K(ret), KP(buf), K(size), K(dump_macro_context_));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -337,9 +348,13 @@ void ObAdminDumpsstExecutor::print_usage()
|
||||
printf(HELP_FMT, "-x,--hex-print", "print obj value in hex mode");
|
||||
printf(HELP_FMT, "-k,--master_key", "master key, hex str");
|
||||
printf(HELP_FMT, "-m,--master_key_id", "master key id");
|
||||
printf(HELP_FMT, "-t,--tablet_id", "tablet id");
|
||||
printf(HELP_FMT, "-s,--logical_version", "macro block logical version");
|
||||
printf("samples:\n");
|
||||
printf(" dump all rows in macro: \n");
|
||||
printf("\tob_admin -d macro_block -f block_file_path -a macro_id\n");
|
||||
printf(" dump specified block in the shared block: \n");
|
||||
printf("\tob_admin -d macro_block -f block_file_path -a macro_id -t tablet_id -s logical_version\n");
|
||||
}
|
||||
} //namespace tools
|
||||
} //namespace oceanbase
|
||||
|
||||
@ -38,14 +38,16 @@ struct ObDumpMacroBlockContext final
|
||||
{
|
||||
public:
|
||||
ObDumpMacroBlockContext()
|
||||
: first_id_(-1), second_id_(-1), micro_id_(-1)
|
||||
: first_id_(-1), second_id_(-1), micro_id_(-1), tablet_id_(0), scn_(-1)
|
||||
{}
|
||||
~ObDumpMacroBlockContext() = default;
|
||||
bool is_valid() const { return second_id_ >= 0; }
|
||||
TO_STRING_KV(K(first_id_), K(second_id_), K(micro_id_));
|
||||
TO_STRING_KV(K(first_id_), K(second_id_), K(micro_id_), K_(tablet_id), K_(scn));
|
||||
uint64_t first_id_;
|
||||
int64_t second_id_;
|
||||
int64_t micro_id_;
|
||||
uint64_t tablet_id_;
|
||||
int64_t scn_;
|
||||
};
|
||||
|
||||
class ObAdminDumpsstExecutor : public ObAdminExecutor
|
||||
|
||||
Reference in New Issue
Block a user