Skip to content
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

Instant Invalidate for ORT and Traffic Ops #299

Closed
wants to merge 28 commits into from

Conversation

dg4prez
Copy link
Contributor

@dg4prez dg4prez commented Feb 22, 2017

This code change adds a revalidate command line option to ort which will only check the regex_revalidate file. This option requires the use of the reval_pending value, which is enabled by setting the new parameter "use_reval_pending" in global parameters to "1" (the default is zero.) If this value is not found, this option will gracefully quit and syncds should be used. If reval_pending is in use then revalidate will verify that no parents are pending and run. Should syncds be run, it will also verify that no parents have reval_pending flagged in addition to the normal "upd_pending" flag, preventing revalidation in incorrect order.

Because this only checks and modifies the regex_revalidate.config file, this can be run via ort more frequently than normal syncds flags.

Edit: Added a feature by which ORT will check for revalidation files prior to starting a dispersion wait period, and then every sixty seconds (if the dispersion is long enough) thereafter. In this way we can maintain full coverage of invalidation at a rate of 1 pass per minute for the entire hour.

ORT has also been updated to support the new config files API.

@dg4prez dg4prez changed the title Instant Invalidate WIP - Instant Invalidate Feb 22, 2017
@dg4prez dg4prez changed the title WIP - Instant Invalidate Instant Invalidate Feb 22, 2017
@dg4prez dg4prez changed the title Instant Invalidate WIP - Instant Invalidate Feb 22, 2017
@dg4prez dg4prez changed the title WIP - Instant Invalidate Instant Invalidate Feb 22, 2017
@dg4prez dg4prez changed the title Instant Invalidate WIP - Instant Invalidate Feb 22, 2017
my $host_name = $self->param("host_name");
print STDERR Dumper($updated);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should take these out, yea?

my $use_reval_pending = $self->db->resultset('Parameter')->search( { -and => [ 'name' => 'use_reval_pending', 'config_file' => 'global' ] } )->get_column('value')->single;

if ( defined($use_reval_pending) && $use_reval_pending == 1 ) {
print STDERR "updating upd_pending and reval_pending\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. Must have missed those.

@dg4prez dg4prez force-pushed the regex_reval branch 3 times, most recently from 46a00c5 to 0518b91 Compare March 3, 2017 01:33
@dg4prez dg4prez changed the title WIP - Instant Invalidate Please test - Instant Invalidate for ORT and Traffic Ops Mar 3, 2017
@dg4prez dg4prez changed the title Please test - Instant Invalidate for ORT and Traffic Ops Please review - Instant Invalidate for ORT and Traffic Ops Mar 3, 2017
@dg4prez dg4prez force-pushed the regex_reval branch 2 times, most recently from 4a35771 to a683daf Compare March 5, 2017 15:06
@dg4prez dg4prez changed the title Please review - Instant Invalidate for ORT and Traffic Ops Instant Invalidate for ORT and Traffic Ops Mar 6, 2017
@dg4prez dg4prez force-pushed the regex_reval branch 3 times, most recently from 0332016 to 57fb7a8 Compare March 13, 2017 16:48
@@ -0,0 +1,26 @@
/*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this migration file needs a later timestamp on the name. see existing migrations - https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_ops/app/db/migrations

it needs to be timestamped later than the add_client_steering migration...

@@ -76,7 +76,9 @@ sub get_config_metadata {
$data_obj->{'info'}->{'cdn_name'} = $cdn_name;
$data_obj->{'info'}->{'cdn_id'} = $server->cdn->id;
$data_obj->{'info'}->{'tm_url'} = $tm_url;
$data_obj->{'info'}->{'tm_cache_url'} = $tm_cache_url;
if ( $tm_cache_url ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be called to_cache_url instead? it would be nice to get rid of all references to 'tm' at some point if possible...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Done.

&log( $self, "Set upd_pending = 1 for all applicable caches", "OPER" );
my $use_reval_pending = $self->db->resultset('Parameter')->search( { -and => [ 'name' => 'use_reval_pending', 'config_file' => 'global' ] } )->get_column('value')->single;

if ( defined($use_reval_pending) && $use_reval_pending == 1 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it

&& $use_reval_pending == '1'

but i dunno. maybe perl is smart enough to figure it out...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted.

}
}
}
}

while ( my $row = $rs_servers->next ) {
if ( $parent_pending{ $row->host_name } ) {
if ( $parent_pending{ $row->host_name } && $parent_reval_pending{ $row->host_name } ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we collapse this if/elseif...seems like the only thing that is different is the

parent_pending => 0|1,
parent_reval_pending => 0|1

maybe a ternary operator?

parent_pending => (condition) ? \1 : \0,
parent_reval_pending => (condition) ? \1 : \0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Done.


my $use_reval_pending = $self->db->resultset('Parameter')->search( { -and => [ 'name' => 'use_reval_pending', 'config_file' => 'global' ] } )->get_column('value')->single;

if ( defined($use_reval_pending) && $use_reval_pending == 1 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can save a few lines of code here by getting rid of the else and moving

$update_server->update( { upd_pending => $updated } );

below the remaining if...and also leave it out of the if...

If that didn't make sense. basically i'm saying no need to call $update_server->update( { upd_pending => $updated } ); twice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted per discussion.

Copy link
Contributor

@dneuman64 dneuman64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's a lot of comments, hopefully not too much bikeshedding.


#### If this is a syncds run, check to see if we can bail.
my $syncds_update = 0;
if ( $script_mode == $REVALIDATE ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it can use some cleanup. Can you do the check to see if $traffic_ops_host is defined first and then check the script mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

@@ -213,7 +250,7 @@
&touch_file('remap.config');
last;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use wood for the bike shed.

@@ -226,6 +263,7 @@
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this new line necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use metal for the roof of the bikeshed.

@@ -262,6 +316,7 @@ sub usage {
print "\t<Mode> = report - prints config differences and exits.\n";
print "\t<Mode> = badass - attempts to fix all config differences that it can.\n";
print "\t<Mode> = syncds - syncs delivery services with what is configured in Traffic Ops.\n";
print "\t<Mode> = revalidate - checks for updated revalidations in Traffic Ops and applies them. Requires Traffic Ops 1.2.\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requires traffic ops 2.1 not 1.2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point.

( $log_level >> $DEBUG ) && print "DEBUG Setting update flag in Traffic Ops to $status.\n";

my %headers = ( 'Cookie' => $cookie );
my $response = $lwp_conn->post( $url, [ 'updated' => $status ], %headers );
my $url = $traffic_ops_host . $uri;
my $response = $lwp_conn->post( $url, [ 'updated' => $status, 'reval_updated' => $reval_status ], %headers );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok if reval_status is null here? Didnt trace the code, I just assume that can happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Traffic ops only looks for it if use_reval_pending is enabled, and reval_status won't be used if that's the case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

( $dispersion > 0 ) && &sleep_timer($dispersion);
}

( $log_level >> $WARN ) && print "\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to just print a carriage return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a really big fan of carriage returns for some reason.

@@ -759,9 +967,9 @@ sub check_syncds_state {
( $log_level >> $ERROR ) && print "ERROR Traffic Ops is signaling that no update is waiting to be applied.\n";
}

my $stj = &lwp_get("$traffic_ops_host\/datastatus");
my $stj = &lwp_get("/datastatus");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, we should use the API endpoint here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

for ( my $i = $duration; $i > 0; $i-- ) {
( $log_level >> $WARN ) && print ".";
sleep 1;
$reval_clock--;
if ($reval_clock < 1 && $script_mode != $BADASS && $reval_in_use == 1 ) {
( $log_level >> $WARN ) && print "\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, do we mean to just print a new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

@@ -1481,8 +1783,8 @@ sub get_header_comment {
my $to_host = shift;
my $toolname;

my $url = "$to_host/api/1.1/system/info.json";
my $result = &lwp_get($url);
my $uri = "/api/1.1/system/info.json";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the 1.2 version if the API instead? Not sure if it changed at all.


return if (!defined($cfg_file_tracker->{$filename}->{'fname-in-TO'}));

return "$traffic_ops_host\/genfiles\/view\/$hostname_short\/" . $cfg_file_tracker->{$filename}->{'fname-in-TO'};
#return "$traffic_ops_host\/genfiles\/view\/$hostname_short\/" . $cfg_file_tracker->{$filename}->{'fname-in-TO'};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this commented out line or can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of it!

}
else {
( $syncds_update ) = &check_syncds_state();
if ( $syncds_update < 1 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't doing anything in this if{}

@dneuman64
Copy link
Contributor

👍 I checked ORT, looks good to me now.

@asfgit asfgit closed this in d8d6650 Mar 16, 2017
-- SQL in section 'Up' is executed when this migration is applied
ALTER TABLE server ADD COLUMN reval_pending boolean NOT NULL DEFAULT false;
INSERT INTO parameter (name, config_file, value, secure) VALUES ('use_reval_pending', 'global', '0', False);
insert into profile_parameter (profile, parameter) values ((select id from profile where name = 'GLOBAL'), (select id from parameter where name = 'use_reval_pending'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dg4prez - so this isn't going to work. when you run db/admin.pl --env=test updgrade to migrate the to_test database, this fails because there is no GLOBAL profile in the to_test db. I'm not exactly sure what the right answer is off the top of my head to fix this but this needs to be fixed because you can't run tests in the master branch currently. Maybe @dewrich or @dangogh have some ideas...

@dneuman64
Copy link
Contributor

dneuman64 commented Mar 24, 2017

Brought this up with @dg4prez the other day. IMO we should add a GLOBAL profile to the test DB via fixtures. I added it manually and it worked.

@dg4prez dg4prez deleted the regex_reval branch April 20, 2017 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants