2023-04-26 04:54:28 +00:00
# pragma once
# include "Parser.h"
namespace DB
{
class KeeperClient ;
class IKeeperClientCommand
{
public :
static const String name ;
virtual bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const = 0 ;
virtual void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const = 0 ;
virtual String getHelpMessage ( ) const = 0 ;
virtual String getName ( ) const = 0 ;
virtual ~ IKeeperClientCommand ( ) = default ;
2023-06-21 03:41:48 +00:00
String generateHelpString ( ) const
{
return fmt : : vformat ( getHelpMessage ( ) , fmt : : make_format_args ( getName ( ) ) ) ;
}
2023-04-26 04:54:28 +00:00
} ;
using Command = std : : shared_ptr < IKeeperClientCommand > ;
class LSCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " ls " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} [path] -- Lists the nodes for the given path (default: cwd) " ; }
2023-04-26 04:54:28 +00:00
} ;
class CDCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " cd " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} [path] -- Change the working path (default `.`) " ; }
2023-04-26 04:54:28 +00:00
} ;
class SetCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " set " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
String getHelpMessage ( ) const override
{
2023-06-21 03:41:48 +00:00
return " {} <path> <value> [version] -- Updates the node's value. Only update if version matches (default: -1) " ;
2023-04-26 04:54:28 +00:00
}
} ;
class CreateCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " create " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-08-07 16:08:31 +00:00
String getHelpMessage ( ) const override { return " {} <path> <value> [mode] -- Creates new node with the set value " ; }
} ;
class TouchCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " touch " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
String getHelpMessage ( ) const override { return " {} <path> -- Creates new node with an empty string as value. Doesn't throw an exception if the node already exists " ; }
2023-04-26 04:54:28 +00:00
} ;
class GetCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " get " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} <path> -- Returns the node's value " ; }
2023-04-26 04:54:28 +00:00
} ;
2023-06-17 03:24:10 +00:00
class GetStatCommand : public IKeeperClientCommand
{
2023-07-21 22:14:30 +00:00
String getName ( ) const override { return " get_stat " ; }
2023-06-17 03:24:10 +00:00
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} [path] -- Returns the node's stat (default `.`) " ; }
2023-06-17 03:24:10 +00:00
} ;
2023-07-26 05:57:16 +00:00
class FindSuperNodes : public IKeeperClientCommand
2023-06-17 03:24:10 +00:00
{
2023-06-21 03:41:48 +00:00
String getName ( ) const override { return " find_super_nodes " ; }
2023-06-17 03:24:10 +00:00
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
String getHelpMessage ( ) const override
{
2023-06-21 03:41:48 +00:00
return " {} <threshold> [path] -- Finds nodes with number of children larger than some threshold for the given path (default `.`) " ;
2023-06-17 03:24:10 +00:00
}
} ;
2023-08-07 16:08:31 +00:00
class DeleteStaleBackups : public IKeeperClientCommand
2023-06-21 03:41:48 +00:00
{
2023-08-07 16:08:31 +00:00
String getName ( ) const override { return " delete_stale_backups " ; }
2023-06-21 03:41:48 +00:00
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
String getHelpMessage ( ) const override
{
return " {} -- Deletes ClickHouse nodes used for backups that are now inactive " ;
}
} ;
class FindBigFamily : public IKeeperClientCommand
{
String getName ( ) const override { return " find_big_family " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
String getHelpMessage ( ) const override
{
return " {} [path] [n] -- Returns the top n nodes with the biggest family in the subtree (default path = `.` and n = 10) " ;
}
} ;
2023-04-26 04:54:28 +00:00
class RMCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " rm " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} <path> -- Remove the node " ; }
2023-04-26 04:54:28 +00:00
} ;
class RMRCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " rmr " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} <path> -- Recursively deletes path. Confirmation required " ; }
2023-04-26 04:54:28 +00:00
} ;
class HelpCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " help " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} -- Prints this message " ; }
2023-04-26 04:54:28 +00:00
} ;
class FourLetterWordCommand : public IKeeperClientCommand
{
String getName ( ) const override { return " flwc " ; }
bool parse ( IParser : : Pos & pos , std : : shared_ptr < ASTKeeperQuery > & node , Expected & expected ) const override ;
void execute ( const ASTKeeperQuery * query , KeeperClient * client ) const override ;
2023-06-21 03:41:48 +00:00
String getHelpMessage ( ) const override { return " {} <command> -- Executes four-letter-word command " ; }
2023-04-26 04:54:28 +00:00
} ;
}