mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
13,838 upstream commits, forward from the 26.6.1.1 fork point. 129 conflicts: 37 resolved mechanically (take upstream's file, re-apply the brand sweep) and 92 by hand where our fork and upstream had both changed the same code. The rule throughout: upstream owns the engine, we own the naming and a small set of deliberate deviations. Never resolve by discarding an upstream change — a dropped rename or a missed new parameter becomes a compile error a thousand files away. Deviations verified intact after the merge: ENABLE_XRAY still defaults OFF (CMakeLists.txt:105) X-Datastore-User read by the server (authenticateUserByHTTP.cpp) X-ClickHouse-* in src/ 0 hanzo/research present system.*_log retention bound present ArrowFlight rip held against upstream re-adding it Two things worth naming, because neither shows up as a conflict: src/CMakeLists.txt gained an UNGUARDED `add_object_library(datastore_storages_arrowflight Storages/ArrowFlight)` from upstream, for a directory our gRPC rip deleted. It sat outside every conflict hunk, so a resolver reading only the markers would sail straight past it into a CMake configure error. Removed; the Server/ArrowFlight sibling at line 474 stays because it is inside `if (TARGET ch_contrib::arrow_flight)`. The brand sweep had rewritten github.com/ClickHouse/ClickHouse issue links to github.com/Datastore/Datastore — a dead host. Those point at upstream's own tracker and are restored, alongside the contributors list, sql.clickhouse.com and the ClickHouse Inc copyright: attribution is theirs, not ours to rename. base/glibc-compatibility/memcpy/memcpy.h is deleted, not kept: upstream dropped it for LLVM-libc's, and our only change to it was a comment rebrand.
143 lines
4.0 KiB
C++
143 lines
4.0 KiB
C++
#pragma once
|
|
|
|
#include <config.h>
|
|
|
|
#include <optional>
|
|
#include <Disks/DiskSelector.h>
|
|
#include <Disks/IDisk.h>
|
|
|
|
#include <boost/any/bad_any_cast.hpp>
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include <Poco/Util/Application.h>
|
|
#include <Common/Exception.h>
|
|
#include <Common/Config/ConfigProcessor.h>
|
|
|
|
#include <boost/program_options/positional_options.hpp>
|
|
|
|
#include <DisksApp.h>
|
|
|
|
#include <DisksClient.h>
|
|
|
|
#include <ICommand_fwd.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace po = boost::program_options;
|
|
using ProgramOptionsDescription = po::options_description;
|
|
using PositionalProgramOptionsDescription = po::positional_options_description;
|
|
using CommandLineOptions = po::variables_map;
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int BAD_ARGUMENTS;
|
|
}
|
|
|
|
class ICommand
|
|
{
|
|
public:
|
|
explicit ICommand(String logger_name) : log(getLogger(logger_name)) { }
|
|
|
|
virtual ~ICommand() = default;
|
|
|
|
void execute(const Strings & arguments, DisksClient & client);
|
|
|
|
virtual void executeImpl(const CommandLineOptions & options, DisksClient & client) = 0;
|
|
|
|
CommandLineOptions processCommandLineArguments(const Strings & arguments);
|
|
|
|
protected:
|
|
template <typename T>
|
|
static T getValueFromCommandLineOptions(const CommandLineOptions & options, const String & name)
|
|
{
|
|
try
|
|
{
|
|
return options[name].as<T>();
|
|
}
|
|
catch (boost::bad_any_cast &)
|
|
{
|
|
throw DB::Exception(ErrorCodes::BAD_ARGUMENTS, "Argument '{}' has wrong type and can't be parsed", name);
|
|
}
|
|
}
|
|
|
|
template <typename T>
|
|
static T getValueFromCommandLineOptionsThrow(const CommandLineOptions & options, const String & name)
|
|
{
|
|
if (options.contains(name))
|
|
return getValueFromCommandLineOptions<T>(options, name);
|
|
|
|
throw DB::Exception(ErrorCodes::BAD_ARGUMENTS, "Mandatory argument '{}' is missing", name);
|
|
}
|
|
|
|
template <typename T>
|
|
static T getValueFromCommandLineOptionsWithDefault(const CommandLineOptions & options, const String & name, const T & default_value)
|
|
{
|
|
if (options.contains(name))
|
|
return getValueFromCommandLineOptions<T>(options, name);
|
|
|
|
return default_value;
|
|
}
|
|
|
|
template <typename T>
|
|
static std::optional<T> getValueFromCommandLineOptionsWithOptional(const CommandLineOptions & options, const String & name)
|
|
{
|
|
if (options.contains(name))
|
|
return std::optional{getValueFromCommandLineOptions<T>(options, name)};
|
|
|
|
return std::nullopt;
|
|
}
|
|
|
|
DiskWithPath & getDiskWithPath(DisksClient & client, const CommandLineOptions & options, const String & name);
|
|
|
|
String getTargetLocation(const String & path_from, DiskWithPath & disk_to, const String & path_to)
|
|
{
|
|
if (!disk_to.getDisk()->existsDirectory(path_to))
|
|
{
|
|
return path_to;
|
|
}
|
|
String copied_path_from = path_from;
|
|
if (copied_path_from.ends_with('/'))
|
|
{
|
|
copied_path_from.pop_back();
|
|
}
|
|
String plain_filename = fs::path(copied_path_from).filename();
|
|
|
|
return fs::path{path_to} / plain_filename;
|
|
}
|
|
|
|
|
|
public:
|
|
String command_name;
|
|
String description;
|
|
ProgramOptionsDescription options_description;
|
|
|
|
protected:
|
|
PositionalProgramOptionsDescription positional_options_description;
|
|
LoggerPtr log;
|
|
};
|
|
|
|
DB::CommandPtr makeCommandCopy();
|
|
DB::CommandPtr makeCommandListDisks();
|
|
DB::CommandPtr makeCommandList();
|
|
DB::CommandPtr makeCommandChangeDirectory();
|
|
DB::CommandPtr makeCommandLink();
|
|
DB::CommandPtr makeCommandMove();
|
|
DB::CommandPtr makeCommandRead();
|
|
DB::CommandPtr makeCommandReadBitmap();
|
|
DB::CommandPtr makeCommandRemove();
|
|
DB::CommandPtr makeCommandWrite();
|
|
DB::CommandPtr makeCommandSed();
|
|
DB::CommandPtr makeCommandMkDir();
|
|
DB::CommandPtr makeCommandSwitchDisk();
|
|
DB::CommandPtr makeCommandGetCurrentDiskAndPath();
|
|
DB::CommandPtr makeCommandHelp(const DisksApp & disks_app);
|
|
DB::CommandPtr makeCommandTouch();
|
|
DB::CommandPtr makeCommandDiskUsage();
|
|
DB::CommandPtr makeCommandWordCount();
|
|
DB::CommandPtr makeCommandReadChecksums();
|
|
#if DATASTORE_CLOUD
|
|
DB::CommandPtr makeCommandPackedIO();
|
|
#endif
|
|
}
|