Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP-121 Ensure SerializationSchema is used in thread-safe way #127

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Added support for OIDC Bearer tokens.

### Fixed

- Ensured SerializationSchema is used in thread-safe way.

## [0.15.0] - 2024-07-30

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.getindata.connectors.http.LookupQueryCreator;
import com.getindata.connectors.http.LookupQueryCreatorFactory;
import com.getindata.connectors.http.internal.table.lookup.LookupRow;
import com.getindata.connectors.http.internal.utils.SynchronizedSerializationSchema;
import static com.getindata.connectors.http.internal.table.lookup.HttpLookupConnectorOptions.ASYNC_POLLING;
import static com.getindata.connectors.http.internal.table.lookup.HttpLookupConnectorOptions.LOOKUP_REQUEST_FORMAT;

/**
Expand Down Expand Up @@ -47,8 +49,14 @@ public LookupQueryCreator createLookupQueryCreator(
queryFormatAwareConfiguration
);

SerializationSchema<RowData> serializationSchema =
encoder.createRuntimeEncoder(null, lookupRow.getLookupPhysicalRowDataType());
final SerializationSchema<RowData> serializationSchema;
if (readableConfig.get(ASYNC_POLLING)) {
serializationSchema = new SynchronizedSerializationSchema<>(
encoder.createRuntimeEncoder(null, lookupRow.getLookupPhysicalRowDataType()));
} else {
serializationSchema =
encoder.createRuntimeEncoder(null, lookupRow.getLookupPhysicalRowDataType());
}

return new GenericJsonQueryCreator(serializationSchema);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.getindata.connectors.http.internal.utils;

import org.apache.flink.api.common.serialization.SerializationSchema;

/**
* Decorator which ensures that underlying SerializationSchema is called in thread-safe way.
*
* @param <T> type
*/
public class SynchronizedSerializationSchema<T> implements SerializationSchema<T> {

private final SerializationSchema<T> delegate;

public SynchronizedSerializationSchema(SerializationSchema<T> delegate) {
this.delegate = delegate;
}

@Override
public void open(InitializationContext context) throws Exception {
doOpen(context);
}

private synchronized void doOpen(InitializationContext context) throws Exception {
this.delegate.open(context);
}

@Override
public byte[] serialize(T element) {
return syncSerialize(element);
}

private synchronized byte[] syncSerialize(T element) {
return delegate.serialize(element);
}
}
Loading