@@ -369,11 +369,11 @@ sub load_db_schemas_in_influxdb {
369369# $schema_dir string: the directory name where the config files are
370370#
371371# Returns:
372- # a reference to a hash holding the parsed statements. This hash is structured as below.
373- # TODO: fix indentation
372+ # $db_schemas: a reference to a hash holding the parsed statements. This hash is structured as below.
373+ #
374374# {
375- # <db name > => {
376- # <rp name > => {
375+ # <db> => {
376+ # <rp> => {
377377# duration => ...,
378378# shard_duration => ...,
379379# default => ...,
@@ -387,39 +387,37 @@ sub load_db_schemas_in_influxdb {
387387sub load_db_schemas_in_config {
388388 my ($schema_dir ) = @_ ;
389389
390- # this will be populated with all statements parsed from the files
391- my %parsed_statements ;
390+ my %db_schemas ;
392391 my $db_files = get_schema_files_for_dir(" $schema_dir /db" );
393392
394393 for my $db_file (@$db_files ) {
395394 my $statements_in_file = read_text(" $schema_dir /db/$db_file " );
396- # my $parsed_statements_from_file = parse_statements($statements_in_file);
397395 my ($databases , $rps ) = parse_statements($statements_in_file );
398396
399- # add the statements from this file to the initial hash
400- # TODO: merge database list and rp list to create a hash which only contains each database and each rp policy once
401- # TODO: hash: database name -> rp name ->
402-
397+ # loop all the databases and add them to the hash
403398 for my $db (@$databases ) {
404- if (exists $parsed_statements {$db }) {
399+ # make sure every database is only created once
400+ if (exists $db_schemas {$db }) {
405401 die " duplicate database $db in file $db_file detected\n " ;
406402 }
407- $parsed_statements {$db } = {};
403+ $db_schemas {$db } = {};
408404 }
405+ # loop all the retention policies and assign them to the correct database
409406 for my $rp (@$rps ) {
410407 my $db = $rp -> {database };
411- if (exists $parsed_statements {$db }) {
412- if (exists $parsed_statements {$db }-> {$rp -> {rp_name }}) {
408+ if (exists $db_schemas {$db }) {
409+ # make sure every retention policy is only created once
410+ if (exists $db_schemas {$db }-> {$rp -> {rp_name }}) {
413411 die " duplicate rp $rp on db $db in file $db_file detected\n " ;
414412 }
415- $parsed_statements {$db }-> {$rp -> {rp_name }} = $rp ;
413+ $db_schemas {$db }-> {$rp -> {rp_name }} = $rp ;
416414 }
417415 else {
418416 die " database $db specified in rp $rp from file $db_file does not exist\n " ;
419417 }
420418 }
421419 }
422- return \%parsed_statements ;
420+ return \%db_schemas ;
423421}
424422
425423#
@@ -430,13 +428,12 @@ sub load_db_schemas_in_config {
430428#
431429# Arguments:
432430# $string_to_parse string: the contents of the config file (loaded as string)
433- # $parsed_statements reference: a reference to a hash. The function will populate it with the parsed statements.
434431#
435432# Returns:
436- # a reference to a hash holding the parsed statements from the file.
433+ # $databases: reference to a list which contains all the database names
434+ # $rps: reference to a list which contains hashes of all the retention policies
437435#
438436sub parse_statements {
439- # TODO: should return 2 lists: 1 list of databases and 1 list of retention policies
440437 my ($string_to_parse ) = @_ ;
441438 # we want to iterate line-by-line
442439 my @splitted_lines = split " \n " , $string_to_parse ;
@@ -492,13 +489,10 @@ sub parse_statements {
492489
493490 # the line is a 'create database' statement...
494491 if ($create_db_statement ) {
495- # TODO: remove: check_if_db_statement_exists_and_die(\%parsed_statements, $db_name);
496492 push @databases , $db_name ;
497- # $parsed_statements{$db_name}{create_query} = $create_db_statement . ';';
498493 # ...and has a retention policy defined inline
499494 if ($inline_rp_statement ) {
500- # flagged as the default policy (assume that the inline policy is the default)
501- # TODO: hash -> new list
495+ # flagged as the default policy (assume that the inline policy is the default)ƒ
502496 push @rps , {
503497 database => $db_name ,
504498 rp_name => $inline_rp_name ,
@@ -510,7 +504,6 @@ sub parse_statements {
510504 }
511505 }
512506 # the line is a 'create retention policy' statement
513- # TODO: add to rp list
514507 elsif ($rp_name ) {
515508 push @rps , {
516509 database => $rp_db_name ,
@@ -532,26 +525,6 @@ sub parse_statements {
532525 return return \@databases , \@rps ;
533526}
534527
535-
536- #
537- # Checks if the db creation statement is already added in the parsed statements hash. If yes then it throws an exception.
538- #
539- # Arguments:
540- # $parsed_statements reference: a reference to the hash containing the db statements
541- # $db_name string:
542- # Returns:
543- # -
544- #
545- sub check_if_db_statement_exists_and_die {
546- my ($parsed_statements , $db_name ) = @_ ;
547-
548- # there should be no 'create database' statement yet for this database
549- if ($parsed_statements -> {$db_name }{create_query }) {
550- die " Create statement already defined for database $db_name . Fix the config file" ;
551- }
552- }
553-
554-
555528# {
556529# <db> => {
557530# <cq_name> => <cq_create_query>,
0 commit comments