You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Nik Clayton <ni...@ngo.org.uk> on 2006/11/01 09:19:50 UTC

API call to retrieve server timestamp / timestamps as offsets?

Hi,

I just ran in to an issue with SVN::Web.  It's not directly Subversion's 
problem, but a Subversion API enhancement would fix it.  Also, it's not 
a problem that will only affect SVN::Web.

When browsing directories, SVN::Web, like many other front ends, shows 
file timestamps as offsets from now.  E.g., "45 seconds ago", "3 minutes 
ago", "12 hours ago", and so on.

For this to work, the host hosting the repo and the host running 
SVN::Web have to have a synchronised clock.  Previously that wasn't a 
problem, but as I port SVN::Web to use SVN::Client it now works against 
remote repositories, and there's no guarantee that the clocks are synced.

If they're not, and the skew is sufficiently large, and the host running 
SVN::Web has a clock that lags behind the one hosting the repo, this can 
result in the front end thinking that files have been modified at some 
point in the future.

This is obviously nonsensical.

The real fix, of course, is to make sure that the hosts have 
synchronised clocks.

Since that's not necessarily something that can be guaranteed, there is 
something that Subversion could do to fix this for all clients.

Either, an API call that returned the server's idea of the current time. 
  All timestamp manipulation could then be done with this value, to get 
accurate offsets.

Or, an API call (or flag) that returned timestamps as negative offsets 
from the current time, instead of timestamps in their own right.

Thoughts?

N

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: API call to retrieve server timestamp / timestamps as offsets?

Posted by Nik Clayton <ni...@ngo.org.uk>.
John Peacock wrote:
> Nik Clayton wrote:
>>     my $current_time = time();        # Seconds since epoch, in UTC
> 
> This is your problem.  If I'm correct in thinking you are using HTTP as a
> transport, parse the server generated Date header and use that as your
> current_time (parsed to seconds since epoch).

I'm using SVN::Client, so I can use any of the Subversion RA mechanisms.

>> I know, and agree, that this is a configuration problem on the client.
>> I'm suggesting that client applications could work around this problem
>> with a little help from Subversion.  Perhaps with an API call, something
>> like:
>>
>>     my $current_time = SVN::Client::get_time_on_server();
> 
> Yes, but that time is wrong one second later... ;-)

That's fine.  You request the current time *after* you've requested some 
data that includes timestamps, not before.

   [...]

   my $ctx          = SVN::Client->new();
   my $dirents      = $ctx->ls($some_uri, $some_rev, 0);
   my $current_time = $ctx->get_time_on_server();

   foreach my $name (keys %$dirents) {
       printf("%s is %d seconds old\n",
         int($current_time - $dirents->{$name}->time()));
   }

   [...]

N


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: API call to retrieve server timestamp / timestamps as offsets?

Posted by John Peacock <jp...@rowman.com>.
Nik Clayton wrote:
>     my $current_time = time();        # Seconds since epoch, in UTC

This is your problem.  If I'm correct in thinking you are using HTTP as a
transport, parse the server generated Date header and use that as your
current_time (parsed to seconds since epoch).

> I know, and agree, that this is a configuration problem on the client.
> I'm suggesting that client applications could work around this problem
> with a little help from Subversion.  Perhaps with an API call, something
> like:
> 
>     my $current_time = SVN::Client::get_time_on_server();

Yes, but that time is wrong one second later... ;-)

John

-- 
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Blvd
Suite H
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: API call to retrieve server timestamp / timestamps as offsets?

Posted by Nik Clayton <ni...@ngo.org.uk>.
John Peacock wrote:
> This doesn't have anything to do with Subversion, however.  In that case, the
> Subversion client should really be using the timestamps as sent by the server
> and only changing the TZ offset if necessary.  The only time that the Subversion
> client should be concerned with local time is when comparing timestamps for
> modifications (which happens in the filesystem quite automatically).

It's a display thing.  Suppose the server's time is correct, and the 
client's time is 1 minute behind the server because of local clock drift.

Code on the client:

     my $current_time = time();        # Seconds since epoch, in UTC

     printf "Entry was modified %d seconds ago",
          $current_time - ($dirent->time() / 1_000_000); # APR time is
                                                         # nanoseconds

That's going to print the wrong value.  And if the dirent was modified 
some time in the last 60 seconds

I know, and agree, that this is a configuration problem on the client. 
I'm suggesting that client applications could work around this problem 
with a little help from Subversion.  Perhaps with an API call, something 
like:

     my $current_time = SVN::Client::get_time_on_server();

N

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: API call to retrieve server timestamp / timestamps as offsets?

Posted by John Peacock <jp...@rowman.com>.
Nik Clayton wrote:
> The real fix, of course, is to make sure that the hosts have
> synchronised clocks.
> 
> Since that's not necessarily something that can be guaranteed, there is
> something that Subversion could do to fix this for all clients.

IMHO, all machines acting as servers should by default be running some sort of
time sync program (Windows has an NTP service and *nix boxes can use either some
ntpd variant or better yet clockspeed).  There is really no excuse not to make
sure that the system clock on servers is correct; there are readily available
public sources of time sync pretty much everywhere.  Clients on networks should
be getting their sync from their local servers (Windows makes this automatic).
Smart users should set up their disconnected client boxes to synchronize with
some external host.

This doesn't have anything to do with Subversion, however.  In that case, the
Subversion client should really be using the timestamps as sent by the server
and only changing the TZ offset if necessary.  The only time that the Subversion
client should be concerned with local time is when comparing timestamps for
modifications (which happens in the filesystem quite automatically).

John

-- 
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Blvd
Suite H
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org