Author: dpfister
Date: Thu Mar 8 23:58:21 2007
New Revision: 516324
URL: http://svn.apache.org/viewvc?view=rev&rev=516324
Log:
JCR-780 - Simultaneous updates by multiple sessions might not appear in the journal
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?view=diff&rev=516324&r1=516323&r2=516324
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Thu Mar 8 23:58:21 2007
@@ -436,14 +436,14 @@
class WorkspaceUpdateChannel implements UpdateEventChannel {
/**
- * Workspace name.
+ * Attribute name used to store record.
*/
- private final String workspace;
+ private static final String ATTRIBUTE_RECORD = "record";
/**
- * Record being appended.
+ * Workspace name.
*/
- private Record record;
+ private final String workspace;
/**
* Create a new instance of this class.
@@ -457,20 +457,14 @@
/**
* {@inheritDoc}
*/
- public void updateCreated() {
+ public void updateCreated(Update update) {
if (status != STARTED) {
log.info("not started: update create ignored.");
return;
}
- if (record != null) {
- String msg = "Record already created.";
- log.warn(msg);
- return;
- }
try {
- sync();
- record = journal.getProducer(PRODUCER_ID).append();
- //sync();
+ Record record = journal.getProducer(PRODUCER_ID).append();
+ update.setAttribute(ATTRIBUTE_RECORD, record);
} catch (JournalException e) {
String msg = "Unable to create log entry.";
log.error(msg, e);
@@ -483,22 +477,25 @@
/**
* {@inheritDoc}
*/
- public void updatePrepared(ChangeLog changes, EventStateCollection esc) {
+ public void updatePrepared(Update update) {
if (status != STARTED) {
log.info("not started: update prepare ignored.");
return;
}
+ Record record = (Record) update.getAttribute(ATTRIBUTE_RECORD);
if (record == null) {
String msg = "No record created.";
log.warn(msg);
return;
}
+ EventStateCollection events = update.getEvents();
+ ChangeLog changes = update.getChanges();
boolean succeeded = false;
try {
record.writeString(workspace);
- write(record, changes, esc);
+ write(record, changes, events);
record.writeChar('\0');
succeeded = true;
} catch (JournalException e) {
@@ -510,7 +507,7 @@
} finally {
if (!succeeded && record != null) {
record.cancelUpdate();
- record = null;
+ update.setAttribute(ATTRIBUTE_RECORD, null);
}
}
}
@@ -518,11 +515,12 @@
/**
* {@inheritDoc}
*/
- public void updateCommitted() {
+ public void updateCommitted(Update update) {
if (status != STARTED) {
log.info("not started: update commit ignored.");
return;
}
+ Record record = (Record) update.getAttribute(ATTRIBUTE_RECORD);
if (record == null) {
String msg = "No record prepared.";
log.warn(msg);
@@ -539,21 +537,22 @@
String msg = "Unexpected error while committing log entry.";
log.error(msg, e);
} finally {
- record = null;
+ update.setAttribute(ATTRIBUTE_RECORD, null);
}
}
/**
* {@inheritDoc}
*/
- public void updateCancelled() {
+ public void updateCancelled(Update update) {
if (status != STARTED) {
log.info("not started: update cancel ignored.");
return;
}
+ Record record = (Record) update.getAttribute(ATTRIBUTE_RECORD);
if (record != null) {
record.cancelUpdate();
- record = null;
+ update.setAttribute(ATTRIBUTE_RECORD, null);
}
}
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java?view=auto&rev=516324
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
Thu Mar 8 23:58:21 2007
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.cluster;
+
+import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.observation.EventStateCollection;
+
+/**
+ * Update operation passed in <code>UpdateEventChannel</code>.
+ */
+public interface Update {
+
+ /**
+ * Set an attribute of this update operation. Can be used
+ * to remember some setting for a later notification.
+ *
+ * @param name attribute name
+ * @param value attribute value
+ */
+ public void setAttribute(String name, Object value);
+
+ /**
+ * Return an attribute of this update operation.
+ *
+ * @param name attribute name
+ * @return attribute value or <code>null</code>
+ */
+ public Object getAttribute(String name);
+
+ /**
+ * Return the local changes of this update operation.
+ *
+ * @return local changes
+ */
+ public ChangeLog getChanges();
+
+ /**
+ * Return the collection of events this update operation will
+ * generate.
+ */
+ public EventStateCollection getEvents();
+}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?view=diff&rev=516324&r1=516323&r2=516324
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
Thu Mar 8 23:58:21 2007
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.core.cluster;
import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.SharedItemStateManager;
import org.apache.jackrabbit.core.observation.EventStateCollection;
/**
@@ -26,26 +27,31 @@
/**
* Called when an a update operation has been created.
+ *
+ * @param update update operation
*/
- public void updateCreated();
+ public void updateCreated(Update update);
/**
* Called when an a update operation has been prepared.
*
- * @param changes changes
- * @param esc events as they will be delivered on success
+ * @param update update operation
*/
- public void updatePrepared(ChangeLog changes, EventStateCollection esc);
+ public void updatePrepared(Update update);
/**
* Called when an a update operation has been committed.
+ *
+ * @param update update operation
*/
- public void updateCommitted();
+ public void updateCommitted(Update update);
/**
* Called when an a update operation has been cancelled.
+ *
+ * @param update update operation
*/
- public void updateCancelled();
+ public void updateCancelled(Update update);
/**
* Set listener that will receive information about incoming, external update events.
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&rev=516324&r1=516323&r2=516324
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Thu Mar 8 23:58:21 2007
@@ -50,6 +50,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.HashMap;
/**
* Shared <code>ItemStateManager</code> (SISM). Caches objects returned from
a
@@ -458,7 +459,7 @@
/**
* Object representing a single update operation.
*/
- class Update {
+ class Update implements org.apache.jackrabbit.core.cluster.Update {
/**
* Local change log.
@@ -497,6 +498,11 @@
private boolean holdingWriteLock;
/**
+ * Map of attributes stored for this update operation.
+ */
+ private HashMap attributes;
+
+ /**
* Create a new instance of this class.
*/
public Update(ChangeLog local, EventStateCollectionFactory factory,
@@ -520,7 +526,7 @@
/* let listener know about change */
if (eventChannel != null) {
- eventChannel.updateCreated();
+ eventChannel.updateCreated(this);
}
try {
@@ -528,7 +534,7 @@
holdingWriteLock = true;
} finally {
if (!holdingWriteLock && eventChannel != null) {
- eventChannel.updateCancelled();
+ eventChannel.updateCancelled(this);
}
}
@@ -650,7 +656,7 @@
/* let listener know about change */
if (eventChannel != null) {
- eventChannel.updatePrepared(local, events);
+ eventChannel.updatePrepared(this);
}
/* Push all changes from the local items to the shared items */
@@ -715,7 +721,7 @@
/* let listener know about finished operation */
if (eventChannel != null) {
- eventChannel.updateCommitted();
+ eventChannel.updateCommitted(this);
}
} finally {
@@ -737,7 +743,7 @@
try {
/* let listener know about cancelled operation */
if (eventChannel != null) {
- eventChannel.updateCancelled();
+ eventChannel.updateCancelled(this);
}
local.disconnect();
@@ -768,6 +774,40 @@
holdingWriteLock = false;
}
}
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setAttribute(String name, Object value) {
+ if (attributes == null) {
+ attributes = new HashMap();
+ }
+ attributes.put(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getAttribute(String name) {
+ if (attributes != null) {
+ return attributes.get(name);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ChangeLog getChanges() {
+ return local;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EventStateCollection getEvents() {
+ return events;
}
}
|