Manage view updates in local node only when distrinuted
package com.orientechnologies.orient.core.db.viewmanager;
import com.orientechnologies.orient.core.db.ODatabase;
+import com.orientechnologies.orient.core.db.OScenarioThreadLocal;
import com.orientechnologies.orient.core.db.OrientDBInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded;
@@ -13,6 +14,7 @@ import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import java.util.*;
+import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -149,13 +151,17 @@ public class ViewManager {
}
public synchronized void updateView(OView view, ODatabaseDocument db) {
-
lastUpdateTimestampForView.put(view.getName(), System.currentTimeMillis());
int cluster = db.addCluster(getNextClusterNameFor(view, db));
- String clusterName = db.getClusterNameById(cluster);
- OResultSet rs = db.query(view.getQuery());
+
+ String query = view.getQuery();
String originRidField = view.getOriginRidField();
+ String clusterName = db.getClusterNameById(cluster);
+ OScenarioThreadLocal.executeAsDistributed(new Callable<Object>() {
+ @Override
+ public Object call() {
+ OResultSet rs = db.query(query);
while (rs.hasNext()) {
OResult item = rs.next();
OElement newRow = copyElement(item, db);
@@ -164,6 +170,10 @@ public class ViewManager {
}
db.save(newRow, clusterName);
}
+ return null;
+ }
+ });
+
view = db.getMetadata().getSchema().getView(view.getName());
if (view == null) {
//the view was dropped in the meantime
