Repository navigation
destination-async-framework: move the state emission logic into GlobalAsyncStateManager - #35240
Conversation
…lAsyncStateManager
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| @@ -64,9 +63,9 @@ public void close() throws Exception { | |||
| * | |||
| * @return list of states that can be flushed | |||
There was a problem hiding this comment.
nit: change java doc.
| public void flushStates(final Map<Long, Long> stateIdToCount) { | ||
| stateIdToCount.forEach(stateManager::decrement); | ||
| return stateManager.flushStates(); | ||
| stateManager.flushStates(); |
There was a problem hiding this comment.
Curious, does the locking break if we return the ids to flush and flush them in the FlushWorkers instead?
That way, all the actual action happens in the flush workers, and not in objects scattered around. Mainly a cleanliness suggestion.
| */ | ||
| public List<PartialStateWithDestinationStats> flushStates() { | ||
| final List<PartialStateWithDestinationStats> output = new ArrayList<>(); | ||
| public void flushStates() { |
There was a problem hiding this comment.
suggestion: what if flushStates took in an output record collector? This helps us prevent passing the record collector everywhere and helps readability.
Looks like it might minimise this PR's change set too.
| @@ -161,8 +164,7 @@ public void decrement(final long stateId, final long count) { | |||
| * | |||
| * @return list of state messages with no more inflight records. | |||
There was a problem hiding this comment.
nit: update javadoc.
There was a problem hiding this comment.
Conditional approval.
If I understand correctly, what we do here is centralise flushing into one class. Flushing itself is locked, so though many threads can call it, we prevent a race condition, which is good! Approved if my understanding is correct.
Most of my feedback is for readability. All action happens in the FlushWorkers in the previous iteration. This is intentional, since someone can read one class and understand most of what is going on. Signalling to another class is a fine pattern - my main suggestion is to keep the output record collector in one spot so it's clearer where writing mostly happens. This is just a suggestion.
What is a must-have, though non-blocking, is to update the javadocs. Keeping them in sync will really help readability!
| private final Consumer<AirbyteMessage> outputRecordCollector; | ||
|
|
||
| private final Object LOCK = new Object(); | ||
| private static final Object LOCK = new Object(); |
There was a problem hiding this comment.
static seems unnecessary ?
| public GlobalAsyncStateManager(final GlobalMemoryManager memoryManager) { | ||
| public GlobalAsyncStateManager(final GlobalMemoryManager memoryManager, final Consumer<AirbyteMessage> outputRecordCollector) { | ||
| this.memoryManager = memoryManager; | ||
| this.outputRecordCollector = outputRecordCollector; |
There was a problem hiding this comment.
Can we avoid holding a copy of outputRecordCollector at instance level and use only in flushStates ? This reduces the possibility of future abuse of this instance variable.
Davin Chia (@davinchia) yes your understanding is correct! Also addressed your review comments. |
|
/publish-java-cdk
|
…lAsyncStateManager (#35240)
There is no issue for this. See slack thread