-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
afs-client-accessd: allow configuration of export time #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,15 @@ Example: | |
|
||
AUDIT_PATH => '/usr/afs/logs/FileAudit', | ||
|
||
=item EXPORT_TIME | ||
|
||
This specifies the hour of the day (UTC) in which the *.sqlite files should be | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace "should be" with "are scheduled". Should mention this is the "approximate scheduled time of day". |
||
exported to the central host. The default is 0 (midnight). | ||
|
||
Example: | ||
|
||
EXPORT_TIME => 16, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Export hour? |
||
|
||
=item SQLITE_PREFIX | ||
|
||
This specifies the directory in which the local disk databases will be stored | ||
|
@@ -581,6 +590,7 @@ read_config() | |
|
||
MSGRCV_WORKAROUND => 0, | ||
USE_FQDN => 0, | ||
EXPORT_TIME => 0, | ||
); | ||
|
||
if (!-r $CONFIG_FILE) { | ||
|
@@ -601,6 +611,11 @@ read_config() | |
$newcfg{$_} = $override{$_}; | ||
} | ||
|
||
if ($newcfg{EXPORT_TIME} < 0 || $newcfg{EXPORT_TIME} > 24) { | ||
$newcfg{EXPORT_TIME} = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if possible, but it would be better if we could log a warning if changing a value which is out of range. |
||
} | ||
$newcfg{EXPORT_TIME} = $newcfg{EXPORT_TIME} * 60 * 60; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not convert the new config value here. If you want to do the conversion once, maybe create a new variable? If feels very side-effectly. |
||
|
||
my $err = ''; | ||
if (! -d $newcfg{SQLITE_PREFIX}) { | ||
$err .= "SQLITE_PREFIX dir $newcfg{SQLITE_PREFIX} does not exist\n"; | ||
|
@@ -1230,6 +1245,27 @@ spawn_exporter() | |
exit(0); | ||
} | ||
|
||
sub | ||
time_to_export() | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After thinking about this a bit, I think this function is not clear to me because it is doing several different things. I feel it would be more clear if we had functions which had more clear intent. For example, for this feature we need to do the following, which can be though of as functions. Each take arguments which evaluate to one (and only one) result value.
In addition, we can make this more clear by declaring constant values as perl constants. That helps because it shows intent to the programmer and the interpreter which things are not going to change as the program runs. Here's some example code (not tested) that shows what I mean.
|
||
my $current_time = time(); | ||
|
||
my $sec_per_day = 24 * 60 * 60; | ||
my $midnight = $current_time - ($current_time % $sec_per_day); | ||
|
||
my $exp_time = $midnight + $CFG{EXPORT_TIME}; | ||
|
||
my $fluctuation = 90; | ||
my $range = (ALARM_INTERVAL / 2) + $fluctuation; | ||
|
||
if (($current_time > ($exp_time - $range)) && | ||
($current_time <= ($exp_time + $range))) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
my $checksignals_firstrun = 1; | ||
# check for changes flagged by a signal handler | ||
sub | ||
|
@@ -1295,10 +1331,6 @@ checksignals() | |
|
||
stop_collection($next_dbname); | ||
|
||
# export database in the background | ||
d("Spawning exporter due to db name change"); | ||
spawn_exporter(); | ||
|
||
$CUR_DBNAME = $next_dbname; | ||
|
||
# set up our sqlite stuff again so we can record new data to it | ||
|
@@ -1322,6 +1354,18 @@ checksignals() | |
spawn_exporter(); | ||
} | ||
|
||
my $sig_alarm = 0; | ||
|
||
if (!$SIGNAL_SHUTDOWN && !$SIGNAL_CHILD && !$SIGNAL_CONFIG) { | ||
$sig_alarm = 1; | ||
} | ||
|
||
if (!$EXPORTER_PID && $sig_alarm && time_to_export()) { | ||
# export database in the background | ||
d("Spawning exporter due to time_to_export"); | ||
spawn_exporter(); | ||
} | ||
|
||
$checksignals_firstrun = 0; | ||
|
||
$SIGNAL_SHUTDOWN = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name might be a bit confusing, since it is not set at the "export time" but the hour of the day (in utc) the export is scheduled. Internally you've converted the value to be the epoch time by multiply the value the user gave by the number of seconds per day.
I think it would be more clear to all this EXPORT_HOUR since it is the hour the export is scheduled.