Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
FullTableScannerAdapterBase.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "migration/cassandra/CassandraMigrationBackend.hpp"
23#include "migration/cassandra/impl/FullTableScanner.hpp"
24
25#include <boost/asio/spawn.hpp>
26
27#include <memory>
28#include <utility>
29
30namespace migration::cassandra::impl {
31
39template <TableSpec TableDesc>
41 static_assert(TableSpec<TableDesc>);
42
43protected:
47 std::shared_ptr<CassandraMigrationBackend> backend_;
48
49public:
50 virtual ~FullTableScannerAdapterBase() = default;
51
57 FullTableScannerAdapterBase(std::shared_ptr<CassandraMigrationBackend> backend) : backend_(std::move(backend))
58 {
59 }
60
67 void
68 readByTokenRange(TokenRange const& range, boost::asio::yield_context yield)
69 {
70 backend_->migrateInTokenRange<TableDesc>(
71 range.start, range.end, [this](auto const& row) { onRowRead(row); }, yield
72 );
73 }
74
81 virtual void
82 onRowRead(TableDesc::Row const& row) = 0;
83};
84} // namespace migration::cassandra::impl
The base class for the full table scanner adapter. It is responsible for reading the rows from the fu...
Definition FullTableScannerAdapterBase.hpp:40
void readByTokenRange(TokenRange const &range, boost::asio::yield_context yield)
Read the row in the given token range from database, this is the adapt function for the FullTableScan...
Definition FullTableScannerAdapterBase.hpp:68
FullTableScannerAdapterBase(std::shared_ptr< CassandraMigrationBackend > backend)
Construct a new Full Table Scanner Adapter Base object.
Definition FullTableScannerAdapterBase.hpp:57
std::shared_ptr< CassandraMigrationBackend > backend_
The backend to use.
Definition FullTableScannerAdapterBase.hpp:47
virtual void onRowRead(TableDesc::Row const &row)=0
Called when a row is read. The derived class should implement this function to convert the database b...
The token range used to split the full table scan into multiple ranges.
Definition FullTableScanner.hpp:42