Skip to content

GEODE-6184 Added internal implementation of ClusterManagementService Java API to create a region#3059

Merged
jinmeiliao merged 16 commits intoapache:developfrom
Petahhh:GEODE-6185-internal-java-api
Jan 15, 2019
Merged

GEODE-6184 Added internal implementation of ClusterManagementService Java API to create a region#3059
jinmeiliao merged 16 commits intoapache:developfrom
Petahhh:GEODE-6185-internal-java-api

Conversation

@aditya87
Copy link
Contributor

@aditya87 aditya87 commented Jan 9, 2019

This internal API will be eventually used by the proposed cluster management REST API (https://cwiki.apache.org/confluence/display/GEODE/Cluster+Management+Service) in order to create a region.

Signed-off-by: Jinmei Liao jiliao@pivotal.io

Thank you for submitting a contribution to Apache Geode.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?

  • Has your PR been rebased against the latest commit within the target branch (typically develop)?

  • Is your initial contribution a single, squashed commit?

  • Does gradlew build run cleanly?

  • Have you written or updated unit tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.

Copy link
Contributor

@kohlmu-pivotal kohlmu-pivotal left a comment

Choose a reason for hiding this comment

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

Imo, there are a few general areas that need improvement:

  • All API's and service methods require JavaDoc and proper documentation
  • All public facing interfaces and API's need extensive JavaDoc
  • single variable or abbreviated variables are not allowed. Please refrain from using 'c' and 'fr' as variable names, have little meaning
  • Rather than have "gaps" in implementation with '//TODO: to be implemented', could you possibly have an exception thrown that would indicate missing implementation. That way if this method used, it would at least fail with a meaningful error
  • Tests should be more granular. There are some tests that test more than 1 scenario. The smell with this approach is that it could fail on the first scenario. One spends time to fix that scenario, just to re-run the test and have the next scenario fail. With finer grained tests, it is more visible the amount of scenarios that fail and estimate the extent of regression.
  • Not sure I understand what deleteFrom on the *CacheElements is supposed to do. Is it deleting the *CacheElement from the passed in CacheConfig or are you deleting the CacheConfig from the *CacheElement?

@aditya87 aditya87 force-pushed the GEODE-6185-internal-java-api branch 2 times, most recently from e777fe8 to fc2eea7 Compare January 9, 2019 21:29
@aditya87 aditya87 changed the title GEODE-6185 Added internal implementation of ClusterManagementService Java API to create a region GEODE-6184 Added internal implementation of ClusterManagementService Java API to create a region Jan 10, 2019
@aditya87 aditya87 force-pushed the GEODE-6185-internal-java-api branch 2 times, most recently from b2deb84 to 1801a54 Compare January 10, 2019 00:15
@aditya87 aditya87 force-pushed the GEODE-6185-internal-java-api branch 4 times, most recently from 09f9e11 to a1c3635 Compare January 10, 2019 21:44
configurationMutatorMap.put(RegionConfig.class, new RegionConfigMutator());
}

public ConfigurationMutator generate(CacheElement config) {
Copy link
Member

Choose a reason for hiding this comment

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

since the mapping is class to the mutator, should the signature be:
public ConfigurationMutator get(Class configClass) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you could pass in the class, but I'd rather keep the interface simpler.

public APIResult createCacheElement(CacheElement config) {
APIResult result = new APIResult();
String group = "cluster";
ConfigurationMutator configurationMutator =
Copy link
Member

@jinmeiliao jinmeiliao Jan 11, 2019

Choose a reason for hiding this comment

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

it probably would be better to have this service hold a reference to this factory instance or the map reference directly as a member variable, then it will only need initialize all the mutator once in every VM. Something like:

public class LocatorClusterManagementService extends ....{
....
private Map<Class, Mutators> mutators = new HashMap(); // this map can be a instance variable since the we only have one service instance per cache.
public LocatorClusterManagementService(...){
  // initialize the map
}
}

public Class UpdateCacheFunction extends ... {
...
private static Map<Class, Realizers> realizers = new HashMap(); // this needs to be a static variable, since the we would generate one function instance per function call.
// some static initializers to initialize the map...
}

We should also have some test visible methods to add to these maps in unit tests.

Copy link
Contributor Author

@aditya87 aditya87 Jan 11, 2019

Choose a reason for hiding this comment

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

Sure, I think once we start adding more mutators/realizers we can refactor it this way. Don't think it's necessary now.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. this is dragging out long as it is now.

*/
@Experimental
public interface ConfigurationMutator<T extends CacheElement> {
void add(T config, CacheConfig existing);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would any mutation operation not return the "new" CacheConfig? I think it would be good practice NOT to modify-in-place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be a good practice not to modify in-place, but don't think it's a bad practice to modify in-place either. If you think about how this could be used, it might even be cleaner to modify in place, so you don't have to declare more variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we are not concerned about concurrency? COULD there be any potential that multiple threads could change the same CacheConfig and instance and modify-in-place? How would the system react if two threads were to amend the same CacheConfig object and ask it to persist it... If concurrency is not a concern, this question is mute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mutators are used technically outside the scope of the methods that actually operate on the common persisted config on the locator. We "atomically" get a CacheConfig object representation of the persisted config (essentially a copy), mutate it, and then it gets written back -- if you look at the way this is used in LocatorClusterManagementService it would make this clear, since the underlying method that does this acquires a lock. So in this case it's thread safe whether you modify in-place or not.

import org.apache.geode.cache.configuration.RegionConfig;
import org.apache.geode.internal.cache.PartitionAttributesImpl;

public class RegionConfigRealizer implements ConfigurationRealizer<RegionConfig> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a PartitionRegionConfigRealizer and ReplicateRegionConfigRealizer and NormalRegionConfigRealizer and ReplicateProxyRegionConfigRealizer.... etc.. Maybe pre-optimization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pre-optimization, especially since we don't have disparate ReplicateRegionConfig and PartitionedRegionConfig classes.

ConfigurationMutatorFactory subject = new ConfigurationMutatorFactory();

RegionConfig config = new RegionConfig();
ConfigurationMutator configurationMutator = subject.generate(config);
Copy link
Contributor

Choose a reason for hiding this comment

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

With the serviceInterface of subject.generate(Class) would be simpler than having to create RegionConfig instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While it would solve the problem of using the RegionConfig instance twice, I don't think it's "simpler", since you're not creating the RegionConfig instance, you're just using the one that's passed in.

…Java API to create a region

Signed-off-by: Jinmei Liao <jiliao@pivotal.io>
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
Signed-off-by: Jinmei Liao <jiliao@pivotal.io>
jinmeiliao and others added 10 commits January 11, 2019 14:39
…create better separation of concerns

Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
… CacheElement instances

Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
…stenceService when null

Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
…asses

Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
Signed-off-by: Jens Deppe <jdeppe@pivotal.io>
…se by LocatorClusterManagementService by adding an extra method
…ier to use by LocatorClusterManagementService by adding an extra method"

This reverts commit c15026f.
Signed-off-by: Peter Tran <ptran@pivotal.io>
Copy link
Member

@jinmeiliao jinmeiliao left a comment

Choose a reason for hiding this comment

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

As long as all the tests are passing.

Signed-off-by: Peter Tran <ptran@pivotal.io>
@aditya87 aditya87 force-pushed the GEODE-6185-internal-java-api branch from f78d9a6 to 6da66b3 Compare January 14, 2019 18:58
Signed-off-by: Aditya Anchuri <aanchuri@pivotal.io>
@jinmeiliao
Copy link
Member

+1

@jdeppe-pivotal
Copy link
Contributor

+100

@jinmeiliao jinmeiliao merged commit 87e65ea into apache:develop Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants