Skip to content

[CDAP-21172]Added cdap-metadata-ext-spanner Module with ExtensionLoader#15959

Merged
123-komal merged 1 commit into
developfrom
es-spanner_feature
Jun 6, 2025
Merged

[CDAP-21172]Added cdap-metadata-ext-spanner Module with ExtensionLoader#15959
123-komal merged 1 commit into
developfrom
es-spanner_feature

Conversation

@123-komal

@123-komal 123-komal commented May 29, 2025

Copy link
Copy Markdown
Contributor

Description:

This PR introduces the SpannerMetadataStorage and it is being loaded at runtime using the MetadataStorageExtensionLoader. Key changes include:

  • SpannerMetadataStorage: A new class that extends MetadataStorage that handles the pipeline metadata and stores it in spanner tables. It delegates the operations (such as createIndex, apply, and search) to the spanner tables in the spanner instance.

  • DelegatingMetadataStorage: This class acts as a wrapper around SpannerMetadataStorage, enabling the use of SpannerMetadataStorage within the MetadataStorage framework. It ensures that the SpannerMetadataStorage is properly initialized.

Testing:

  • Local Testing:Tested these changes using a Distributed docker image.

Comment thread cdap-common/src/main/resources/cdap-default.xml
Constants.Metrics.STORAGE_METRICS_TAGS);
metricsCollector.increment(Constants.Metrics.MetadataStorage.METRICS_PREFIX + metricSuffix, 1L);
Constants.Metrics.STORAGE_METRICS_TAGS);
metricsCollector.increment(Constants.Metrics.MetadataStorage.METRICS_PREFIX + metricSuffix,1L);

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.

why are these lines changed? because of formatting? I think the earlier formatting was correct are you using Google formatter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated Now

this.cConf = cConf;
this.extensionLoader = extensionLoader;
this.extensionLoader.getAll();

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.

remove new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

}
if (Constants.Metadata.STORAGE_PROVIDER_ELASTICSEARCH.equalsIgnoreCase(config)) {
return injector.getInstance(ElasticsearchMetadataStorage.class);
return injector.getInstance(DefaultMetadataStorageProvider.class);

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.

I see this is loading the extenssion for spanner. i.e. after your change the new instances will not use elastic search is that expected? we dont have any control plane changes ready?

I think we should have a cconf flag to guard this change and when everything is okay we can turn that on from the control plane

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We did that previously also at that time it worked

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

but it worked if use just ElasticsearchMetadataStorage so I think it is issue

@Override
public MetadataChange apply(MetadataMutation mutation, MutationOptions options)
throws IOException {
return getDelegate().apply(mutation, options);

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.

do we really need to call getDelegate everytime or we can cache the result ?

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.

I think it is advisable to call getDelegate() each time as that method is rightly synchronized. Similar thing is done in DefaultStorageProvider and DelegatingMessagingService.

Comment thread pom.xml Outdated
@123-komal 123-komal force-pushed the es-spanner_feature branch from 366ff67 to fe0dfb3 Compare May 30, 2025 03:42
Comment thread cdap-metadata-ext-spanner/pom.xml Outdated
Comment thread cdap-metadata-ext-spanner/pom.xml Outdated
@123-komal 123-komal force-pushed the es-spanner_feature branch 3 times, most recently from 18e8057 to 05ce05e Compare May 30, 2025 09:46
Comment thread cdap-common/src/main/resources/cdap-default.xml
Comment thread cdap-metadata-ext-spanner/pom.xml Outdated
@123-komal 123-komal force-pushed the es-spanner_feature branch 4 times, most recently from b2a0e2b to 682799c Compare June 3, 2025 12:57

public class DefaultMetadataStorageProviderContext implements MetadataStorageContext {

private static final String storageImpl = "gcp-spanner";

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.

this should be coming from the cconf I feel

}
};
}
} No newline at end of file

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.

add new line

if (metadataStorage != null) {
return metadataStorage;
}
synchronized (this) {

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.

do we need to synchronize on this? cant we do only on MetadataStorage.class?

something similar to
if (metadataStorage == null) {
synchronized (MetadataStorage.class) {
if (metadataStorage == null) {
metadataStorage = extensionLoader.get(getName()));
// and other stuffs
}
}
}

@sidhdirenge wdyt?

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.

For now I would leave it as is - this is the pattern followed by other Providers.

We might miss some race condition maybe?

@123-komal 123-komal force-pushed the es-spanner_feature branch from 682799c to 35568f8 Compare June 3, 2025 13:53

@sidhdirenge sidhdirenge 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.

We are almost there with the changes! Before your next revision please make sure you do the following :

  1. Copyright for all the new files added. I would suggest run the mvn commands without -Drat.skip=true. You will be able to catch all the files with missing copyrights (for sanity check)
  2. Proper google formatting - Please make sure you do ctrl+alt+L. Do this consecutively twice - to update the line breaks as well.
  3. Java docs for all the new classes and all the public methods.

Comment thread cdap-metadata-ext-spanner/pom.xml Outdated
@sidhdirenge sidhdirenge added the build Triggers github actions build label Jun 3, 2025
@123-komal 123-komal force-pushed the es-spanner_feature branch from 35568f8 to 0607c2d Compare June 3, 2025 13:56
@123-komal 123-komal force-pushed the es-spanner_feature branch from 2b9e276 to 5d0177d Compare June 5, 2025 11:48
public class DelegatingMetadataStorage implements MetadataStorage {
private final CConfiguration cConf;
private final MetadataStorage delegate;
private static String prefix = "";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

initialization should be done in constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk

}
// TODO(CDAP-21174): Create metadata storage specific properties
if (getName().equals("gcp-spanner")) {
prefix = Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX + getName() + ".";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use String.format("%s%s.", Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX, getName())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk

@cdapio cdapio deleted a comment from sidhdirenge Jun 5, 2025
@123-komal 123-komal force-pushed the es-spanner_feature branch from 5d0177d to 60e25fa Compare June 5, 2025 12:43
this.prefix = String.format("%s%s.", Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX, getName());
}
else{
this.prefix="";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this.prefix=null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

if (getName().equals("gcp-spanner")) {
this.prefix = String.format("%s%s.", Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX, getName());
}
else{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add space after else

Can you please use Google Configuration Checker Style? It will automatically take care of these issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk

@123-komal 123-komal force-pushed the es-spanner_feature branch from 60e25fa to 604d785 Compare June 5, 2025 13:28

private final Map<String, String> properties;

DefaultMetadataStorageContext(CConfiguration cConf, String prefix) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add @Nullable annotation for nullable values which is prefix here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk

private final Map<String, String> properties;

DefaultMetadataStorageContext(CConfiguration cConf, String prefix) {
this.properties = Collections.unmodifiableMap(cConf.getPropsWithPrefix(prefix));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also if prefix is null initialize properties with emptyMap otherwise cConf.getPropsWithPrefix(prefix) will throw NPE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk

throw new IllegalArgumentException("Unsupported MetadataProvider type: " + getName());
}
// TODO(CDAP-21174): Create metadata storage specific properties
if (getName().equals("gcp-spanner")) {

@itsankit-google itsankit-google Jun 5, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please define a private static final variable for this constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for private static final it needs to be initialized there and as you said early it shouldn't be defined outside the constructor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I meant to add it for string gcp-spanner constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okk updated

@123-komal 123-komal force-pushed the es-spanner_feature branch from 604d785 to a59bbb0 Compare June 5, 2025 13:48
private final Map<String, String> properties;

DefaultMetadataStorageContext(CConfiguration cConf, @Nullable String prefix) {
if(prefix!=null){

@itsankit-google itsankit-google Jun 5, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

checkstyle looks off, add space after )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add space before and after !=

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +25 to +28
// TODO(CDAP-21174): Create metadata storage specific properties

/**
* Default implementation of the {@link MetadataStorageContext}.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please combine the top level single line comment in multi-line javadoc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@123-komal 123-komal force-pushed the es-spanner_feature branch 2 times, most recently from 84d66ee to 5190754 Compare June 5, 2025 15:09


/**
* // TODO(CDAP-21174): Create metadata storage specific properties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove //

@123-komal 123-komal force-pushed the es-spanner_feature branch from 5190754 to e5a08bb Compare June 5, 2025 15:51


/**
* // TODO(CDAP-21174): Create metadata storage specific properties

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 :

  • no need of // before TODO.
  • In any java docs, the description should come first. Then you can have the TODO (followed by arguments/return vars in case of Java docs for methods). You can refer to other places in the codebase.

private final CConfiguration cConf;
private final MetadataStorage delegate;
private static String prefix;
private static final String metadatastorageImpl = "gcp-spanner";

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.

Please use something like : METDATA_STORAGE_IMPL

also -
I think metadataStorageImpl is very vague term here. It's value is very spanner specific.
Would be better to rename it.

@123-komal 123-komal force-pushed the es-spanner_feature branch from e5a08bb to 35dd43f Compare June 5, 2025 16:04
@123-komal 123-komal force-pushed the es-spanner_feature branch from 35dd43f to 813e666 Compare June 6, 2025 03:46
Format Changes

changes

Changes

name-changes

formatting-changes

elastic-changes

changes

Added copyright section

Updated

Updated

Added Javadocs

Corrected Copyright

Corrected Copyright

Lexicographical order correction

Formatting correction

Formatting correction

changes

Updated PR

Updated names

Updated comments

Updated commit

Formatting changes

Formatting changes

Formatting changes

Formatting Changes

Prefix Change

Formatting Changes

Formatting Changes

Format changes

edited default context

edited default context

added constant

Formatting Changes

Formatting Changes

Corrected Formatting

Corrected Formatting
@123-komal 123-komal force-pushed the es-spanner_feature branch from 813e666 to 14ce5fc Compare June 6, 2025 03:57
@123-komal 123-komal merged commit c7dc08b into develop Jun 6, 2025
10 checks passed
@123-komal 123-komal deleted the es-spanner_feature branch June 6, 2025 07:50
@sonarqubecloud

sonarqubecloud Bot commented Jun 6, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Triggers github actions build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants