-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDSTOR-11601 add create_shard implementation
- Loading branch information
1 parent
1272ed1
commit 9945e64
Showing
11 changed files
with
327 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <sisl/utility/enum.hpp> | ||
#include <isa-l/crc.h> | ||
|
||
namespace homeobject { | ||
|
||
ENUM(ReplicationMessageType, uint16_t, PG_MESSAGE = 0, SHARD_MESSAGE, BLOB_MESSAGE, UNKNOWN_MESSAGE); | ||
|
||
// magic num comes from the first 8 bytes of 'echo homeobject_replication | md5sum' | ||
static constexpr uint64_t HOMEOBJECT_REPLICATION_MAGIC = 0x11153ca24efc8d34; | ||
|
||
struct ReplicationMessageHeader { | ||
uint64_t magic_num{HOMEOBJECT_REPLICATION_MAGIC}; | ||
ReplicationMessageType message_type; | ||
uint32_t message_size; | ||
uint32_t message_crc; | ||
uint8_t reserved_pad[2]{}; | ||
uint32_t header_crc; | ||
uint32_t calculate_crc() const { | ||
return crc32_ieee(0, r_cast<const unsigned char*>(this), sizeof(*this) - sizeof(header_crc)); | ||
} | ||
}; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "replication_state_machine.hpp" | ||
#include "homeobject_impl.hpp" | ||
|
||
namespace homeobject { | ||
|
||
void ReplicationStateMachine::on_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key, | ||
blkid_list_t const& blkids,void* ctx) { | ||
const ReplicationMessageHeader* msg_header = r_cast<const ReplicationMessageHeader*>(header.bytes); | ||
//TODO: read data from pba or get data from replication context(prefered) | ||
sisl::sg_list value; | ||
|
||
switch (msg_header->message_type) { | ||
case SHARD_MESSAGE: { | ||
home_object->on_shard_message_commit(lsn, header, key, value, ctx); | ||
} | ||
case PG_MESSAGE: | ||
case BLOB_MESSAGE: | ||
default: { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void ReplicationStateMachine::on_pre_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key, void* ctx) {} | ||
|
||
void ReplicationStateMachine::on_rollback(int64_t lsn, sisl::blob const& header, sisl::blob const& key, void* ctx) {} | ||
|
||
blk_alloc_hints ReplicationStateMachine::get_blk_alloc_hints(sisl::blob const& header) { | ||
return blk_alloc_hints(); | ||
} | ||
|
||
void ReplicationStateMachine::on_replica_stop() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
|
||
#include "homestore/replication/repl_dev.h" | ||
|
||
|
||
namespace homeobject { | ||
|
||
class HomeObjectImpl; | ||
|
||
class ReplicationStateMachine : public homestore::ReplicaDevListener { | ||
public: | ||
/// @brief Called when the log entry has been committed in the replica set. | ||
/// | ||
/// This function is called from a dedicated commit thread which is different from the original thread calling | ||
/// replica_set::write(). There is only one commit thread, and lsn is guaranteed to be monotonically increasing. | ||
/// | ||
/// @param lsn - The log sequence number | ||
/// @param header - Header originally passed with replica_set::write() api | ||
/// @param key - Key originally passed with replica_set::write() api | ||
/// @param pbas - List of pbas where data is written to the storage engine. | ||
/// @param ctx - User contenxt passed as part of the replica_set::write() api | ||
/// | ||
virtual void on_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key, blkid_list_t const& blkids, | ||
void* ctx); | ||
|
||
/// @brief Called when the log entry has been received by the replica dev. | ||
/// | ||
/// On recovery, this is called from a random worker thread before the raft server is started. It is | ||
/// guaranteed to be serialized in log index order. | ||
/// | ||
/// On the leader, this is called from the same thread that replica_set::write() was called. | ||
/// | ||
/// On the follower, this is called when the follower has received the log entry. It is guaranteed to be serialized | ||
/// in log sequence order. | ||
/// | ||
/// NOTE: Listener can choose to ignore this pre commit, however, typical use case of maintaining this is in-case | ||
/// replica set needs to support strong consistent reads and follower needs to ignore any keys which are not being | ||
/// currently in pre-commit, but yet to be committed. | ||
/// | ||
/// @param lsn - The log sequence number | ||
/// @param header - Header originally passed with replica_set::write() api | ||
/// @param key - Key originally passed with replica_set::write() api | ||
/// @param ctx - User contenxt passed as part of the replica_set::write() api | ||
virtual void on_pre_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key, void* ctx); | ||
|
||
/// @brief Called when the log entry has been rolled back by the replica set. | ||
/// | ||
/// This function is called on followers only when the log entry is going to be overwritten. This function is called | ||
/// from a random worker thread, but is guaranteed to be serialized. | ||
/// | ||
/// For each log index, it is guaranteed that either on_commit() or on_rollback() is called but not both. | ||
/// | ||
/// NOTE: Listener should do the free any resources created as part of pre-commit. | ||
/// | ||
/// @param lsn - The log sequence number getting rolled back | ||
/// @param header - Header originally passed with replica_set::write() api | ||
/// @param key - Key originally passed with replica_set::write() api | ||
/// @param ctx - User contenxt passed as part of the replica_set::write() api | ||
virtual void on_rollback(int64_t lsn, sisl::blob const& header, sisl::blob const& key, void* ctx); | ||
|
||
/// @brief Called when replication module is trying to allocate a block to write the value | ||
/// | ||
/// This function can be called both on leader and follower when it is trying to allocate a block to write the | ||
/// value. Callee is expected to provide hints for allocation based on the header supplied as part of original | ||
/// write. In cases where callee don't care about the hints can return default blk_alloc_hints. | ||
/// | ||
/// @param header Header originally passed with repl_dev::write() api on the leader | ||
/// @return Expected to return blk_alloc_hints for this write | ||
virtual blk_alloc_hints get_blk_alloc_hints(sisl::blob const& header); | ||
|
||
/// @brief Called when the replica set is being stopped | ||
virtual void on_replica_stop(); | ||
|
||
private: | ||
HomeObjectImpl* home_object; | ||
}; | ||
|
||
} |
Oops, something went wrong.