Skip to content

Commit ea1feb2

Browse files
authored
Merge pull request #1975 from geofabrik/repl-output-more-human
Improve the human readility of the `osm2pgsql-replication`
2 parents 2038358 + e998bb7 commit ea1feb2

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

scripts/osm2pgsql-replication

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ def init(conn, args):
323323
setup_replication_state(conn, args.table, base_url, seq, date)
324324

325325
LOG.info("Initialised updates for service '%s'.", base_url)
326-
LOG.info("Starting at sequence %d (%s).", seq, date)
326+
LOG.info("Starting at sequence %d (%s).", seq,
327+
date.astimezone(dt.timezone.utc).strftime('%Y-%m-%dT%H:%MZ'))
327328

328329
return 0
329330

@@ -365,8 +366,9 @@ def update(conn, args):
365366
return 1
366367

367368
base_url, seq, ts = cur.fetchone()
368-
LOG.info("Using replication service '%s'. Current sequence %d (%s).",
369-
base_url, seq, ts)
369+
initial_local_timestamp = ts
370+
LOG.info("Using replication service '%s'.", base_url)
371+
local_db_age_sec = int((dt.datetime.now(dt.timezone.utc) - ts).total_seconds())
370372

371373
repl = ReplicationServer(base_url)
372374
current = repl.get_state_info()
@@ -380,6 +382,16 @@ def update(conn, args):
380382
LOG.info("Database already up-to-date.")
381383
return 0
382384

385+
remote_server_age_sec = int((dt.datetime.now(dt.timezone.utc) - current.timestamp).total_seconds())
386+
LOG.debug("Applying %d sequence(s) (%d → %d), covering %s (%s sec) of changes (%s → %s)",
387+
current.sequence - seq, current.sequence, seq,
388+
pretty_format_timedelta(int((current.timestamp - ts).total_seconds())),
389+
int((current.timestamp - ts).total_seconds()),
390+
ts.astimezone(dt.timezone.utc).strftime('%Y-%m-%dT%H:%MZ'), current.timestamp.astimezone(dt.timezone.utc).strftime('%Y-%m-%dT%H:%MZ')
391+
)
392+
393+
update_started = dt.datetime.now(dt.timezone.utc)
394+
383395
if args.diff_file is not None:
384396
outfile = Path(args.diff_file)
385397
else:
@@ -430,12 +442,31 @@ def update(conn, args):
430442

431443
if nextstate is not None:
432444
LOG.info("Data imported until %s. Backlog remaining: %s",
433-
nextstate.timestamp,
434-
dt.datetime.now(dt.timezone.utc) - nextstate.timestamp)
445+
nextstate.timestamp.astimezone(dt.timezone.utc).strftime('%Y-%m-%dT%H:%MZ'),
446+
pretty_format_timedelta((dt.datetime.now(dt.timezone.utc) - nextstate.timestamp).total_seconds()),
447+
)
448+
435449

436450
if args.once:
437451
break
438452

453+
454+
update_duration_sec = (dt.datetime.now(dt.timezone.utc) - update_started).total_seconds()
455+
with conn.cursor() as cur:
456+
cur.execute(sql.SQL('SELECT * FROM {}').format(args.table))
457+
if cur.rowcount != 1:
458+
LOG.fatal("Updates not set up correctly. Run 'osm2pgsql-updates init' first.")
459+
return 1
460+
461+
_base_url, _seq, current_local_timestamp = cur.fetchone()
462+
463+
total_applied_changes_duration_sec = (current_local_timestamp - initial_local_timestamp).total_seconds()
464+
LOG.debug("It took %s (%d sec) to apply %s (%d sec) of changes. This is a speed of ×%.1f.",
465+
pretty_format_timedelta(update_duration_sec), int(update_duration_sec),
466+
pretty_format_timedelta(total_applied_changes_duration_sec), int(total_applied_changes_duration_sec),
467+
total_applied_changes_duration_sec / update_duration_sec
468+
)
469+
439470
return 0
440471

441472
def get_parser():

0 commit comments

Comments
 (0)