Skip to content

Commit 1f95874

Browse files
authored
Merge branch 'develop' into 1833_Permission_domains
2 parents c141c4e + 278f7b1 commit 1f95874

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+688
-220
lines changed

src/app/ClioApplication.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "etl/LoadBalancer.hpp"
2727
#include "etl/NetworkValidatedLedgers.hpp"
2828
#include "feed/SubscriptionManager.hpp"
29+
#include "migration/MigrationInspectorFactory.hpp"
2930
#include "rpc/Counters.hpp"
3031
#include "rpc/RPCEngine.hpp"
3132
#include "rpc/WorkQueue.hpp"
@@ -103,6 +104,16 @@ ClioApplication::run(bool const useNgWebServer)
103104
// Interface to the database
104105
auto backend = data::makeBackend(config_);
105106

107+
{
108+
auto const migrationInspector = migration::makeMigrationInspector(config_, backend);
109+
// Check if any migration is blocking Clio server starting.
110+
if (migrationInspector->isBlockingClio() and backend->hardFetchLedgerRangeNoThrow()) {
111+
LOG(util::LogService::error())
112+
<< "Existing Migration is blocking Clio, Please complete the database migration first.";
113+
return EXIT_FAILURE;
114+
}
115+
}
116+
106117
// Manages clients subscribed to streams
107118
auto subscriptions = feed::SubscriptionManager::makeSubscriptionManager(config_, backend);
108119

src/main/Main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above
@@ -42,7 +42,8 @@ try {
4242
[](app::CliArgs::Action::Exit const& exit) { return exit.exitCode; },
4343
[](app::CliArgs::Action::VerifyConfig const& verify) {
4444
if (app::parseConfig(verify.configPath)) {
45-
std::cout << "Config " << verify.configPath << " is correct" << "\n";
45+
std::cout << "Config " << verify.configPath << " is correct"
46+
<< "\n";
4647
return EXIT_SUCCESS;
4748
}
4849
return EXIT_FAILURE;

src/migration/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ target_sources(
55
cassandra/impl/ObjectsAdapter.cpp cassandra/impl/TransactionsAdapter.cpp
66
)
77

8-
target_link_libraries(clio_migration PRIVATE clio_util clio_etl)
8+
target_link_libraries(clio_migration PRIVATE clio_util clio_data)

src/migration/MigrationApplication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above

src/migration/MigrationApplication.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//------------------------------------------------------------------------------
2+
/*
3+
This file is part of clio: https://github.com/XRPLF/clio
4+
Copyright (c) 2025, 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 "data/BackendInterface.hpp"
23+
#include "migration/MigrationInspectorInterface.hpp"
24+
#include "migration/MigratiorStatus.hpp"
25+
#include "migration/cassandra/CassandraMigrationManager.hpp"
26+
#include "util/Assert.hpp"
27+
#include "util/log/Logger.hpp"
28+
#include "util/newconfig/ConfigDefinition.hpp"
29+
30+
#include <boost/algorithm/string.hpp>
31+
#include <boost/algorithm/string/predicate.hpp>
32+
33+
#include <memory>
34+
#include <utility>
35+
36+
namespace migration {
37+
38+
/**
39+
* @brief A factory function that creates migration inspector instance and initializes the migration table if needed.
40+
*
41+
* @param config The config.
42+
* @param backend The backend instance. It should be initialized before calling this function.
43+
* @return A shared_ptr<MigrationInspectorInterface> instance
44+
*/
45+
inline std::shared_ptr<MigrationInspectorInterface>
46+
makeMigrationInspector(
47+
util::config::ClioConfigDefinition const& config,
48+
std::shared_ptr<BackendInterface> const& backend
49+
)
50+
{
51+
ASSERT(backend != nullptr, "Backend is not initialized");
52+
53+
auto inspector = std::make_shared<migration::cassandra::CassandraMigrationInspector>(backend);
54+
55+
// Database is empty, we need to initialize the migration table if it is a writeable backend
56+
if (not config.get<bool>("read_only") and not backend->hardFetchLedgerRangeNoThrow()) {
57+
migration::MigratorStatus migrated(migration::MigratorStatus::Migrated);
58+
for (auto const& name : inspector->allMigratorsNames()) {
59+
backend->writeMigratorStatus(name, migrated.toString());
60+
}
61+
}
62+
return inspector;
63+
}
64+
65+
} // namespace migration
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//------------------------------------------------------------------------------
2+
/*
3+
This file is part of clio: https://github.com/XRPLF/clio
4+
Copyright (c) 2025, 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/MigratiorStatus.hpp"
23+
24+
#include <string>
25+
#include <tuple>
26+
#include <vector>
27+
28+
namespace migration {
29+
30+
/**
31+
* @brief The interface for the migration inspector.The Clio server application will use this interface to inspect
32+
* the migration status.
33+
*/
34+
struct MigrationInspectorInterface {
35+
virtual ~MigrationInspectorInterface() = default;
36+
37+
/**
38+
* @brief Get the status of all the migrators
39+
* @return A vector of tuple, the first element is the migrator's name, the second element is the status of the
40+
*/
41+
virtual std::vector<std::tuple<std::string, MigratorStatus>>
42+
allMigratorsStatusPairs() const = 0;
43+
44+
/**
45+
* @brief Get all registered migrators' names
46+
*
47+
* @return A vector of migrators' names
48+
*/
49+
virtual std::vector<std::string>
50+
allMigratorsNames() const = 0;
51+
52+
/**
53+
* @brief Get the status of a migrator by its name
54+
*
55+
* @param name The migrator's name
56+
* @return The status of the migrator
57+
*/
58+
virtual MigratorStatus
59+
getMigratorStatusByName(std::string const& name) const = 0;
60+
61+
/**
62+
* @brief Get the description of a migrator by its name
63+
*
64+
* @param name The migrator's name
65+
* @return The description of the migrator
66+
*/
67+
virtual std::string
68+
getMigratorDescriptionByName(std::string const& name) const = 0;
69+
70+
/**
71+
* @brief Return if Clio server is blocked
72+
*
73+
* @return True if Clio server is blocked by migration, false otherwise
74+
*/
75+
virtual bool
76+
isBlockingClio() const = 0;
77+
};
78+
79+
} // namespace migration
Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above
@@ -19,59 +19,23 @@
1919

2020
#pragma once
2121

22-
#include "migration/MigratiorStatus.hpp"
22+
#include "migration/MigrationInspectorInterface.hpp"
2323

2424
#include <string>
25-
#include <tuple>
26-
#include <vector>
2725

2826
namespace migration {
2927

3028
/**
31-
* @brief The interface for the migration manager. This interface is tend to be implemented for specific database. The
32-
* application layer will use this interface to run the migrations.
29+
* @brief The interface for the migration manager. The migration application layer will use this interface to run the
30+
* migrations. Unlike the MigrationInspectorInterface which only provides the status of migration, this interface
31+
* contains the acutal migration running method.
3332
*/
34-
struct MigrationManagerInterface {
35-
virtual ~MigrationManagerInterface() = default;
36-
33+
struct MigrationManagerInterface : virtual public MigrationInspectorInterface {
3734
/**
3835
* @brief Run the the migration according to the given migrator's name
3936
*/
4037
virtual void
4138
runMigration(std::string const&) = 0;
42-
43-
/**
44-
* @brief Get the status of all the migrators
45-
* @return A vector of tuple, the first element is the migrator's name, the second element is the status of the
46-
*/
47-
virtual std::vector<std::tuple<std::string, MigratorStatus>>
48-
allMigratorsStatusPairs() const = 0;
49-
50-
/**
51-
* @brief Get all registered migrators' names
52-
*
53-
* @return A vector of migrators' names
54-
*/
55-
virtual std::vector<std::string>
56-
allMigratorsNames() const = 0;
57-
58-
/**
59-
* @brief Get the status of a migrator by its name
60-
*
61-
* @param name The migrator's name
62-
* @return The status of the migrator
63-
*/
64-
virtual MigratorStatus
65-
getMigratorStatusByName(std::string const& name) const = 0;
66-
67-
/**
68-
* @brief Get the description of a migrator by its name
69-
*
70-
* @param name The migrator's name
71-
* @return The description of the migrator
72-
*/
73-
virtual std::string
74-
getMigratorDescriptionByName(std::string const& name) const = 0;
7539
};
7640

7741
} // namespace migration

src/migration/MigratiorStatus.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above

src/migration/MigratorStatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
/*
33
This file is part of clio: https://github.com/XRPLF/clio
4-
Copyright (c) 2022-2024, the clio developers.
4+
Copyright (c) 2024, the clio developers.
55
66
Permission to use, copy, modify, and distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above

0 commit comments

Comments
 (0)