Skip to content

Commit

Permalink
handle comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwmao committed Nov 5, 2024
1 parent 1192443 commit 10f102f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
4 changes: 3 additions & 1 deletion src/lib/homestore_backend/hs_homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class HSHomeObject : public HomeObjectImpl {
ShardInfo info;
homestore::chunk_num_t chunk_id;
};

//TODO this blk is used to store snapshot metadata/status for recovery
struct snapshot_info_superblk {};
#pragma pack()

Expand Down Expand Up @@ -319,6 +319,8 @@ class HSHomeObject : public HomeObjectImpl {
void process_shard_snapshot_data(ResyncShardMetaData const& shard_meta, snp_obj_id_t& obj_id);
void process_blobs_snapshot_data(ResyncBlobDataBatch const& data_blob, snp_obj_id_t& obj_id);

//snapshot start lsn
int64_t lsn{0};
shard_id_t shard_cursor{0};
blob_id_t blob_cursor{0};
snp_batch_id_t cur_batch_num{0};
Expand Down
47 changes: 29 additions & 18 deletions src/lib/homestore_backend/replication_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,33 @@ VENUM(SyncMessageType, uint16_t, PG_META = 0, SHARD_META = 1, SHARD_BATCH = 2,

// magic num comes from the first 8 bytes of 'echo homeobject_replication | md5sum'
static constexpr uint64_t HOMEOBJECT_REPLICATION_MAGIC = 0x11153ca24efc8d34;
// magic num comes from the first 8 bytes of 'echo homeobject_resync | md5sum'
static constexpr uint64_t HOMEOBJECT_RESYNC_MAGIC = 0xbb6813cb4a339f30;
static constexpr uint32_t HOMEOBJECT_REPLICATION_PROTOCOL_VERSION_V1 = 0x01;
static constexpr uint32_t HOMEOBJECT_RESYNC_PROTOCOL_VERSION_V1 = 0x01;
static constexpr uint32_t init_crc32 = 0;
static constexpr uint64_t LAST_OBJ_ID =ULLONG_MAX;

#pragma pack(1)
template<typename Header>
struct BaseMessageHeader {
uint64_t magic_num{HOMEOBJECT_REPLICATION_MAGIC};
uint32_t protocol_version;
uint32_t payload_size;
uint32_t payload_crc;
mutable uint32_t header_crc;
uint8_t reserved_pad[4]{};

virtual uint32_t expected_protocol_version() const = 0;

void seal() {
header_crc = 0;
header_crc = calculate_crc();
}

uint32_t calculate_crc() const {
return crc32_ieee(init_crc32, reinterpret_cast<const unsigned char*>(this), sizeof(*this));
const auto* hdr=static_cast<const Header*>(this);
return crc32_ieee(init_crc32, reinterpret_cast<const unsigned char*>(hdr), sizeof(*hdr));
}

bool corrupted() const {
if (magic_num != HOMEOBJECT_REPLICATION_MAGIC || protocol_version != expected_protocol_version()) {
return true;
}

auto saved_crc = header_crc;
header_crc = 0;
bool is_corrupted = (saved_crc != calculate_crc());
Expand All @@ -59,14 +56,21 @@ struct BaseMessageHeader {
}
};

struct ReplicationMessageHeader : public BaseMessageHeader{
uint32_t protocol_version{HOMEOBJECT_REPLICATION_PROTOCOL_VERSION_V1};
ReplicationMessageType msg_type; // message type
struct ReplicationMessageHeader : public BaseMessageHeader<ReplicationMessageHeader>{
ReplicationMessageHeader(): BaseMessageHeader() {
magic_num = HOMEOBJECT_REPLICATION_MAGIC;
protocol_version = HOMEOBJECT_REPLICATION_PROTOCOL_VERSION_V1;
}
ReplicationMessageType msg_type;
pg_id_t pg_id{0};
uint8_t reserved_pad[4]{};
shard_id_t shard_id{0};

uint32_t expected_protocol_version() const override {
return HOMEOBJECT_REPLICATION_PROTOCOL_VERSION_V1; // Specific version for sync messages
bool corrupted() const{
if (magic_num != HOMEOBJECT_REPLICATION_MAGIC || protocol_version != HOMEOBJECT_REPLICATION_PROTOCOL_VERSION_V1) {
return true;
}
return BaseMessageHeader::corrupted();
}

std::string to_string() const {
Expand All @@ -76,12 +80,19 @@ struct ReplicationMessageHeader : public BaseMessageHeader{
}
};

struct SyncMessageHeader : public BaseMessageHeader {
uint32_t protocol_version{HOMEOBJECT_RESYNC_PROTOCOL_VERSION_V1};
SyncMessageType msg_type; // message type
struct SyncMessageHeader : public BaseMessageHeader<SyncMessageHeader> {
SyncMessageHeader() : BaseMessageHeader() {
magic_num = HOMEOBJECT_RESYNC_MAGIC;
protocol_version = HOMEOBJECT_RESYNC_PROTOCOL_VERSION_V1;
}
SyncMessageType msg_type;
uint8_t reserved_pad[6]{};

uint32_t expected_protocol_version() const override {
return HOMEOBJECT_RESYNC_PROTOCOL_VERSION_V1; // Specific version for sync messages
bool corrupted() const{
if (magic_num != HOMEOBJECT_RESYNC_MAGIC || protocol_version != HOMEOBJECT_RESYNC_PROTOCOL_VERSION_V1) {
return true;
}
return BaseMessageHeader::corrupted();
}

std::string to_string() const {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/homestore_backend/resync_blob_data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace homeobject;
table ResyncBlobData {
blob_id : uint64;
is_deleted: bool;
data : [ubyte]; // Raw blob data loaded from drive, include BlobHeader, user_key and payload
data : [ubyte]; // Raw blob data loaded from drive, include BlobHeader, user_key and payload
}

table ResyncBlobDataBatch {
blob_list : [ResyncBlobData]; // List of blobs in the batch
is_last_batch: bool; // Is the last batch of the shard?
blob_list : [ResyncBlobData]; // List of blobs in the batch
is_last_batch: bool; // Is the last batch of the shard
}

// ResyncBlobData schema is the batch message in data resync
Expand Down
18 changes: 9 additions & 9 deletions src/lib/homestore_backend/resync_pg_data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ native_include "sisl/utility/non_null_ptr.hpp";
namespace homeobject;

table Member {
uuid : [ubyte];
name : [ubyte];
priority: int;
uuid : [ubyte];
name : [ubyte];
priority: int;
}

table ResyncPGMetaData {
pg_id : uint16; // only low 16 bit is used for pg_id;
replica_set_uuid : [ubyte]; // uuid of replica set
blob_seq_num : uint64; // blob sequence number, used to assign next blob id;
shard_seq_num: uint64; // shard sequence number, used to assign next shard id;
members : [Member]; // peers;
shard_ids : [uint64]; // shard ids to transmit;
pg_id : uint16; // only low 16 bit is used for pg_id;
replica_set_uuid : [ubyte]; // uuid of replica set
blob_seq_num : uint64; // blob sequence number, used to assign next blob id;
shard_seq_num: uint64; // shard sequence number, used to assign next shard id;
members : [Member]; // peers;
shard_ids : [uint64]; // shard ids to transmit;
}

// ResyncPGMetaData schema is the first message(ObjID=0) in the resync data stream
Expand Down
16 changes: 8 additions & 8 deletions src/lib/homestore_backend/resync_shard_data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ native_include "sisl/utility/non_null_ptr.hpp";
namespace homeobject;

table ResyncShardMetaData {
shard_id : uint64; // shard id to be created with;
pg_id : uint16; // pg id which this shard belongs to;
state : ubyte; // shard state;
created_lsn : uint64; // lsn on shard creation;
created_time : uint64; // shard creation time
last_modified_time : ulong; // shard last modify time
total_capacity_bytes : ulong; // total capacity of the shard
vchunk_id : uint16; // vchunk id
shard_id : uint64; // shard id to be created with;
pg_id : uint16; // pg id which this shard belongs to;
state : ubyte; // shard state;
created_lsn : uint64; // lsn on shard creation;
created_time : uint64; // shard creation time
last_modified_time : ulong; // shard last modify time
total_capacity_bytes : ulong; // total capacity of the shard
vchunk_id : uint16; // vchunk id
}

//ShardMetaData schema is the first batch(batch=0) in the shard transmission
Expand Down

0 comments on commit 10f102f

Please sign in to comment.