global_state_accessor.pxd 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. from libcpp.string cimport string as c_string
  2. from libcpp cimport bool as c_bool
  3. from libcpp.vector cimport vector as c_vector
  4. from libcpp.unordered_map cimport unordered_map
  5. from libcpp.memory cimport unique_ptr
  6. from libc.stdint cimport (
  7. int32_t as c_int32_t,
  8. uint32_t as c_uint32_t,
  9. int64_t as c_int64_t,
  10. )
  11. from ray.includes.unique_ids cimport (
  12. CActorID,
  13. CJobID,
  14. CNodeID,
  15. CObjectID,
  16. CWorkerID,
  17. CPlacementGroupID,
  18. )
  19. from ray.includes.common cimport (
  20. CRayStatus,
  21. CGcsClientOptions,
  22. )
  23. from ray.includes.optional cimport (
  24. optional
  25. )
  26. cdef extern from "ray/gcs_rpc_client/global_state_accessor.h" nogil:
  27. cdef cppclass CGlobalStateAccessor "ray::gcs::GlobalStateAccessor":
  28. CGlobalStateAccessor(const CGcsClientOptions&)
  29. c_bool Connect()
  30. void Disconnect()
  31. c_vector[c_string] GetAllJobInfo(
  32. c_bool skip_submission_job_info_field, c_bool skip_is_running_tasks_field)
  33. CJobID GetNextJobID()
  34. c_vector[c_string] GetAllNodeInfo()
  35. c_vector[c_string] GetAllAvailableResources()
  36. c_vector[c_string] GetAllTotalResources()
  37. unordered_map[CNodeID, c_int64_t] GetDrainingNodes()
  38. unique_ptr[c_string] GetInternalKV(
  39. const c_string &namespace, const c_string &key)
  40. c_vector[c_string] GetAllTaskEvents()
  41. unique_ptr[c_string] GetObjectInfo(const CObjectID &object_id)
  42. unique_ptr[c_string] GetAllResourceUsage()
  43. c_vector[c_string] GetAllActorInfo(
  44. optional[CActorID], optional[CJobID], optional[c_string])
  45. unique_ptr[c_string] GetActorInfo(const CActorID &actor_id)
  46. unique_ptr[c_string] GetWorkerInfo(const CWorkerID &worker_id)
  47. c_vector[c_string] GetAllWorkerInfo()
  48. c_bool AddWorkerInfo(const c_string &serialized_string)
  49. c_bool UpdateWorkerDebuggerPort(const CWorkerID &worker_id,
  50. const c_uint32_t debuger_port)
  51. c_bool UpdateWorkerNumPausedThreads(const CWorkerID &worker_id,
  52. const c_int32_t num_paused_threads_delta)
  53. c_uint32_t GetWorkerDebuggerPort(const CWorkerID &worker_id)
  54. unique_ptr[c_string] GetPlacementGroupInfo(
  55. const CPlacementGroupID &placement_group_id)
  56. unique_ptr[c_string] GetPlacementGroupByName(
  57. const c_string &placement_group_name,
  58. const c_string &ray_namespace,
  59. )
  60. c_vector[c_string] GetAllPlacementGroupInfo()
  61. c_string GetSystemConfig()
  62. CRayStatus GetNode(
  63. const c_string &node_id_hex_str,
  64. c_string *node_info)
  65. cdef extern from * namespace "ray::gcs" nogil:
  66. """
  67. #include <thread>
  68. #include "ray/gcs/store_client_kv.h"
  69. #include "ray/gcs/store_client/redis_store_client.h"
  70. #include "ray/util/raii.h"
  71. namespace ray {
  72. namespace gcs {
  73. bool RedisGetKeySync(const std::string& host,
  74. int32_t port,
  75. const std::string& username,
  76. const std::string& password,
  77. bool use_ssl,
  78. const std::string& config,
  79. const std::string& key,
  80. std::string* data) {
  81. // Logging default value see class `RayLog`.
  82. InitShutdownRAII ray_log_shutdown_raii(ray::RayLog::StartRayLog,
  83. ray::RayLog::ShutDownRayLog,
  84. "ray_init",
  85. ray::RayLogLevel::WARNING,
  86. /*log_filepath=*/"",
  87. /*err_log_filepath=*/"",
  88. /*log_rotation_max_size=*/1ULL << 29,
  89. /*log_rotation_file_num=*/10);
  90. std::string config_list;
  91. RAY_CHECK(absl::Base64Unescape(config, &config_list));
  92. RayConfig::instance().initialize(config_list);
  93. instrumented_io_context io_service{/*enable_lag_probe=*/false, /*running_on_single_thread=*/true};
  94. RedisClientOptions options{host, port, username, password, use_ssl};
  95. auto client = std::make_unique<StoreClientInternalKV>(
  96. std::make_unique<RedisStoreClient>(io_service, options));
  97. bool ret_val = false;
  98. client->Get("session", key, {[&](std::optional<std::string> result) {
  99. if (result.has_value()) {
  100. *data = result.value();
  101. ret_val = true;
  102. } else {
  103. RAY_LOG(INFO) << "Failed to retrieve the key " << key
  104. << " from persistent storage.";
  105. ret_val = false;
  106. }
  107. }, io_service});
  108. io_service.run_for(std::chrono::milliseconds(1000));
  109. return ret_val;
  110. }
  111. }
  112. }
  113. """
  114. c_bool RedisGetKeySync(const c_string& host,
  115. c_int32_t port,
  116. const c_string& username,
  117. const c_string& password,
  118. c_bool use_ssl,
  119. const c_string& config,
  120. const c_string& key,
  121. c_string* data)
  122. cdef extern from "ray/gcs/store_client/redis_store_client.h" namespace "ray::gcs" nogil:
  123. c_bool RedisDelKeyPrefixSync(const c_string& host,
  124. c_int32_t port,
  125. const c_string& username,
  126. const c_string& password,
  127. c_bool use_ssl,
  128. const c_string& key_prefix)