Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/41#discussion_r14532369
--- Diff:
core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
---
@@ -266,67 +416,83 @@ public void checkpoint(BrooklynMemento newMemento) {
if (LOG.isDebugEnabled()) LOG.debug("Ignoring checkpointing
entire memento, because not running");
return;
}
- objectStore.prepareForMasterUse();
- Stopwatch stopwatch = Stopwatch.createStarted();
-
- for (EntityMemento entity :
newMemento.getEntityMementos().values()) {
- persist("entities", entity);
- }
- for (LocationMemento location :
newMemento.getLocationMementos().values()) {
- persist("locations", location);
- }
- for (PolicyMemento policy :
newMemento.getPolicyMementos().values()) {
- persist("policies", policy);
- }
- for (EnricherMemento enricher :
newMemento.getEnricherMementos().values()) {
- persist("enrichers", enricher);
- }
+ Stopwatch stopwatch = deltaImpl(PersisterDeltaImpl.builder()
+ .entities(newMemento.getEntityMementos().values())
+ .locations(newMemento.getLocationMementos().values())
+ .policies(newMemento.getPolicyMementos().values())
+ .enrichers(newMemento.getEnricherMementos().values())
+ .build());
if (LOG.isDebugEnabled()) LOG.debug("Checkpointed entire memento
in {}", Time.makeTimeStringRounded(stopwatch));
}
-
+
@Override
public void delta(Delta delta) {
if (!running) {
if (LOG.isDebugEnabled()) LOG.debug("Ignoring checkpointed
delta of memento, because not running");
return;
}
- objectStore.prepareForMasterUse();
-
- Stopwatch stopwatch = Stopwatch.createStarted();
-
- for (EntityMemento entity : delta.entities()) {
- persist("entities", entity);
- }
- for (LocationMemento location : delta.locations()) {
- persist("locations", location);
- }
- for (PolicyMemento policy : delta.policies()) {
- persist("policies", policy);
- }
- for (EnricherMemento enricher : delta.enrichers()) {
- persist("enrichers", enricher);
- }
-
- for (String id : delta.removedEntityIds()) {
- delete("entities", id);
- }
- for (String id : delta.removedLocationIds()) {
- delete("locations", id);
- }
- for (String id : delta.removedPolicyIds()) {
- delete("policies", id);
- }
- for (String id : delta.removedEnricherIds()) {
- delete("enrichers", id);
- }
+ Stopwatch stopwatch = deltaImpl(delta);
if (LOG.isDebugEnabled()) LOG.debug("Checkpointed delta of memento
in {}; updated {} entities, {} locations and {} policies; " +
"removing {} entities, {} locations and {} policies",
new Object[] {Time.makeTimeStringRounded(stopwatch),
delta.entities(), delta.locations(), delta.policies(),
delta.removedEntityIds(), delta.removedLocationIds(),
delta.removedPolicyIds()});
}
+
+ private Stopwatch deltaImpl(Delta delta) {
--- End diff --
Agree worth a comment.
Correct that currently just called by a single-threaded scheduled executor.
For the unstarted persistence task, that's a bit trickier. We'd need to
merge the deltas together so that we do persist all of the entities needing
persisted. That behaviour of only persisting most recent is what used to happen
in the overly complicated async writer class.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---