forked from O2-Czech-Republic/proxima-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… configurable watermark estimator and idle policy for commit log readers
- Loading branch information
Showing
40 changed files
with
2,468 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
core/src/main/java/cz/o2/proxima/time/AbstractWatermarkEstimator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright 2017-2020 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.time; | ||
|
||
import com.google.common.base.Preconditions; | ||
import cz.o2.proxima.storage.StreamElement; | ||
|
||
/** The watermark estimator base class. */ | ||
public abstract class AbstractWatermarkEstimator implements WatermarkEstimator { | ||
/** Used idle policy */ | ||
private final WatermarkIdlePolicy idlePolicy; | ||
|
||
/** If estimator is in the idle state */ | ||
private boolean isIdle = false; | ||
|
||
protected AbstractWatermarkEstimator(WatermarkIdlePolicy idlePolicy) { | ||
Preconditions.checkNotNull(idlePolicy, "Idle policy must be provided"); | ||
this.idlePolicy = idlePolicy; | ||
} | ||
|
||
/** | ||
* Estimates current watermark. | ||
* | ||
* @return the estimated watermark. | ||
*/ | ||
protected abstract long estimateWatermark(); | ||
|
||
/** | ||
* Updates the watermark estimate according to given stream element. | ||
* | ||
* @param element a stream element. | ||
*/ | ||
protected abstract void updateWatermark(StreamElement element); | ||
|
||
/** Signals that streaming source is idle. */ | ||
@Override | ||
public void idle() { | ||
isIdle = true; | ||
idlePolicy.idle(getWatermark()); | ||
} | ||
|
||
/** | ||
* Updates the watermark estimate according to the given stream element. | ||
* | ||
* @param element a stream element. | ||
*/ | ||
@Override | ||
public final void update(StreamElement element) { | ||
isIdle = false; | ||
idlePolicy.update(element); | ||
updateWatermark(element); | ||
} | ||
|
||
/** | ||
* Returns monotonically increasing estimated watermark. | ||
* | ||
* @return the watermark estimate. | ||
*/ | ||
@Override | ||
public long getWatermark() { | ||
if (isIdle) { | ||
return Math.max(estimateWatermark(), idlePolicy.getIdleWatermark()); | ||
} | ||
return estimateWatermark(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/src/main/java/cz/o2/proxima/time/PartitionedWatermarkEstimator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2017-2020 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.time; | ||
|
||
import cz.o2.proxima.storage.StreamElement; | ||
|
||
/** Watermark estimator wrapper for partitioned sources. */ | ||
public interface PartitionedWatermarkEstimator extends WatermarkSupplier { | ||
|
||
/** | ||
* Returns estimated watermark across all partitions. | ||
* | ||
* @return the watermark estimate. | ||
*/ | ||
long getWatermark(); | ||
|
||
/** | ||
* Updates the partition watermark estimate according to the given stream element. | ||
* | ||
* @param element a stream element. | ||
*/ | ||
default void update(int partition, StreamElement element) {} | ||
|
||
/** Signals that a given partition is idle. */ | ||
default void idle(int partition) {} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.