Permalink
Browse files

Bemore accurate about generating serial numbers from timestamps

  • Loading branch information...
1 parent 4b9b634 commit 70b877cfc112f0b2d3f2f60581e8b18cf6550dcd @abh committed Sep 7, 2012
Showing with 15 additions and 8 deletions.
  1. +1 −0 Changes
  2. +14 −8 lib/GeoDNS.pm
View
@@ -1,3 +1,4 @@
+ - Be more accurate about generating serial numbers from timestamps
- Don't include the server_id in the json version data
- Fix version tests (Steve Wills)
- Enable travis-ci testing
View
@@ -375,7 +375,8 @@ sub _load_config {
my $config = {};
$config->{last_config_check} = time;
- $config->{files} = [];
+ $config->{files} = {};
+ $config->{first_config_file} = $filename;
$config->{config_file_stack} = [];
_read_config( $config, $filename );
@@ -396,7 +397,7 @@ sub _load_config {
# warn Data::Dumper->Dump([\$config], [qw(config)]);
# the default serial is timestamp of the newest config file.
- $config->{serial} = max map {$_->[1]} @{ $config->{files} }
+ $config->{serial} = max values %{ $config->{files} }
unless $config->{serial} and $config->{serial} =~ m/^\d+$/;
$config->{ttl} = 180 unless $config->{ttl} and $config->{ttl} !~ m/\D/;
@@ -412,6 +413,10 @@ sub _load_config {
($config_base->{primary_ns}) = sort keys %{$config_base->{data}->{""}->{ns}} if $config_base->{data}->{""}->{ns};
}
+ unless ($config_base->{serial}) {
+ $config_base->{serial} = max map { $config->{files}->{$_} } @{$config_base->{files}};
+ }
+
for my $f (qw(primary_ns ttl serial)) {
$config_base->{$f} = $config->{$f} or die "default $f needed but not set"
unless $config_base->{$f};
@@ -448,7 +453,7 @@ sub _read_config {
push @{ $config->{config_file_stack} }, $file;
- push @{ $config->{files} }, [$file, (stat($file))[9]];
+ $config->{files}->{$file} = (stat($file))[9];
my $base_ns = 0;
@@ -466,7 +471,7 @@ sub _read_config {
$config->{base} = $base_name;
if ($json_file) {
open my $json_fh, '<', $json_file or die "Could not open $json_file: $!\n";
- push @{ $config->{files} }, [$json_file, (stat($json_file))[9]];
+ $config->{files}->{$json_file} = (stat($json_file))[9];
my $data = eval { local $/ = undef; <$json_fh> };
close $json_fh;
$config->{bases}->{$base_name} = $json->decode($data);
@@ -500,6 +505,7 @@ sub _read_config {
my $base = $config->{base};
my $config_base = $config->{bases}->{$base};
+ $config_base->{files} = [ @{ $config->{config_file_stack} } ];
if (s/^ns\s+//) {
if (!$base_ns) {
@@ -542,15 +548,15 @@ sub _read_config {
sub check_config {
my $self = shift;
return unless time >= ($self->config->{last_config_check} + 30);
- my ($first_file) = (@{$self->config->{files}})[0];
- $first_file = $first_file && $first_file->[0];
+ my $first_file = $self->config->{first_config_file};
cluck 'No "first_file' unless $first_file;
#return unless $first_file;
my $reload = 0;
- for my $file (@{$self->config->{files}}) {
- if ((stat($file->[0]))[9] != $file->[1]) {
+ for my $file (keys %{$self->config->{files}}) {
+ my $mtime = $self->config->{files}->{$file};
+ if ((stat($file))[9] != $mtime) {
$reload = 1;
last;
}

0 comments on commit 70b877c

Please sign in to comment.