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
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomeObjectConan(ConanFile):
name = "homeobject"
version = "2.2.11"
version = "2.2.12"

homepage = "https://github.com/eBay/HomeObject"
description = "Blob Store built on HomeReplication"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/homestore_backend/hs_blob_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ BlobManager::AsyncResult< blob_id_t > HSHomeObject::_put_blob(ShardInfo const& s
compute_blob_payload_hash(req->blob_header()->hash_algorithm, blob.body.cbytes(), blob_size,
(uint8_t*)blob.user_key.data(), blob.user_key.size(), req->blob_header()->hash,
BlobHeader::blob_max_hash_len);
req->blob_header()->seal();

// Add blob body to the request
req->add_data_sg(std::move(blob.body));
Expand Down Expand Up @@ -360,8 +361,7 @@ HSHomeObject::blob_put_get_blk_alloc_hints(sisl::blob const& header, cintrusive<

auto hs_pg = get_hs_pg(msg_header->pg_id);
if (hs_pg == nullptr) {
LOGW("Received a blob_put on an unknown pg:{}, underlying engine will retry this later",
msg_header->pg_id);
LOGW("Received a blob_put on an unknown pg:{}, underlying engine will retry this later", msg_header->pg_id);
return folly::makeUnexpected(homestore::ReplServiceError::RESULT_NOT_EXIST_YET);
}

Expand Down
45 changes: 43 additions & 2 deletions src/lib/homestore_backend/hs_homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class HSHomeObject : public HomeObjectImpl {
data_type_t type{data_type_t::BLOB_INFO};
};

struct shard_info_superblk : public DataHeader {
struct shard_info_superblk : DataHeader {
ShardInfo info;
homestore::chunk_num_t p_chunk_id;
homestore::chunk_num_t v_chunk_id;
Expand Down Expand Up @@ -301,7 +301,7 @@ class HSHomeObject : public HomeObjectImpl {
#pragma pack(1)
// Every blob payload stored in disk as blob header | blob data | blob metadata(optional) | padding.
// Padding of zeroes is added to make sure the whole payload be aligned to device block size.
struct BlobHeader : public DataHeader {
struct BlobHeader : DataHeader {
static constexpr uint64_t blob_max_hash_len = 32;

enum class HashAlgorithm : uint8_t {
Expand All @@ -312,6 +312,7 @@ class HSHomeObject : public HomeObjectImpl {
};

HashAlgorithm hash_algorithm;
mutable uint8_t header_hash[blob_max_hash_len]{};
uint8_t hash[blob_max_hash_len]{};
shard_id_t shard_id;
blob_id_t blob_id;
Expand All @@ -325,6 +326,46 @@ class HSHomeObject : public HomeObjectImpl {
magic, version, shard_id, blob_size, user_key_size, (uint8_t)hash_algorithm,
spdlog::to_hex(hash, hash + blob_max_hash_len));
}

bool valid() const {
if (!DataHeader::valid()) { return false; }

uint8_t hash_arr[blob_max_hash_len];
std::memcpy(hash_arr, header_hash, blob_max_hash_len);
if (!_do_seal()) {
std::memcpy(header_hash, hash_arr, blob_max_hash_len);
return false;
}

bool hash_valid = std::memcmp(header_hash, hash_arr, blob_max_hash_len) == 0;
std::memcpy(header_hash, hash_arr, blob_max_hash_len);
return hash_valid;
}

void seal() const {
if (!_do_seal()) {
DEBUG_ASSERT(false, "Invalid hash algorithm"); // Not implemented
}
}

private:
bool _do_seal() const {
switch (hash_algorithm) {
case HashAlgorithm::NONE:
return true;
case HashAlgorithm::CRC32: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use the same hash_algorithm between valid and seal , right?
seal is now always using crc32, so other hash_algorithm does not make sense to valid.

I mean can we add a member to indicate the hash_algorithm, and valid and seal will share it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will fix in the next push.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::memset(header_hash, 0, blob_max_hash_len);
uint32_t computed_hash = crc32_ieee(0, (uint8_t*)this, sizeof(BlobHeader));
std::memcpy(header_hash, &computed_hash, sizeof(uint32_t));
return true;
}
case HashAlgorithm::MD5:
case HashAlgorithm::SHA1:
default:
break; // Not implemented
}
return false;
}
};
#pragma pack()

Expand Down
1 change: 1 addition & 0 deletions src/lib/homestore_backend/tests/homeobj_misc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ TEST_F(HomeObjectFixture, SnapshotReceiveHandler) {
reinterpret_cast< uint8_t* >(blob.user_key.data()),
blob.user_key.size(), hdr.hash,
HSHomeObject::BlobHeader::blob_max_hash_len);
hdr.seal();

std::memcpy(blob_raw.bytes(), &hdr, sizeof(HSHomeObject::BlobHeader));
if (!blob.user_key.empty()) {
Expand Down