-
Notifications
You must be signed in to change notification settings - Fork 348
Add SpannerMetadataModule with ExtensionLoader #15959
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -2845,6 +2845,11 @@ | |||
<value>/opt/cdap/master/ext/log-publisher</value> | |||
</property> | |||
|
|||
<property> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a flag to determine if we want to use spanner instead of elastic search?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for extension (not specific to spanner) - I think we might not need a flag here.
Komal is anyways testing the default flow for ES implementation. So should be safe.
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); |
There was a problem hiding this comment.
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?
this.cConf = cConf; | ||
this.extensionLoader = extensionLoader; | ||
this.extensionLoader.getAll(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove new line
@@ -179,7 +179,7 @@ public MetadataStorage get() { | |||
return injector.getInstance(DatasetMetadataStorage.class); | |||
} | |||
if (Constants.Metadata.STORAGE_PROVIDER_ELASTICSEARCH.equalsIgnoreCase(config)) { | |||
return injector.getInstance(ElasticsearchMetadataStorage.class); | |||
return injector.getInstance(DefaultMetadataStorageProvider.class); |
There was a problem hiding this comment.
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
@Override | ||
public MetadataChange apply(MetadataMutation mutation, MutationOptions options) | ||
throws IOException { | ||
return getDelegate().apply(mutation, options); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
String propertiesPrefix = | ||
Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX + storageImpl + "."; | ||
this.cConf = Collections.unmodifiableMap(cConf.getPropsWithPrefix(propertiesPrefix)); | ||
this.properties = Collections.unmodifiableMap(cConf.getPropsWithPrefix(propertiesPrefix)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both these variables are having same values - do we need 2 separate vars here?
import java.util.stream.Collectors; | ||
import org.apache.tephra.TransactionSystemClient; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take care while committing changes - the ones unrelated to your PR should not be changed (even if Google formatter updates few other lines) Otherwise you will mess up the blame / git history for the original changes.
* A simple class to pass around a Spanner Mutation, along with the metadata | ||
* change that it effects. | ||
*/ | ||
public class RequestAndChange implements ChangeRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually naming convention is like : For spanner impl you can call this class as SpannerChangeRequest
For ES -> ElasticSearchChangeRequest / ESChangeRequest.
import java.util.Map; | ||
|
||
public interface MetadataStorageContext { | ||
Map<String, String> getProperties(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if this one is needed.
pom.xml
Outdated
@@ -48,6 +48,9 @@ | |||
<organizationUrl>http://www.cdap.io</organizationUrl> | |||
</developer> | |||
</developers> | |||
<modules> | |||
<module>cdap-metadata-ext-spanner</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this to place where other modules are added.
366ff67
to
fe0dfb3
Compare
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class DefaultMetadataStorageProvider implements MetadataStorage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if we should call this as Provider.
DefaultStorageProvider implements StorageProvider (in case of storage tables).
For Metadata, we do not have an interface like MetadataStorageProvider.
Maybe we can call it as DefaultMetadataStorage / DelegatingMetadataStorage?
@bhardwaj-priyanshu - wdyt?
|
||
public String getName() { | ||
return cConf.get(Constants.Metadata.STORAGE_PROVIDER_SPANNER); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just read the MetadataStorage property from cConf.
This function will check if the property value matches the getName() in ES or getName in Spanner impl.
Or you can even follow something llike this : https://github.com/cdapio/cdap/blob/develop/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/common/DefaultStorageProvider.java#L53
and then have switch case like : https://github.com/cdapio/cdap/blob/develop/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/common/DefaultStorageProvider.java#L96
Both the cases work.
cdap-metadata-ext-spanner/pom.xml
Outdated
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-spanner</artifactId> | ||
<version>6.12.1</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the spanner version to use latest. Actually the spanner package comes from the google cloud library. You need to override the google cloud library in this extension to use the latest version like this - https://github.com/cdapio/cdap/blob/develop/cdap-storage-ext-spanner/pom.xml#L41.
</dependency> | ||
<dependency> | ||
<groupId>io.cdap.cdap</groupId> | ||
<artifactId>cdap-common</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have dependency on cdap-common ideally. There is a chance that some mvn packages will have versions incompatible to the latest spanner ones.
Please check if there is a way to remove it.
18e8057
to
05ce05e
Compare
@@ -2845,6 +2845,11 @@ | |||
<value>/opt/cdap/master/ext/log-publisher</value> | |||
</property> | |||
|
|||
<property> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for extension (not specific to spanner) - I think we might not need a flag here.
Komal is anyways testing the default flow for ES implementation. So should be safe.
@@ -179,7 +179,7 @@ public MetadataStorage get() { | |||
return injector.getInstance(DatasetMetadataStorage.class); | |||
} | |||
if (Constants.Metadata.STORAGE_PROVIDER_ELASTICSEARCH.equalsIgnoreCase(config)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the if case as discussed earlier.
Let the DefaultStorageProvider handle the if else logic for ES to use or Spanner
@@ -83,6 +84,16 @@ public void setAuditPublisher(AuditPublisher auditPublisher) { | |||
this.auditPublisher = auditPublisher; | |||
} | |||
|
|||
@Override | |||
public String getName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please verify how this is called since the default value of metadata.storage.implementation=elastic
if (metadataStorage != null) { | ||
return metadataStorage; | ||
} | ||
LOG.info(extensionLoader.get(getName()).toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra loggers that are used for debugging right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will run into NPE if getName is empty string - we should not run into NPEs.
@@ -74,6 +74,16 @@ public class DatasetMetadataStorage extends SearchHelper implements MetadataStor | |||
super(txClient, tableDefinition); | |||
} | |||
|
|||
@Override | |||
public String getName(){ | |||
return "DatasetMetadataStorage"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can instead use .getClass().getSimpleName() instead
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the entire google cloud version
This will eventually be overridden when google cloud package is imported
https://github.com/cdapio/cdap/blob/develop/cdap-storage-ext-spanner/pom.xml#L41
You can try mvn dependency tree command to find out which version is pulled.
|
||
@Override | ||
public void initialize(MetadataStorageContext context) throws Exception { | ||
Log.info("Spanner Initialized"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@Override | ||
public String getName() { | ||
return Constants.Metadata.STORAGE_PROVIDER_SPANNER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this is adding the cdap-common dependency.
Please feel free to remove this constant to avoid that dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see the META-INF for this. Please check - I guess it would be needed for Extension loader.
Format Changes changes Changes name-changes formatting-changes elastic-changes
05ce05e
to
b2a0e2b
Compare
No description provided.