[ 
https://issues.apache.org/jira/browse/BEAM-8537?focusedWorklogId=371233&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-371233
 ]

ASF GitHub Bot logged work on BEAM-8537:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jan/20 23:59
            Start Date: 13/Jan/20 23:59
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on pull request #10375: [BEAM-8537] 
Provide WatermarkEstimator to track watermark
URL: https://github.com/apache/beam/pull/10375#discussion_r366089468
 
 

 ##########
 File path: sdks/python/apache_beam/runners/common.py
 ##########
 @@ -495,6 +525,162 @@ def invoke_process(self,
         windowed_value, self.process_method(windowed_value.value))
 
 
+class _ThreadsafeWatermarkEstimator(object):
+  """A threadsafe wrapper which wraps a WatermarkEstimator with locking
+  mechanism to guarantee multi-thread safety.
+  """
+  def __init__(self, watermark_estimator, lock):
+    if not isinstance(watermark_estimator, iobase.WatermarkEstimator):
+      raise ValueError('Initializing Threadsafe requires a WatermarkEstimator')
+    self._watermark_estimator = watermark_estimator
+    self._lock = lock
+
+  def __getattr__(self, attr):
+    if hasattr(self._watermark_estimator, attr):
+      def method_wrapper(*args, **kw):
+        with self._lock:
+          return getattr(self._watermark_estimator, attr)(*args, **kw)
+      return method_wrapper
+    raise AttributeError(attr)
+
+  def get_estimator_state(self):
+    # The caller should hold the lock before entering this function.
+    return self._watermark_estimator.get_estimator_state()
+
+  def current_watermark(self):
+    # The caller should hold the lock before entering this function.
+    return self._watermark_estimator.current_watermark()
+
+  def observe_timestamp(self, timestamp):
+    if not isinstance(timestamp, Timestamp):
+      raise ValueError('Input of observe_timestamp should be a Timestamp '
+                       'object')
+    with self._lock:
+      self._watermark_estimator.observe_timestamp(timestamp)
+
+
+class _ThreadsafeRestrictionTracker(object):
+  """A thread-safe wrapper which wraps a `RestritionTracker`.
+
+  This wrapper guarantees synchronization of modifying restrictions across
+  multi-thread.
 
 Review comment:
   ```suggestion
     multiple threads.
   ```
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 371233)
    Time Spent: 5h  (was: 4h 50m)

> Provide WatermarkEstimatorProvider for different types of WatermarkEstimator
> ----------------------------------------------------------------------------
>
>                 Key: BEAM-8537
>                 URL: https://issues.apache.org/jira/browse/BEAM-8537
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-core, sdk-py-harness
>            Reporter: Boyuan Zhang
>            Assignee: Boyuan Zhang
>            Priority: Major
>          Time Spent: 5h
>  Remaining Estimate: 0h
>
> This is a follow up for in-progress PR:  
> https://github.com/apache/beam/pull/9794.
> Current implementation in PR9794 provides a default implementation of 
> WatermarkEstimator. For further work, we want to let WatermarkEstimator to be 
> a pure Interface. We'll provide a WatermarkEstimatorProvider to be able to 
> create a custom WatermarkEstimator per windowed value. It should be similar 
> to how we track restriction for SDF: 
> WatermarkEstimator <---> RestrictionTracker 
> WatermarkEstimatorProvider <---> RestrictionTrackerProvider
> WatermarkEstimatorParam <---> RestrictionDoFnParam



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to