Skip to content

destination-async-framework: move the state emission logic into GlobalAsyncStateManager - #35240

Merged
Subodh Chaturvedi (subodh1810) merged 9 commits into
masterfrom
fix-async-destination-framework-state-emission-13th-feb
Feb 15, 2024
Merged

Subodh Chaturvedi (subodh1810) merged 9 commits into
masterfrom
fix-async-destination-framework-state-emission-13th-feb

Conversation

@subodh1810

Copy link
Copy Markdown
Contributor

There is no issue for this. See slack thread

@vercel

vercel Bot commented Feb 13, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
airbyte-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 6:37pm

@@ -64,9 +63,9 @@ public void close() throws Exception {
*
* @return list of states that can be flushed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change java doc.

public void flushStates(final Map<Long, Long> stateIdToCount) {
stateIdToCount.forEach(stateManager::decrement);
return stateManager.flushStates();
stateManager.flushStates();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

@davinchia Davin Chia (davinchia) Feb 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update javadoc.

@davinchia Davin Chia (davinchia) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static seems unnecessary ?

public GlobalAsyncStateManager(final GlobalMemoryManager memoryManager) {
public GlobalAsyncStateManager(final GlobalMemoryManager memoryManager, final Consumer<AirbyteMessage> outputRecordCollector) {
this.memoryManager = memoryManager;
this.outputRecordCollector = outputRecordCollector;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@subodh1810

Copy link
Copy Markdown
Contributor Author

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!

Davin Chia (@davinchia) yes your understanding is correct! Also addressed your review comments.

@subodh1810

Subodh Chaturvedi (subodh1810) commented Feb 15, 2024 •

Copy link
Copy Markdown
Contributor Author

/publish-java-cdk

🕑 https://github.com/airbytehq/airbyte/actions/runs/7920403471
✅ Successfully published Java CDK version=0.20.9!

@octavia-squidington-iii Octavia Squidington III (octavia-squidington-iii) added the area/documentation Improvements or additions to documentation label Feb 15, 2024
@subodh1810
Subodh Chaturvedi (subodh1810) deleted the fix-async-destination-framework-state-emission-13th-feb branch February 15, 2024 19:06

This branch was successfully deployed

1 active deployment
Preview — 9ecf4328 Deployed Feb 15, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/connectors Connector related issues area/documentation Improvements or additions to documentation CDK Connector Development Kit connectors/destination/bigquery connectors/destination/snowflake

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants