@@ -106,11 +106,13 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
106106 std::cerr << " c - compress" << std::endl;
107107 std::cerr << " x - decompress" << std::endl;
108108 std::cerr << " s - search" << std::endl;
109+ std::cerr << " i - compress IR format" << std::endl;
109110 std::cerr << std::endl;
110111 std::cerr << " Try "
111112 << " c --help OR"
112113 << " x --help OR"
113- << " s --help for command-specific details." << std::endl;
114+ << " s --help OR"
115+ << " i --help for command-specific details." << std::endl;
114116
115117 po::options_description visible_options;
116118 visible_options.add (general_options);
@@ -125,6 +127,7 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
125127 case (char )Command::Compress:
126128 case (char )Command::Extract:
127129 case (char )Command::Search:
130+ case (char )Command::IrCompress:
128131 m_command = (Command)command_input;
129132 break ;
130133 default :
@@ -696,6 +699,147 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
696699 " The --count-by-time and --count options are mutually exclusive."
697700 );
698701 }
702+ } else if (Command::IrCompress == m_command) {
703+ po::options_description compression_positional_options;
704+ // clang-format off
705+ compression_positional_options.add_options ()(
706+ " archives-dir" ,
707+ po::value<std::string>(&m_archives_dir)->value_name (" DIR" ),
708+ " output directory"
709+ )(
710+ " input-paths" ,
711+ po::value<std::vector<std::string>>(&m_file_paths)->value_name (" PATHS" ),
712+ " input paths"
713+ );
714+ // clang-format on
715+
716+ po::options_description compression_options (" Compression options" );
717+ std::string metadata_db_config_file_path;
718+ std::string input_path_list_file_path;
719+ // clang-format off
720+ compression_options.add_options ()(
721+ " compression-level" ,
722+ po::value<int >(&m_compression_level)->value_name (" LEVEL" )->
723+ default_value (m_compression_level),
724+ " 1 (fast/low compression) to 9 (slow/high compression)."
725+ )(
726+ " target-encoded-size" ,
727+ po::value<size_t >(&m_target_encoded_size)->value_name (" TARGET_ENCODED_SIZE" )->
728+ default_value (m_target_encoded_size),
729+ " Target size (B) for the dictionaries and encoded messages before a new "
730+ " archive is created."
731+ )(
732+ " min-table-size" ,
733+ po::value<size_t >(&m_minimum_table_size)->value_name (" MIN_TABLE_SIZE" )->
734+ default_value (m_minimum_table_size),
735+ " Minimum size (B) for a packed table before it gets compressed."
736+ )(
737+ " max-document-size" ,
738+ po::value<size_t >(&m_max_document_size)->value_name (" DOC_SIZE" )->
739+ default_value (m_max_document_size),
740+ " Maximum allowed size (B) for a single document before compression fails."
741+ )(
742+ " timestamp-key" ,
743+ po::value<std::string>(&m_timestamp_key)->value_name (" TIMESTAMP_COLUMN_KEY" )->
744+ default_value (m_timestamp_key),
745+ " Path (e.g. x.y) for the field containing the log event's timestamp."
746+ )(
747+ " db-config-file" ,
748+ po::value<std::string>(&metadata_db_config_file_path)->value_name (" FILE" )->
749+ default_value (metadata_db_config_file_path),
750+ " Global metadata DB YAML config"
751+ )(
752+ " files-from,f" ,
753+ po::value<std::string>(&input_path_list_file_path)
754+ ->value_name (" FILE" )
755+ ->default_value (input_path_list_file_path),
756+ " Compress files specified in FILE"
757+ )(
758+ " print-archive-stats" ,
759+ po::bool_switch (&m_print_archive_stats),
760+ " Print statistics (json) about the archive after it's compressed."
761+ )(
762+ " single-file-archive" ,
763+ po::bool_switch (&m_single_file_archive),
764+ " Create a single archive file instead of multiple files."
765+ )(
766+ " disable-log-order" ,
767+ po::bool_switch (&m_disable_log_order),
768+ " Do not record log order at ingestion time."
769+ );
770+ // clang-format on
771+
772+ po::positional_options_description positional_options;
773+ positional_options.add (" archives-dir" , 1 );
774+ positional_options.add (" input-paths" , -1 );
775+
776+ po::options_description all_compression_options;
777+ all_compression_options.add (compression_options);
778+ all_compression_options.add (compression_positional_options);
779+
780+ std::vector<std::string> unrecognized_options
781+ = po::collect_unrecognized (parsed.options , po::include_positional);
782+ unrecognized_options.erase (unrecognized_options.begin ());
783+ po::store (
784+ po::command_line_parser (unrecognized_options)
785+ .options (all_compression_options)
786+ .positional (positional_options)
787+ .run (),
788+ parsed_command_line_options
789+ );
790+ po::notify (parsed_command_line_options);
791+
792+ if (parsed_command_line_options.count (" help" )) {
793+ print_ir_compression_usage ();
794+
795+ std::cerr << " Examples:\n " ;
796+ std::cerr << " # Compress file1.ir and dir1 into archives-dir\n " ;
797+ std::cerr << " " << m_program_name << " i archives-dir file1.ir dir1\n " ;
798+
799+ po::options_description visible_options;
800+ visible_options.add (general_options);
801+ visible_options.add (compression_options);
802+ std::cerr << visible_options << ' \n ' ;
803+ return ParsingResult::InfoCommand;
804+ }
805+
806+ if (m_archives_dir.empty ()) {
807+ throw std::invalid_argument (" No archives directory specified." );
808+ }
809+
810+ if (false == input_path_list_file_path.empty ()) {
811+ if (false == read_paths_from_file (input_path_list_file_path, m_file_paths)) {
812+ SPDLOG_ERROR (" Failed to read paths from {}" , input_path_list_file_path);
813+ return ParsingResult::Failure;
814+ }
815+ }
816+
817+ if (m_file_paths.empty ()) {
818+ throw std::invalid_argument (" No input paths specified." );
819+ }
820+
821+ // Parse and validate global metadata DB config
822+ if (false == metadata_db_config_file_path.empty ()) {
823+ clp::GlobalMetadataDBConfig metadata_db_config;
824+ try {
825+ metadata_db_config.parse_config_file (metadata_db_config_file_path);
826+ } catch (std::exception& e) {
827+ SPDLOG_ERROR (" Failed to validate metadata database config - {}." , e.what ());
828+ return ParsingResult::Failure;
829+ }
830+
831+ if (clp::GlobalMetadataDBConfig::MetadataDBType::MySQL
832+ != metadata_db_config.get_metadata_db_type ())
833+ {
834+ SPDLOG_ERROR (
835+ " Invalid metadata database type for {}; only supported type is MySQL." ,
836+ m_program_name
837+ );
838+ return ParsingResult::Failure;
839+ }
840+
841+ m_metadata_db_config = std::move (metadata_db_config);
842+ }
699843 }
700844 } catch (std::exception& e) {
701845 SPDLOG_ERROR (" {}" , e.what ());
@@ -809,4 +953,8 @@ void CommandLineArguments::print_search_usage() const {
809953 " [OUTPUT_HANDLER [OUTPUT_HANDLER_OPTIONS]]"
810954 << std::endl;
811955}
956+
957+ void CommandLineArguments::print_ir_compression_usage () const {
958+ std::cerr << " Usage: " << m_program_name << " i [OPTIONS] ARCHIVES_DIR [FILE/DIR ...]\n " ;
959+ }
812960} // namespace clp_s
0 commit comments