Abacn commented on code in PR #39461:
URL: https://github.com/apache/beam/pull/39461#discussion_r3767248318


##########
sdks/python/apache_beam/io/fileio.py:
##########
@@ -292,32 +293,51 @@ def state_coder(self):
     return VarIntCoder()
 
 
+def _mtime_of(metadata: filesystem.FileMetadata, option: str) -> float:
+  # A missing (zero) timestamp is rejected because every file would then carry
+  # the same one, and updates could never be told apart.
+  if not metadata.last_updated_in_seconds:
+    raise BeamIOError(
+        'MatchContinuously(%s=True) requires file last-modified times, but '
+        '%s reports none.' % (option, metadata.path))
+  return metadata.last_updated_in_seconds
+
+
+def _mtime_timestamp(metadata: filesystem.FileMetadata) -> Timestamp:
+  # Floored to the millisecond a runner keeps for element timestamps, so the
+  # cursor compares against the same resolution it is persisted at.
+  micros = Timestamp.of(_mtime_of(metadata, 'timestamp_cursor')).micros
+  return Timestamp(micros=micros - micros % 1000)

Review Comment:
   The adjusted logic could have stale watermark slowly updated sources. When a 
poll has no new result, watermark stuck. We have a similar issue for 
PeriodicImpulse: #39026
   
   In FileIO.matchContinuously, are the timestamped elements on their mtime, or 
the poll time? This affects how watermark should be handled. My first comment 
assume they were timestamped on mtime, which introduces tricky scenarios. If 
it's actually on poll time, things would be simpler. Just advance watermark to 
now() everytime would suffice.
   
   



##########
sdks/python/apache_beam/io/fileio.py:
##########
@@ -292,32 +293,51 @@ def state_coder(self):
     return VarIntCoder()
 
 
+def _mtime_of(metadata: filesystem.FileMetadata, option: str) -> float:
+  # A missing (zero) timestamp is rejected because every file would then carry
+  # the same one, and updates could never be told apart.
+  if not metadata.last_updated_in_seconds:
+    raise BeamIOError(
+        'MatchContinuously(%s=True) requires file last-modified times, but '
+        '%s reports none.' % (option, metadata.path))
+  return metadata.last_updated_in_seconds
+
+
+def _mtime_timestamp(metadata: filesystem.FileMetadata) -> Timestamp:
+  # Floored to the millisecond a runner keeps for element timestamps, so the
+  # cursor compares against the same resolution it is persisted at.
+  micros = Timestamp.of(_mtime_of(metadata, 'timestamp_cursor')).micros
+  return Timestamp(micros=micros - micros % 1000)

Review Comment:
   The adjusted logic could have stale watermark slowly updated sources. When a 
poll has no new result, watermark stuck. We have a similar issue for 
PeriodicImpulse: #39026
   
   In FileIO.matchContinuously, are the timestamped elements on their mtime, or 
the poll time? This affects how watermark should be handled. My first comment 
assume they were timestamped on mtime, which introduces tricky scenarios. If 
it's actually on poll time, things would be simpler. Just advance watermark to 
now() everytime would suffice.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to