139 lines
3.8 KiB
C++
139 lines
3.8 KiB
C++
/**
|
|
* Copyright (c) 2021 OceanBase
|
|
* OceanBase CE is licensed under Mulan PubL v2.
|
|
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
|
* You may obtain a copy of Mulan PubL v2 at:
|
|
* http://license.coscl.org.cn/MulanPubL-2.0
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
* See the Mulan PubL v2 for more details.
|
|
*/
|
|
|
|
#ifndef OB_STORAGE_SUPER_BLOCK_STRUCT_H_
|
|
#define OB_STORAGE_SUPER_BLOCK_STRUCT_H_
|
|
|
|
#include "common/log/ob_log_cursor.h"
|
|
#include "storage/blocksstable/ob_macro_block_id.h"
|
|
|
|
namespace oceanbase
|
|
{
|
|
namespace storage
|
|
{
|
|
struct ObServerSuperBlockHeader final
|
|
{
|
|
public:
|
|
static const int32_t SERVER_SUPER_BLOCK_VERSION = 1;
|
|
static const int64_t OB_MAX_SUPER_BLOCK_SIZE = 64 * 1024;
|
|
|
|
ObServerSuperBlockHeader();
|
|
~ObServerSuperBlockHeader() = default;
|
|
bool is_valid() const;
|
|
void reset();
|
|
TO_STRING_KV(K_(version), K_(magic), K_(body_size), K_(body_crc));
|
|
NEED_SERIALIZE_AND_DESERIALIZE;
|
|
|
|
int32_t version_;
|
|
int32_t magic_;
|
|
int32_t body_size_;
|
|
int32_t body_crc_;
|
|
};
|
|
|
|
struct ServerSuperBlockBody final
|
|
{
|
|
public:
|
|
static const int64_t SUPER_BLOCK_BODY_VERSION = 1;
|
|
|
|
int64_t create_timestamp_; // create timestamp
|
|
int64_t modify_timestamp_; // last modified timestamp
|
|
int64_t macro_block_size_;
|
|
int64_t total_macro_block_count_;
|
|
int64_t total_file_size_;
|
|
|
|
common::ObLogCursor replay_start_point_;
|
|
blocksstable::MacroBlockId tenant_meta_entry_;
|
|
|
|
ServerSuperBlockBody();
|
|
bool is_valid() const;
|
|
void reset();
|
|
|
|
TO_STRING_KV("Type", "ObServerSuperBlockBody",
|
|
K_(create_timestamp),
|
|
K_(modify_timestamp),
|
|
K_(macro_block_size),
|
|
K_(total_macro_block_count),
|
|
K_(total_file_size),
|
|
K_(replay_start_point),
|
|
K_(tenant_meta_entry));
|
|
|
|
OB_UNIS_VERSION(SUPER_BLOCK_BODY_VERSION);
|
|
};
|
|
|
|
struct ObServerSuperBlock final
|
|
{
|
|
public:
|
|
|
|
ObServerSuperBlock();
|
|
~ObServerSuperBlock() = default;
|
|
|
|
// represents an entry to an empty linked list, distinguished with the invalid macro block id
|
|
static const blocksstable::MacroBlockId EMPTY_LIST_ENTRY_BLOCK;
|
|
|
|
bool is_valid() const;
|
|
void reset();
|
|
NEED_SERIALIZE_AND_DESERIALIZE;
|
|
TO_STRING_KV(K_(header), K_(body));
|
|
|
|
OB_INLINE int64_t get_macro_block_size() const
|
|
{
|
|
return body_.macro_block_size_;
|
|
}
|
|
OB_INLINE int64_t get_total_macro_block_count() const
|
|
{
|
|
return body_.total_macro_block_count_;
|
|
}
|
|
OB_INLINE int64_t get_super_block_size() const
|
|
{
|
|
return header_.get_serialize_size() + body_.get_serialize_size();
|
|
}
|
|
int construct_header();
|
|
int format_startup_super_block(const int64_t macro_block_size, const int64_t data_file_size);
|
|
|
|
ObServerSuperBlockHeader header_;
|
|
ServerSuperBlockBody body_;
|
|
};
|
|
|
|
struct ObTenantSuperBlock final
|
|
{
|
|
public:
|
|
static const uint64_t HIDDEN_FLAG_MASK = 0x01;
|
|
|
|
static const int64_t TENANT_SUPER_BLOCK_VERSION = 1;
|
|
ObTenantSuperBlock();
|
|
ObTenantSuperBlock(const uint64_t tenant_id, const bool is_hidden = false);
|
|
~ObTenantSuperBlock() = default;
|
|
void reset();
|
|
bool is_valid() const;
|
|
|
|
TO_STRING_KV(K_(tenant_id),
|
|
K_(replay_start_point),
|
|
K_(ls_meta_entry),
|
|
K_(tablet_meta_entry),
|
|
K_(is_hidden));
|
|
OB_UNIS_VERSION(TENANT_SUPER_BLOCK_VERSION);
|
|
|
|
public:
|
|
uint64_t tenant_id_;
|
|
common::ObLogCursor replay_start_point_;
|
|
blocksstable::MacroBlockId ls_meta_entry_;
|
|
blocksstable::MacroBlockId tablet_meta_entry_;
|
|
bool is_hidden_;
|
|
};
|
|
|
|
#define IS_EMPTY_BLOCK_LIST(entry_block) (entry_block == oceanbase::storage::ObServerSuperBlock::EMPTY_LIST_ENTRY_BLOCK)
|
|
|
|
} // end namespace storage
|
|
} // end namespace oceanbase
|
|
|
|
#endif // OB_STORAGE_SUPER_BLOCK_STRUCT_H_
|