mirror of
https://github.com/wassname/ray.git
synced 2026-09-11 12:43:20 +08:00
[Streaming] add barrier helper tests (#11107)
This commit is contained in:
@@ -7,11 +7,92 @@
|
||||
|
||||
namespace ray {
|
||||
namespace streaming {
|
||||
class StreamingBarrierHelper {
|
||||
class StreamingBarrierHelper final {
|
||||
using BarrierIdQueue = std::shared_ptr<std::queue<uint64_t>>;
|
||||
|
||||
public:
|
||||
StreamingBarrierHelper() {}
|
||||
/// No duplicated barrier helper should be loaded in data writer or data
|
||||
/// reader, so we mark BarrierHelper as a nocopyable object.
|
||||
StreamingBarrierHelper(const StreamingBarrierHelper &barrier_helper) = delete;
|
||||
|
||||
StreamingBarrierHelper operator=(const StreamingBarrierHelper &barrier_helper) = delete;
|
||||
|
||||
virtual ~StreamingBarrierHelper() = default;
|
||||
|
||||
/// Get barrier id from queue-barrier map by given seq-id.
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in barrier_id, barrier or checkpoint of long runtime job
|
||||
/// \param_out msg_id, message id of barrier
|
||||
StreamingStatus GetMsgIdByBarrierId(const ObjectID &q_id, uint64_t barrier_id,
|
||||
uint64_t &msg_id);
|
||||
|
||||
/// Append new message id to queue-barrier map.
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in barrier_id, barrier or checkpoint of long running job
|
||||
/// \param_in msg_id, message id of barrier
|
||||
void SetMsgIdByBarrierId(const ObjectID &q_id, uint64_t barrier_id, uint64_t msg_id);
|
||||
|
||||
/// Check whether barrier id in queue-barrier map.
|
||||
/// \param_in barrier_id, barrier id or checkpoint id
|
||||
bool Contains(uint64_t barrier_id);
|
||||
|
||||
/// Remove barrier info from queue-barrier map by given seq id.
|
||||
void ReleaseBarrierMapById(uint64_t barrier_id);
|
||||
|
||||
/// Remove all barrier info from queue-barrier map.
|
||||
void ReleaseAllBarrierMap();
|
||||
|
||||
/// Fetch barrier id list from queue-barrier map.
|
||||
void GetAllBarrier(std::vector<uint64_t> &barrier_id_vec);
|
||||
|
||||
/// Get barrier map capacity of current version.
|
||||
uint32_t GetBarrierMapSize();
|
||||
|
||||
/// We assume there are multiple barriers in one checkpoint, so barrier id
|
||||
/// should belong to a checkpoint id.
|
||||
/// \param_in barrier_id, barrier id
|
||||
/// \param_in checkpoint_id, checkpoint id
|
||||
void MapBarrierToCheckpoint(uint64_t barrier_id, uint64_t checkpoint_id);
|
||||
|
||||
/// Get checkpoint id by given barrier id
|
||||
/// \param_in barrier_id, barrier id
|
||||
/// \param_out checkpoint_id, checkpoint id
|
||||
StreamingStatus GetCheckpointIdByBarrierId(uint64_t barrier_id,
|
||||
uint64_t &checkpoint_id);
|
||||
|
||||
/// Clear barrier-checkpoint relation if elements of barrier id vector are
|
||||
/// equal to or less than given barrier id.
|
||||
/// \param_in barrier_id
|
||||
void ReleaseBarrierMapCheckpointByBarrierId(const uint64_t barrier_id);
|
||||
|
||||
/// Get barrier id by lastest message id and channel
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in message_id, lastest message id of barrier data
|
||||
/// \param_out barrier_id, barrier id
|
||||
/// \param_in is_pop, whether pop out from queue
|
||||
StreamingStatus GetBarrierIdByLastMessageId(const ObjectID &q_id, uint64_t message_id,
|
||||
uint64_t &barrier_id, bool is_pop = false);
|
||||
|
||||
/// Put new barrier id in map by channel index and lastest message id.
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in message_id, lastest message id of barrier data
|
||||
/// \param_in barrier_id, barrier id
|
||||
void SetBarrierIdByLastMessageId(const ObjectID &q_id, uint64_t message_id,
|
||||
uint64_t barrier_id);
|
||||
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in checkpoint_id, checkpoint id of long running job
|
||||
void GetCurrentMaxCheckpointIdInQueue(const ObjectID &q_id,
|
||||
uint64_t &checkpoint_id) const;
|
||||
|
||||
/// \param_in q_id, channel id
|
||||
/// \param_in checkpoint_id, checkpoint id of long running job
|
||||
void SetCurrentMaxCheckpointIdInQueue(const ObjectID &q_id,
|
||||
const uint64_t checkpoint_id);
|
||||
|
||||
private:
|
||||
// Global barrier map set (global barrier id -> (channel id -> msg id))
|
||||
// Global barrier map set (global barrier id -> (channel id -> seq id))
|
||||
std::unordered_map<uint64_t, std::unordered_map<ObjectID, uint64_t>>
|
||||
global_barrier_map_;
|
||||
|
||||
@@ -34,32 +115,6 @@ class StreamingBarrierHelper {
|
||||
std::mutex global_barrier_mutex_;
|
||||
|
||||
std::mutex barrier_map_checkpoint_mutex_;
|
||||
|
||||
public:
|
||||
StreamingStatus GetMsgIdByBarrierId(const ObjectID &q_id, uint64_t barrier_id,
|
||||
uint64_t &msg_id);
|
||||
void SetMsgIdByBarrierId(const ObjectID &q_id, uint64_t barrier_id, uint64_t seq_id);
|
||||
bool Contains(uint64_t barrier_id);
|
||||
void ReleaseBarrierMapById(uint64_t barrier_id);
|
||||
void ReleaseAllBarrierMap();
|
||||
void GetAllBarrier(std::vector<uint64_t> &barrier_id_vec);
|
||||
uint32_t GetBarrierMapSize();
|
||||
|
||||
void MapBarrierToCheckpoint(uint64_t barrier_id, uint64_t checkpoint);
|
||||
StreamingStatus GetCheckpointIdByBarrierId(uint64_t barrier_id,
|
||||
uint64_t &checkpoint_id);
|
||||
void ReleaseBarrierMapCheckpointByBarrierId(const uint64_t barrier_id);
|
||||
|
||||
StreamingStatus GetBarrierIdByLastMessageId(const ObjectID &q_id, uint64_t message_id,
|
||||
uint64_t &barrier_id, bool is_pop = false);
|
||||
void SetBarrierIdByLastMessageId(const ObjectID &q_id, uint64_t message_id,
|
||||
uint64_t barrier_id);
|
||||
|
||||
void GetCurrentMaxCheckpointIdInQueue(const ObjectID &q_id,
|
||||
uint64_t &checkpoint_id) const;
|
||||
|
||||
void SetCurrentMaxCheckpointIdInQueue(const ObjectID &q_id,
|
||||
const uint64_t checkpoint_id);
|
||||
};
|
||||
} // namespace streaming
|
||||
} // namespace ray
|
||||
|
||||
Reference in New Issue
Block a user