You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2014/01/20 23:09:05 UTC
svn commit: r1559841 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
Author: jukka
Date: Mon Jan 20 22:09:05 2014
New Revision: 1559841
URL: http://svn.apache.org/r1559841
Log:
OAK-1292: Avoid async indexer commits when there are no changes to index
Merge the two-level conditional in AsyncIndexUpdate.run() to a single if.
Replace the final AtomicBoolean flag with a member variable of an internal AsyncUpdateCallback object.
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java?rev=1559841&r1=1559840&r2=1559841&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java Mon Jan 20 22:09:05 2014
@@ -24,7 +24,6 @@ import static org.apache.jackrabbit.oak.
import java.util.Calendar;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
@@ -84,6 +83,26 @@ public class AsyncIndexUpdate implements
this.provider = checkNotNull(provider);
}
+ /**
+ * Index update callback that tries to raise the async status flag when
+ * the first index change is detected.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/OAK-1292">OAK-1292</a>
+ */
+ private class AsyncUpdateCallback implements IndexUpdateCallback {
+
+ private boolean dirty = false;
+
+ @Override
+ public void indexUpdate() throws CommitFailedException {
+ if (!dirty) {
+ dirty = true;
+ preAsyncRun(store, name);
+ }
+ }
+
+ }
+
@Override
public synchronized void run() {
log.debug("Running background index task {}", name);
@@ -111,46 +130,33 @@ public class AsyncIndexUpdate implements
before = MISSING_NODE;
}
- final AtomicBoolean dirty = new AtomicBoolean(false);
-
- IndexUpdateCallback callback = new IndexUpdateCallback() {
- @Override
- public void indexUpdate() throws CommitFailedException {
- if (dirty.getAndSet(true)) {
- preAsyncRun(store, name);
- }
- }
- };
-
+ AsyncUpdateCallback callback = new AsyncUpdateCallback();
IndexUpdate indexUpdate = new IndexUpdate(provider, name, after,
builder, callback);
CommitFailedException exception = EditorDiff.process(indexUpdate,
before, after);
- if (exception == null) {
+ if (exception == null && callback.dirty) {
async.setProperty(name, checkpoint);
- if (dirty.get()) {
- try {
- store.merge(builder, new CommitHook() {
- @Override
- @Nonnull
- public NodeState processCommit(NodeState before,
- NodeState after) throws CommitFailedException {
- // check for concurrent updates by this async task
- PropertyState stateAfterRebase = before
- .getChildNode(ASYNC).getProperty(name);
- if (Objects.equal(state, stateAfterRebase)) {
- return postAsyncRunStatus(after.builder())
- .getNodeState();
- } else {
- throw CONCURRENT_UPDATE;
- }
+ try {
+ store.merge(builder, new CommitHook() {
+ @Override @Nonnull
+ public NodeState processCommit(NodeState before,
+ NodeState after) throws CommitFailedException {
+ // check for concurrent updates by this async task
+ PropertyState stateAfterRebase = before
+ .getChildNode(ASYNC).getProperty(name);
+ if (Objects.equal(state, stateAfterRebase)) {
+ return postAsyncRunStatus(after.builder())
+ .getNodeState();
+ } else {
+ throw CONCURRENT_UPDATE;
}
- }, null);
- } catch (CommitFailedException e) {
- if (e != CONCURRENT_UPDATE) {
- exception = e;
}
+ }, null);
+ } catch (CommitFailedException e) {
+ if (e != CONCURRENT_UPDATE) {
+ exception = e;
}
}
}