Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/41#discussion_r14507361
--- 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 --
is there a danger that we might have many threads backing up here? i think
not, that persistence is invoked by a single thread, but if we start doing a
lot of out-of-band `persistNow` we might.
worth a comment that an
"if-unstarted-persistence-task-is-pending-then-just-wait-on-him-rather-than-submit-another"
might be wanted in future?
---
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.
---