1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Make the streaming replication protocol messages architecture-independent.

We used to send structs wrapped in CopyData messages, which works as long as
the client and server agree on things like endianess, timestamp format and
alignment. That's good enough for running a standby server, which has to run
on the same platform anyway, but it's useful for tools like pg_receivexlog
to work across platforms.

This breaks protocol compatibility of streaming replication, but we never
promised that to be compatible across versions, anyway.
This commit is contained in:
Heikki Linnakangas
2012-11-07 18:59:12 +02:00
parent ed5699dd1b
commit add6c3179a
7 changed files with 384 additions and 367 deletions

View File

@ -1285,6 +1285,50 @@ GetCurrentTimestamp(void)
return result;
}
/*
* GetCurrentIntegerTimestamp -- get the current operating system time as int64
*
* Result is the number of milliseconds since the Postgres epoch. If compiled
* with --enable-integer-datetimes, this is identical to GetCurrentTimestamp(),
* and is implemented as a macro.
*/
#ifndef HAVE_INT64_TIMESTAMP
int64
GetCurrentIntegerTimestamp(void)
{
int64 result;
struct timeval tp;
gettimeofday(&tp, NULL);
result = (int64) tp.tv_sec -
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
result = (result * USECS_PER_SEC) + tp.tv_usec;
return result;
}
#endif
/*
* IntegetTimestampToTimestampTz -- convert an int64 timestamp to native format
*
* When compiled with --enable-integer-datetimes, this is implemented as a
* no-op macro.
*/
#ifndef HAVE_INT64_TIMESTAMP
TimestampTz
IntegerTimestampToTimestampTz(int64 timestamp)
{
TimestampTz result;
result = timestamp / USECS_PER_SEC;
result += (timestamp % USECS_PER_SEC) / 1000000.0;
return result;
}
#endif
/*
* TimestampDifference -- convert the difference between two timestamps
* into integer seconds and microseconds