Repository navigation
Expand file tree
/
Copy pathtransfer_task.h
More file actions
783 lines (675 loc) · 24.7 KB
/
Copy pathtransfer_task.h
File metadata and controls
783 lines (675 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
#pragma once
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <cstring>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <thread>
#include <vector>
#include "transfer_engine.h"
#include "types.h"
#include "replica.h"
#include "storage_backend.h"
#include "client_metric.h"
#include "nof/nvmeof_initiator.h"
namespace mooncake {
/**
* @brief Transfer strategy enumeration
*/
enum class TransferStrategy {
LOCAL_MEMCPY = 0, // Local memory copy using memcpy
TRANSFER_ENGINE = 1, // Remote transfer using transfer engine
FILE_READ = 2, // File read operation
EMPTY = 3,
SPDK_NVMF = 4 // Spdk nvmf operation
};
enum class OffloadBufferAccess {
kTransferEngine,
kLocalAddress,
};
enum class TransferIntent : int {
kUnspecified = transfer_intent_values::kUnspecified,
kForegroundGet = transfer_intent_values::kForegroundGet,
kBackgroundPrefetch = transfer_intent_values::kBackgroundPrefetch,
kMigration = transfer_intent_values::kMigration,
};
inline std::optional<TransferIntent> TransferIntentFromInt(int intent) {
switch (intent) {
case transfer_intent_values::kUnspecified:
return TransferIntent::kUnspecified;
case transfer_intent_values::kForegroundGet:
return TransferIntent::kForegroundGet;
case transfer_intent_values::kBackgroundPrefetch:
return TransferIntent::kBackgroundPrefetch;
case transfer_intent_values::kMigration:
return TransferIntent::kMigration;
default:
return std::nullopt;
}
}
/**
* @brief Stream operator for TransferStrategy
*/
inline std::ostream& operator<<(std::ostream& os,
const TransferStrategy& strategy) noexcept {
switch (strategy) {
case TransferStrategy::LOCAL_MEMCPY:
return os << "LOCAL_MEMCPY";
case TransferStrategy::TRANSFER_ENGINE:
return os << "TRANSFER_ENGINE";
case TransferStrategy::SPDK_NVMF:
return os << "SPDK_NVMF";
case TransferStrategy::FILE_READ:
return os << "FILE_READ";
case TransferStrategy::EMPTY:
return os << "EMPTY";
default:
return os << "UNKNOWN";
}
}
/**
* @brief Abstract base class for operation state management
*
* This class encapsulates the common state and behavior for async transfer
* operations. Derived classes implement strategy-specific waiting logic.
*/
class OperationState {
public:
OperationState() = default;
virtual ~OperationState() = default;
// Non-copyable, non-movable
OperationState(const OperationState&) = delete;
OperationState& operator=(const OperationState&) = delete;
OperationState(OperationState&&) = delete;
OperationState& operator=(OperationState&&) = delete;
/**
* @brief Check if the operation has completed
*/
virtual bool is_completed() = 0;
/**
* @brief Get the operation result. Make sure to call is_completed() first.
*/
ErrorCode get_result() const { // lock mutex
std::lock_guard<std::mutex> lock(mutex_);
assert(result_.has_value() &&
"get_result() called on an incomplete or failed-to-set "
"operation state.");
return result_.value_or(ErrorCode::INVALID_PARAMS);
}
/**
* @brief Get the transfer strategy
*/
virtual TransferStrategy get_strategy() const = 0;
/**
* @brief Wait for the operation to complete (strategy-specific
* implementation)
*/
virtual void wait_for_completion() = 0;
protected:
std::optional<ErrorCode> result_ = std::nullopt;
mutable std::mutex mutex_;
std::condition_variable cv_;
};
/**
* @brief Operation state for local memcpy transfers
*/
class EmptyOperationState : public OperationState {
public:
bool is_completed() override { return true; }
void wait_for_completion() override {}
TransferStrategy get_strategy() const override {
return TransferStrategy::EMPTY;
}
};
/**
* @brief Operation state for local memcpy transfers
*/
class MemcpyOperationState : public OperationState {
public:
bool is_completed() override {
std::lock_guard<std::mutex> lock(mutex_);
return result_.has_value();
}
void set_completed(ErrorCode error_code) {
{
std::lock_guard<std::mutex> lock(mutex_);
assert(!result_.has_value());
result_.emplace(error_code);
}
cv_.notify_all();
}
void wait_for_completion() override {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return result_.has_value(); });
}
TransferStrategy get_strategy() const override {
return TransferStrategy::LOCAL_MEMCPY;
}
};
/**
* @brief Operation state for NoF (NVMe-oF) transfers
*/
class NofOperationState : public OperationState {
public:
bool is_completed() override {
std::lock_guard<std::mutex> lock(mutex_);
return result_.has_value();
}
void set_completed(ErrorCode error_code, std::string error_detail = "") {
{
std::lock_guard<std::mutex> lock(mutex_);
assert(!result_.has_value());
result_.emplace(error_code);
error_detail_ = std::move(error_detail);
}
cv_.notify_all();
}
// Data-plane error detail (sc/sct/status string), empty on success.
// Surfaced to logs today; available here for future API plumbing.
[[nodiscard]] std::string error_detail() const {
std::lock_guard<std::mutex> lock(mutex_);
return error_detail_;
}
void wait_for_completion() override {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return result_.has_value(); });
}
TransferStrategy get_strategy() const override {
return TransferStrategy::SPDK_NVMF;
}
private:
std::string error_detail_;
};
class FilereadOperationState : public OperationState {
public:
bool is_completed() override {
std::lock_guard<std::mutex> lock(mutex_);
return result_.has_value();
}
void set_completed(ErrorCode error_code) {
{
std::lock_guard<std::mutex> lock(mutex_);
assert(!result_.has_value());
result_.emplace(error_code);
}
cv_.notify_all();
}
void wait_for_completion() override {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return result_.has_value(); });
}
TransferStrategy get_strategy() const override {
return TransferStrategy::FILE_READ;
}
};
/**
* @brief Operation state for transfer engine operations
*/
class TransferEngineOperationState : public OperationState {
public:
TransferEngineOperationState(TransferEngine& engine, BatchID batch_id,
size_t batch_size)
: engine_(engine),
tent_engine_(engine.getTentEngine().get()),
batch_id_(batch_id),
batch_size_(batch_size),
start_ts_(getCurrentTimeInMilli()) {}
~TransferEngineOperationState();
bool is_completed() override;
void wait_for_completion() override;
TransferStrategy get_strategy() const override {
return TransferStrategy::TRANSFER_ENGINE;
}
private:
/**
* @brief Check the current completion status of the task, make sure to lock
* the mutex before calling this function.
* Updates the internal state and returns true if the task is completed.
*/
void check_task_status();
void set_result_internal(ErrorCode error_code);
TransferEngine& engine_;
mooncake::tent::TransferEngine* tent_engine_;
BatchID batch_id_;
size_t batch_size_;
const int64_t start_ts_;
};
/**
* @brief Represents the future result of an asynchronous transfer operation
*
* This class provides a std::future-like interface for asynchronous transfer
* operations. Users can check completion status, wait for results, or get the
* final error code.
*/
class TransferFuture {
public:
explicit TransferFuture(std::shared_ptr<OperationState> state);
// Non-copyable but movable
TransferFuture(const TransferFuture&) = delete;
TransferFuture& operator=(const TransferFuture&) = delete;
TransferFuture(TransferFuture&&) = default;
TransferFuture& operator=(TransferFuture&&) = default;
/**
* @brief Check if the operation has completed (non-blocking)
* @return true if the operation is finished, false otherwise
*/
bool isReady() const;
/**
* @brief Wait for the operation to complete (blocking)
* @return ErrorCode indicating success or failure
*/
ErrorCode wait();
/**
* @brief Get the result, waiting if necessary (blocking)
* @return ErrorCode indicating success or failure
*/
ErrorCode get();
/**
* @brief Get the transfer strategy used by this operation
* @return TransferStrategy enum value
*/
TransferStrategy strategy() const;
/**
* @brief Create another future that observes the same operation
*
* Used when one submitted batch carries several keys, so each key can
* wait on it independently.
*/
TransferFuture share() const { return TransferFuture(state_); }
private:
std::shared_ptr<OperationState> state_;
};
/// Scatter transfer operation returned by
/// TransferSubmitter::submitNativeScatter().
///
/// Thread safety: NOT thread-safe. Only one thread may call wait(),
/// waitFor(), or destroy this object at a time. The caller that received
/// the operation from submitNativeScatter() owns it for its entire lifetime.
class StoreScatterTransferOperation {
public:
StoreScatterTransferOperation(StoreScatterTransferOperation&&) noexcept;
StoreScatterTransferOperation& operator=(
StoreScatterTransferOperation&&) noexcept;
~StoreScatterTransferOperation();
StoreScatterTransferOperation(const StoreScatterTransferOperation&) =
delete;
StoreScatterTransferOperation& operator=(
const StoreScatterTransferOperation&) = delete;
Status wait();
Status waitFor(std::chrono::nanoseconds timeout);
private:
class Impl;
explicit StoreScatterTransferOperation(std::unique_ptr<Impl> impl);
std::unique_ptr<Impl> impl_;
friend class TransferSubmitter;
};
/**
* @brief Memory copy operation descriptor
*/
struct MemcpyOperation {
void* dest;
const void* src;
size_t size;
MemcpyOperation(void* d, const void* s, size_t sz)
: dest(d), src(s), size(sz) {}
};
/**
* @brief Memcpy task for async execution
*/
struct MemcpyTask {
std::vector<MemcpyOperation> operations;
std::shared_ptr<MemcpyOperationState> state;
MemcpyTask(std::vector<MemcpyOperation> ops,
std::shared_ptr<MemcpyOperationState> s)
: operations(std::move(ops)), state(std::move(s)) {}
};
/**
* @brief True when some op writes bytes that another op of the task reads or
* writes, so the ops must run one after another instead of being batched.
*
* Zero-length ops touch nothing. An op whose own source and destination
* overlap counts too, and so does a range whose end would wrap past the top of
* the address space; both are conservative.
*/
bool MemcpyOperationsOverlap(const std::vector<MemcpyOperation>& operations);
/**
* @brief Thread pool for asynchronous memcpy operations
*
* This class manages a single worker thread that executes memcpy operations
* asynchronously.
*/
class MemcpyWorkerPool {
public:
explicit MemcpyWorkerPool();
~MemcpyWorkerPool();
// Non-copyable, non-movable
MemcpyWorkerPool(const MemcpyWorkerPool&) = delete;
MemcpyWorkerPool& operator=(const MemcpyWorkerPool&) = delete;
MemcpyWorkerPool(MemcpyWorkerPool&&) = delete;
MemcpyWorkerPool& operator=(MemcpyWorkerPool&&) = delete;
/**
* @brief Submit a memcpy task for async execution
* @param task The memcpy task to execute
*/
void submitTask(MemcpyTask task);
private:
void workerThread();
std::vector<std::thread> workers_;
std::queue<MemcpyTask> task_queue_;
std::mutex queue_mutex_;
std::condition_variable queue_cv_;
std::atomic<bool> shutdown_;
};
struct NofQos;
struct NofMetric;
/**
* @brief NoF operation descriptor (byte-oriented, opaque handle)
*/
struct NofTask {
NofSegmentHandle* seg_handle;
void* ptr;
uint64_t byte_offset;
uint64_t byte_length;
uint64_t remaining_bytes;
int outstanding_sub_io;
NofIOOp op;
int idx; // subop idx
bool failed;
bool on_chain;
std::shared_ptr<NofOperationState> state;
// First failure's error detail (sc/sct/status string); written only on
// the failure path, empty in steady state — zero hot-path cost.
std::string error_detail;
// Shared ownership of the worker's outstanding-I/O counter (formerly a
// raw pointer to a worker-thread stack variable).
std::shared_ptr<std::atomic<int64_t>> io_count;
NofQos* nof_qos;
NofTask* nxt;
// Optional metrics sink; wired by TransferSubmitter, nullptr when the
// client has no metrics.
NofMetric* metric = nullptr;
NofTask(NofSegmentHandle* handle, void* buf, uint64_t byte_off,
uint64_t byte_len, NofIOOp op_code,
std::shared_ptr<NofOperationState> s)
: seg_handle(handle),
ptr(buf),
byte_offset(byte_off),
byte_length(byte_len),
remaining_bytes(byte_len),
outstanding_sub_io(0),
op(op_code),
idx(0),
failed(false),
on_chain(false),
state(std::move(s)),
io_count(nullptr),
nof_qos(nullptr),
nxt(nullptr) {}
};
struct NofSubTask {
// Embedded adaptor keeps the steady-state submit/completion path free of
// per-sub-IO heap allocation.
NofIOAdaptor adaptor;
NofTask* task;
uint32_t submit_bytes;
std::stack<NofSubTask*>* sub_task_pool;
};
constexpr int kDefaultNofSubmitChunkBytes = (1 << 17); // 128k
constexpr int kDefaultNofInflightBytesLimit = (1 << 25); // 32M
struct NofQos {
// Block size cached at QoS creation; the poll loop does not re-query it.
const uint32_t block_size;
const int blocks_per_chunk;
const int inflight_blocks_limit;
int inflight_blocks[static_cast<size_t>(NofIOOp::kNum)];
NofTask* head[static_cast<size_t>(NofIOOp::kNum)];
NofTask* tail[static_cast<size_t>(NofIOOp::kNum)];
explicit NofQos(uint32_t bs);
bool Empty() const {
return (head[static_cast<size_t>(NofIOOp::kRead)] == nullptr &&
head[static_cast<size_t>(NofIOOp::kWrite)] == nullptr);
}
void PushTask(NofTask* task) {
size_t op = static_cast<size_t>(task->op);
if (head[op] == nullptr) {
head[op] = task;
tail[op] = task;
} else {
tail[op]->nxt = task;
tail[op] = task;
}
}
void PopTask(NofIOOp op) {
size_t i = static_cast<size_t>(op);
if (head[i]) {
head[i] = head[i]->nxt;
}
}
};
constexpr int kDefaultNofWorkers = 4;
class NofWorkerPool {
public:
explicit NofWorkerPool(std::shared_ptr<NVMeoFInitiator> initiator,
int numa_socket_id = 0);
~NofWorkerPool();
NofWorkerPool(const NofWorkerPool&) = delete;
NofWorkerPool& operator=(const NofWorkerPool&) = delete;
NofWorkerPool(NofWorkerPool&&) = delete;
NofWorkerPool& operator=(NofWorkerPool&&) = delete;
void submitTask(NofTask task);
private:
void workerThread(int work_idx);
std::shared_ptr<NVMeoFInitiator> initiator_;
int worker_count_;
int numa_socket_id_;
std::vector<std::thread> workers_;
std::unique_ptr<std::queue<NofTask>[]> task_queue_;
std::unique_ptr<std::mutex[]> queue_mutex_;
std::unique_ptr<std::condition_variable[]> queue_cv_;
std::atomic<bool> shutdown_;
std::mutex seg_mutex_;
int seg_num = 0;
std::map<NofSegmentHandle*, int> seg_to_worker_;
};
/**
* @brief Fileread task for async execution
*/
struct FilereadTask {
std::string file_path;
size_t object_size;
std::vector<Slice> slices;
std::shared_ptr<FilereadOperationState> state;
FilereadTask(const std::string& path, size_t size,
const std::vector<Slice>& slices_ref,
std::shared_ptr<FilereadOperationState> s)
: file_path(path),
object_size(size),
slices(slices_ref),
state(std::move(s)) {}
};
/**
* @brief Thread pool for asynchronous memcpy operations
*
* This class manages a single worker thread that executes memcpy operations
* asynchronously.
*/
class FilereadWorkerPool {
public:
explicit FilereadWorkerPool(std::shared_ptr<StorageBackend>& backend);
~FilereadWorkerPool();
// Non-copyable, non-movable
FilereadWorkerPool(const FilereadWorkerPool&) = delete;
FilereadWorkerPool& operator=(const FilereadWorkerPool&) = delete;
FilereadWorkerPool(FilereadWorkerPool&&) = delete;
FilereadWorkerPool& operator=(FilereadWorkerPool&&) = delete;
/**
* @brief Submit a memcpy task for async execution
* @param task The memcpy task to execute
*/
void submitTask(FilereadTask task);
private:
friend class FilereadWorkerPoolTestPeer;
void workerThread();
std::vector<std::thread> workers_;
std::queue<FilereadTask> task_queue_;
std::mutex queue_mutex_;
std::condition_variable queue_cv_;
std::atomic<bool> shutdown_;
std::shared_ptr<StorageBackend> backend_;
};
/**
* @brief Submitter class for asynchronous transfer operations
*
* This class analyzes transfer requirements, selects optimal strategies, and
* immediately submits operations returning TransferFuture objects for result
* tracking.
*/
class TransferSubmitter {
public:
explicit TransferSubmitter(
TransferEngine& engine, std::shared_ptr<StorageBackend>& backend,
const std::string& local_hostname,
TransferMetric* transfer_metric = nullptr, int numa_socket_id = 0,
std::shared_ptr<NVMeoFInitiator> nof_initiator = nullptr,
NofMetric* nof_metric = nullptr);
/**
* @brief Submit an asynchronous transfer operation
*
* Analyzes the transfer requirements, selects the optimal strategy,
* and immediately submits the operation. Returns a TransferFuture
* that can be used to track completion and get results.
*
* @param handles Buffer descriptors for the transfer
* @param slices Memory slices for the transfer
* @param op_code Transfer operation (READ/WRITE)
* @return TransferFuture representing the async operation, or nullopt on
* failure
*/
std::optional<TransferFuture> submit(
const Replica::Descriptor& replica, std::vector<Slice>& slices,
TransferRequest::OpCode op_code, void* ptr = nullptr, size_t size = 0,
TransferIntent intent = TransferIntent::kUnspecified);
/**
* @brief Submit a range read: read [src_offset, src_offset+size) from
* object into slice.ptr. Slices must total exactly `size` bytes.
*/
std::optional<TransferFuture> submitRangeRead(
const Replica::Descriptor& replica, std::vector<Slice>& slices,
uint64_t src_offset,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submitRangeWrite(
const Replica::Descriptor& replica, std::vector<Slice>& slices,
uint64_t dst_offset,
TransferIntent intent = TransferIntent::kUnspecified);
TransferEngine::ScatterTransferOperation submitScatter(
const std::vector<TransferEngine::ScatterTransferRange>& transfers);
StoreScatterTransferOperation submitNativeScatter(
const std::vector<TransferEngine::ScatterTransferRange>& transfers,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submit_batch(
const std::vector<Replica::Descriptor>& replicas,
std::vector<std::vector<Slice>>& all_slices,
TransferRequest::OpCode op_code,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submit_batch_get_offload_object(
const std::string& transfer_engine_addr,
const std::vector<std::string>& keys,
const std::vector<uint64_t>& pointers,
const std::unordered_map<std::string, std::vector<Slice>>&
batched_slices,
OffloadBufferAccess buffer_access,
TransferIntent intent = TransferIntent::kUnspecified);
[[nodiscard]] bool canUseLocalMemcpy(const std::string& endpoint) const;
/**
* @brief Pure comparison helper: returns true iff both endpoints are
* non-empty and identical. Exposed for unit testing of the locality
* decision without instantiating a full TransferEngine.
*
* Two endpoints identify the same process only when their ip:port (or
* full hostname) match exactly; same-host different-process pairs share
* an IP but not a port and must NOT be treated as locally addressable.
*/
static bool isSameProcessEndpoint(const std::string& handle_endpoint,
const std::string& local_endpoint);
private:
TransferEngine& engine_;
mooncake::tent::TransferEngine* tent_engine_ = nullptr;
// Cached at construction: the local transport endpoint never changes for
// the lifetime of the TransferSubmitter, so we avoid calling
// engine_.getLocalIpAndPort() (which allocates a string) on every transfer.
const std::string local_endpoint_;
std::unique_ptr<MemcpyWorkerPool> memcpy_pool_;
std::shared_ptr<NVMeoFInitiator> nof_initiator_;
NofMetric* nof_metric_ = nullptr;
std::unique_ptr<NofWorkerPool> nof_pool_;
std::unique_ptr<FilereadWorkerPool> fileread_pool_;
bool memcpy_enabled_;
const std::string local_hostname_;
TransferMetric* transfer_metric_;
/**
* @brief Select the optimal transfer strategy
*/
TransferStrategy selectStrategy(const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices) const;
/**
* @brief Validate transfer parameters
*/
bool validateTransferParams(const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices) const;
void appendMemcpyOperations(const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices,
TransferRequest::OpCode op_code,
uint64_t buffer_offset,
std::vector<MemcpyOperation>& operations);
/**
* @brief Submit memcpy operation asynchronously
*/
std::optional<TransferFuture> submitMemcpyOperation(
const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices, const TransferRequest::OpCode op_code,
uint64_t src_offset = 0);
std::optional<TransferFuture> submitMemcpyOperations(
std::vector<MemcpyOperation> operations);
/**
* @brief Submit NoF (NVMe-oF) operation asynchronously
*/
std::optional<TransferFuture> submitNofOperation(
const AllocatedBuffer::Descriptor& handle, void* ptr, size_t size,
const TransferRequest::OpCode op_code);
/**
* @brief Submit transfer engine operation asynchronously
* @param src_offset Optional offset in source buffer (default 0)
*/
std::optional<TransferFuture> submitTransferEngineOperation(
const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices, const TransferRequest::OpCode op_code,
uint64_t src_offset = 0,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submitMemoryReadOperation(
const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices, uint64_t src_offset,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submitMemoryWriteOperation(
const AllocatedBuffer::Descriptor& handle,
const std::vector<Slice>& slices, uint64_t dst_offset,
TransferIntent intent = TransferIntent::kUnspecified);
std::optional<TransferFuture> submitFileReadOperation(
const Replica::Descriptor& replica, std::vector<Slice>& slices,
TransferRequest::OpCode op_code);
/**
* @brief Calculate total bytes for transfer operation and update metrics
*/
void updateTransferMetrics(const std::vector<Slice>& slices,
TransferRequest::OpCode op);
std::optional<TransferFuture> submitTransfer(
std::vector<TransferRequest>& requests,
TransferIntent intent = TransferIntent::kUnspecified);
};
} // namespace mooncake