17 #include "logdevice/include/AsyncReader.h" 18 #include "logdevice/include/ClientFactory.h" 19 #include "logdevice/include/ClientSettings.h" 20 #include "logdevice/include/ClusterAttributes.h" 21 #include "logdevice/include/ConfigSubscriptionHandle.h" 22 #include "logdevice/include/Err.h" 23 #include "logdevice/include/LogHeadAttributes.h" 24 #include "logdevice/include/LogTailAttributes.h" 25 #include "logdevice/include/LogsConfigTypes.h" 26 #include "logdevice/include/Reader.h" 27 #include "logdevice/include/Record.h" 28 #include "logdevice/include/types.h" 37 namespace facebook {
namespace logdevice {
42 enum class FindKeyAccuracy { STRICT, APPROXIMATE };
54 enum class DataSizeAccuracy { APPROXIMATE, COUNT };
68 typedef std::function<void(Status st, const DataRecord& r)> append_callback_t;
76 typedef std::function<void(Status, lsn_t result)> find_time_callback_t;
84 typedef std::function<void(FindKeyResult result)> find_key_callback_t;
92 typedef std::function<void(Status, uint64_t result)> byte_offset_callback_t;
100 typedef std::function<void(Status)> trim_callback_t;
108 typedef std::function<void(Status status, bool empty)> is_empty_callback_t;
116 typedef std::function<void(Status status, size_t size)> data_size_callback_t;
124 typedef std::function<void(Status status, lsn_t)> get_tail_lsn_callback_t;
132 typedef std::function<void(Status status, std::pair<logid_t, logid_t>)>
133 get_log_range_by_name_callback_t;
141 typedef std::function<void(Status status, std::map<std::string, logid_range_t>)>
142 get_log_ranges_by_namespace_callback_t;
149 typedef std::function<void()> config_update_callback_t;
158 typedef std::function<void(Status status, std::unique_ptr<client::LogGroup>)>
159 get_log_group_callback_t;
161 typedef std::function<void(Status status,
162 std::unique_ptr<client::LogGroup>,
163 const std::string& failure_reason)>
164 make_log_group_callback_t;
166 typedef std::function<void(Status status,
167 std::unique_ptr<client::LogAttributes>)>
168 get_log_attributes_callback_t;
170 typedef std::function<void(Status status, std::unique_ptr<client::Directory>)>
171 get_directory_callback_t;
173 typedef std::function<void(Status status,
174 std::unique_ptr<client::Directory>,
175 const std::string& failure_reason)>
176 make_directory_callback_t;
178 typedef std::function<
179 void(Status, uint64_t version,
const std::string& failure_reason)>
180 logsconfig_status_callback_t;
188 typedef std::function<void(Status status, std::unique_ptr<LogTailAttributes>)>
189 get_tail_attributes_callback_t;
197 typedef std::function<void(Status status, std::unique_ptr<LogHeadAttributes>)>
198 get_head_attributes_callback_t;
212 virtual ~
Client() =
default;
287 appendSync(logid_t logid,
289 AppendAttributes attrs = AppendAttributes(),
290 std::chrono::milliseconds* timestamp =
nullptr) noexcept = 0;
309 appendSync(logid_t logid,
310 PayloadGroup&& payload_group,
311 AppendAttributes attrs = AppendAttributes(),
312 std::chrono::milliseconds* timestamp =
nullptr) noexcept = 0;
333 appendSync(logid_t logid,
334 const Payload& payload,
335 AppendAttributes attrs = AppendAttributes(),
336 std::chrono::milliseconds* timestamp =
nullptr) noexcept = 0;
375 virtual int append(logid_t logid,
377 append_callback_t cb,
378 AppendAttributes attrs = AppendAttributes()) noexcept = 0;
385 virtual int append(logid_t logid,
386 PayloadGroup&& payload_group,
387 append_callback_t cb,
388 AppendAttributes attrs = AppendAttributes()) noexcept = 0;
395 virtual int append(logid_t logid,
396 const Payload& payload,
397 append_callback_t cb,
398 AppendAttributes attrs = AppendAttributes()) noexcept = 0;
425 virtual std::unique_ptr<Reader>
426 createReader(
size_t max_logs, ssize_t buffer_size = -1) noexcept = 0;
432 virtual std::unique_ptr<AsyncReader>
433 createAsyncReader(ssize_t buffer_size = -1) noexcept = 0;
439 virtual void setTimeout(std::chrono::milliseconds timeout) noexcept = 0;
472 virtual int trimSync(logid_t logid, lsn_t lsn) noexcept = 0;
482 virtual int trim(logid_t logid, lsn_t lsn, trim_callback_t cb) noexcept = 0;
492 virtual void addWriteToken(std::string) noexcept = 0;
571 findTimeSync(logid_t logid,
572 std::chrono::milliseconds timestamp,
573 Status* status_out =
nullptr,
574 FindKeyAccuracy accuracy = FindKeyAccuracy::STRICT) noexcept = 0;
645 findKeySync(logid_t logid,
647 FindKeyAccuracy accuracy = FindKeyAccuracy::STRICT) noexcept = 0;
659 findTime(logid_t logid,
660 std::chrono::milliseconds timestamp,
661 find_time_callback_t cb,
662 FindKeyAccuracy accuracy = FindKeyAccuracy::STRICT) noexcept = 0;
673 findKey(logid_t logid,
675 find_key_callback_t cb,
676 FindKeyAccuracy accuracy = FindKeyAccuracy::STRICT) noexcept = 0;
704 virtual int isLogEmptySync(logid_t logid,
bool* empty) noexcept = 0;
715 virtual int isLogEmpty(logid_t logid, is_empty_callback_t cb) noexcept = 0;
747 virtual int dataSizeSync(logid_t logid,
748 std::chrono::milliseconds start,
749 std::chrono::milliseconds end,
750 DataSizeAccuracy accuracy,
751 size_t* size) noexcept = 0;
767 virtual int dataSize(logid_t logid,
768 std::chrono::milliseconds start,
769 std::chrono::milliseconds end,
770 DataSizeAccuracy accuracy,
771 data_size_callback_t cb) noexcept = 0;
810 virtual lsn_t getTailLSNSync(logid_t logid) noexcept = 0;
821 virtual int getTailLSN(logid_t logid,
822 get_tail_lsn_callback_t cb) noexcept = 0;
862 virtual std::unique_ptr<LogTailAttributes>
863 getTailAttributesSync(logid_t logid) noexcept = 0;
874 virtual int getTailAttributes(logid_t logid,
875 get_tail_attributes_callback_t cb) noexcept = 0;
895 virtual std::unique_ptr<LogHeadAttributes>
896 getHeadAttributesSync(logid_t logid) noexcept = 0;
907 virtual int getHeadAttributes(logid_t logid,
908 get_head_attributes_callback_t cb) noexcept = 0;
934 virtual logid_range_t getLogRangeByName(
const std::string& name) noexcept = 0;
945 getLogRangeByName(
const std::string& name,
946 get_log_range_by_name_callback_t cb) noexcept = 0;
952 virtual std::string getLogNamespaceDelimiter() noexcept = 0;
974 virtual std::map<std::string, logid_range_t>
975 getLogRangesByNamespace(
const std::string& ns) noexcept = 0;
985 virtual void getLogRangesByNamespace(
986 const std::string& ns,
987 get_log_ranges_by_namespace_callback_t cb) noexcept = 0;
1004 virtual std::unique_ptr<client::LogGroup>
1005 getLogGroupSync(
const std::string& path) noexcept = 0;
1016 virtual void getLogGroup(
const std::string& path,
1017 get_log_group_callback_t cb) noexcept = 0;
1034 virtual std::unique_ptr<client::LogGroup>
1035 getLogGroupByIdSync(
const logid_t logid) noexcept = 0;
1050 virtual void getLogGroupById(
const logid_t logid,
1051 get_log_group_callback_t cb) noexcept = 0;
1070 virtual int makeDirectory(
const std::string& path,
1071 bool mk_intermediate_dirs,
1072 const client::LogAttributes& attrs,
1073 make_directory_callback_t cb) noexcept = 0;
1082 virtual std::unique_ptr<client::Directory> makeDirectorySync(
1083 const std::string& path,
1084 bool mk_intermediate_dirs =
false,
1085 const client::LogAttributes& attrs = client::LogAttributes(),
1086 std::string* failure_reason =
nullptr) noexcept = 0;
1102 virtual int removeDirectory(
const std::string& path,
1104 logsconfig_status_callback_t) noexcept = 0;
1115 virtual bool removeDirectorySync(
const std::string& path,
1116 bool recursive =
false,
1117 uint64_t* version =
nullptr) noexcept = 0;
1128 virtual bool removeLogGroupSync(
const std::string& path,
1129 uint64_t* version =
nullptr) noexcept = 0;
1141 virtual int removeLogGroup(
const std::string& path,
1142 logsconfig_status_callback_t cb) noexcept = 0;
1165 virtual int rename(
const std::string& from_path,
1166 const std::string& to_path,
1167 logsconfig_status_callback_t cb) noexcept = 0;
1180 virtual bool renameSync(
const std::string& from_path,
1181 const std::string& to_path,
1182 uint64_t* version =
nullptr,
1183 std::string* failure_reason =
nullptr) noexcept = 0;
1207 virtual int makeLogGroup(
const std::string& path,
1208 const logid_range_t& range,
1209 const client::LogAttributes& attrs,
1210 bool mk_intermediate_dirs,
1211 make_log_group_callback_t cb) noexcept = 0;
1224 virtual std::unique_ptr<client::LogGroup>
1225 makeLogGroupSync(
const std::string& path,
1226 const logid_range_t& range,
1227 const client::LogAttributes& attrs = client::LogAttributes(),
1228 bool mk_intermediate_dirs =
false,
1229 std::string* failure_reason =
nullptr) noexcept = 0;
1247 virtual int setAttributes(
const std::string& path,
1248 const client::LogAttributes& attrs,
1249 logsconfig_status_callback_t cb) noexcept = 0;
1261 setAttributesSync(
const std::string& path,
1262 const client::LogAttributes& attrs,
1263 uint64_t* version =
nullptr,
1264 std::string* failure_reason =
nullptr) noexcept = 0;
1279 virtual int setLogGroupRange(
const std::string& path,
1280 const logid_range_t& range,
1281 logsconfig_status_callback_t) noexcept = 0;
1293 setLogGroupRangeSync(
const std::string& path,
1294 const logid_range_t& range,
1295 uint64_t* version =
nullptr,
1296 std::string* failure_reason =
nullptr) noexcept = 0;
1304 virtual int getDirectory(
const std::string& path,
1305 get_directory_callback_t) noexcept = 0;
1310 virtual std::unique_ptr<client::Directory>
1311 getDirectorySync(
const std::string& path) noexcept = 0;
1328 virtual bool syncLogsConfigVersion(uint64_t version) noexcept = 0;
1340 notifyOnLogsConfigVersion(uint64_t version,
1341 std::function<
void()>) noexcept = 0;
1349 virtual std::unique_ptr<ClusterAttributes>
1350 getClusterAttributes() noexcept = 0;
1366 subscribeToConfigUpdates(config_update_callback_t) noexcept = 0;
1373 virtual size_t getMaxPayloadSize() noexcept = 0;
1385 virtual std::string getAllReadStreamsDebugInfo() noexcept = 0;
1412 virtual void publishEvent(Severity sev,
1413 std::string name_space,
1415 std::string data =
"",
1416 std::string context =
"") noexcept = 0;
Definition: AsyncReader.h:16
Definition: ClientSettings.h:25
Definition: ConfigSubscriptionHandle.h:31