Skip to content

Commit d79dac5

Browse files
committed
Merge MaintenanceManager into DatabaseManager
1 parent 1c5230d commit d79dac5

7 files changed

Lines changed: 319 additions & 447 deletions

File tree

src/fb-cpp/DatabaseManager.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,46 @@ void DatabaseManager::execute(const DatabaseManagerOptions& options)
6565
startAction(std::vector<std::uint8_t>(buffer, buffer + length));
6666
waitForCompletion();
6767
}
68+
69+
70+
void DatabaseManager::execute(const MaintenanceOptions& options)
71+
{
72+
StatusWrapper statusWrapper{getClient()};
73+
auto builder =
74+
fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0));
75+
76+
builder->insertTag(&statusWrapper, isc_action_svc_repair);
77+
builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str());
78+
79+
int optionsVal = 0;
80+
if (options.getSweep())
81+
optionsVal |= isc_spb_rpr_sweep_db;
82+
if (options.getValidate())
83+
optionsVal |= isc_spb_rpr_validate_db;
84+
if (options.getMend())
85+
optionsVal |= isc_spb_rpr_mend_db;
86+
if (options.getIgnoreChecksum())
87+
optionsVal |= isc_spb_rpr_ignore_checksum;
88+
if (options.getKillShadows())
89+
optionsVal |= isc_spb_rpr_kill_shadows;
90+
if (options.getFull())
91+
optionsVal |= isc_spb_rpr_full;
92+
if (options.getCheckDb())
93+
optionsVal |= isc_spb_rpr_check_db;
94+
if (options.getIcu())
95+
optionsVal |= isc_spb_rpr_icu;
96+
if (options.getUpgradeDb())
97+
optionsVal |= isc_spb_rpr_upgrade_db;
98+
99+
if (optionsVal != 0)
100+
builder->insertInt(&statusWrapper, isc_spb_options, optionsVal);
101+
102+
if (const auto parallelWorkers = options.getParallelWorkers())
103+
builder->insertInt(&statusWrapper, isc_spb_rpr_par_workers, static_cast<int>(*parallelWorkers));
104+
105+
const auto buffer = builder->getBuffer(&statusWrapper);
106+
const auto length = builder->getBufferLength(&statusWrapper);
107+
108+
startAction(std::vector<std::uint8_t>(buffer, buffer + length));
109+
waitForCompletion(options.getVerboseOutput());
110+
}

src/fb-cpp/DatabaseManager.h

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define FBCPP_DATABASE_MANAGER_H
2727

2828
#include "ServiceManager.h"
29+
#include <cstdint>
2930
#include <optional>
3031
#include <string>
3132

@@ -80,6 +81,231 @@ namespace fbcpp
8081
std::optional<ReplicaMode> replicaMode;
8182
};
8283

84+
///
85+
/// Represents options used to run a database maintenance operation through the service manager.
86+
///
87+
class MaintenanceOptions final
88+
{
89+
public:
90+
///
91+
/// Returns the database path to be maintained.
92+
///
93+
const std::string& getDatabase() const
94+
{
95+
return database;
96+
}
97+
98+
///
99+
/// Sets the database path to be maintained.
100+
///
101+
MaintenanceOptions& setDatabase(const std::string& value)
102+
{
103+
database = value;
104+
return *this;
105+
}
106+
107+
///
108+
/// Returns the verbose output callback.
109+
///
110+
const ServiceManager::VerboseOutput& getVerboseOutput() const
111+
{
112+
return verboseOutput;
113+
}
114+
115+
///
116+
/// Sets the verbose output callback.
117+
///
118+
MaintenanceOptions& setVerboseOutput(ServiceManager::VerboseOutput value)
119+
{
120+
verboseOutput = std::move(value);
121+
return *this;
122+
}
123+
124+
///
125+
/// Returns the requested number of parallel workers.
126+
///
127+
const std::optional<std::uint32_t>& getParallelWorkers() const
128+
{
129+
return parallelWorkers;
130+
}
131+
132+
///
133+
/// Sets the requested number of parallel workers.
134+
///
135+
MaintenanceOptions& setParallelWorkers(std::uint32_t value)
136+
{
137+
parallelWorkers = value;
138+
return *this;
139+
}
140+
141+
///
142+
/// Returns whether database sweep is enabled.
143+
///
144+
bool getSweep() const
145+
{
146+
return sweep;
147+
}
148+
149+
///
150+
/// Sets whether database sweep is enabled.
151+
///
152+
MaintenanceOptions& setSweep(bool value)
153+
{
154+
sweep = value;
155+
return *this;
156+
}
157+
158+
///
159+
/// Returns whether database validation is enabled.
160+
///
161+
bool getValidate() const
162+
{
163+
return validate;
164+
}
165+
166+
///
167+
/// Sets whether database validation is enabled.
168+
///
169+
MaintenanceOptions& setValidate(bool value)
170+
{
171+
validate = value;
172+
return *this;
173+
}
174+
175+
///
176+
/// Returns whether database mending is enabled.
177+
///
178+
bool getMend() const
179+
{
180+
return mend;
181+
}
182+
183+
///
184+
/// Sets whether database mending is enabled.
185+
///
186+
MaintenanceOptions& setMend(bool value)
187+
{
188+
mend = value;
189+
return *this;
190+
}
191+
192+
///
193+
/// Returns whether checksum verification is ignored.
194+
///
195+
bool getIgnoreChecksum() const
196+
{
197+
return ignoreChecksum;
198+
}
199+
200+
///
201+
/// Sets whether checksum verification is ignored.
202+
///
203+
MaintenanceOptions& setIgnoreChecksum(bool value)
204+
{
205+
ignoreChecksum = value;
206+
return *this;
207+
}
208+
209+
///
210+
/// Returns whether killing database shadows is enabled.
211+
///
212+
bool getKillShadows() const
213+
{
214+
return killShadows;
215+
}
216+
217+
///
218+
/// Sets whether killing database shadows is enabled.
219+
///
220+
MaintenanceOptions& setKillShadows(bool value)
221+
{
222+
killShadows = value;
223+
return *this;
224+
}
225+
226+
///
227+
/// Returns whether full validation is enabled.
228+
///
229+
bool getFull() const
230+
{
231+
return full;
232+
}
233+
234+
///
235+
/// Sets whether full validation is enabled.
236+
///
237+
MaintenanceOptions& setFull(bool value)
238+
{
239+
full = value;
240+
return *this;
241+
}
242+
243+
///
244+
/// Returns whether checking only metadata/structure is enabled.
245+
///
246+
bool getCheckDb() const
247+
{
248+
return checkDb;
249+
}
250+
251+
///
252+
/// Sets whether checking only metadata/structure is enabled.
253+
///
254+
MaintenanceOptions& setCheckDb(bool value)
255+
{
256+
checkDb = value;
257+
return *this;
258+
}
259+
260+
///
261+
/// Returns whether recreating ICU indexes is enabled.
262+
///
263+
bool getIcu() const
264+
{
265+
return icu;
266+
}
267+
268+
///
269+
/// Sets whether recreating ICU indexes is enabled.
270+
///
271+
MaintenanceOptions& setIcu(bool value)
272+
{
273+
icu = value;
274+
return *this;
275+
}
276+
277+
///
278+
/// Returns whether database upgrade is enabled.
279+
///
280+
bool getUpgradeDb() const
281+
{
282+
return upgradeDb;
283+
}
284+
285+
///
286+
/// Sets whether database upgrade is enabled.
287+
///
288+
MaintenanceOptions& setUpgradeDb(bool value)
289+
{
290+
upgradeDb = value;
291+
return *this;
292+
}
293+
294+
private:
295+
std::string database;
296+
ServiceManager::VerboseOutput verboseOutput;
297+
std::optional<std::uint32_t> parallelWorkers;
298+
bool sweep = false;
299+
bool validate = false;
300+
bool mend = false;
301+
bool ignoreChecksum = false;
302+
bool killShadows = false;
303+
bool full = false;
304+
bool checkDb = false;
305+
bool icu = false;
306+
bool upgradeDb = false;
307+
};
308+
83309
///
84310
/// Executes configuration and maintenance operations through the Firebird service manager.
85311
///
@@ -93,6 +319,11 @@ namespace fbcpp
93319
/// Configures database properties using the provided options.
94320
///
95321
void execute(const DatabaseManagerOptions& options);
322+
323+
///
324+
/// Runs a maintenance or repair operation using the provided options.
325+
///
326+
void execute(const MaintenanceOptions& options);
96327
};
97328
} // namespace fbcpp
98329

src/fb-cpp/MaintenanceManager.cpp

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)