Skip to content

Commit

Permalink
Revert "refactor views to implement indexes"
Browse files Browse the repository at this point in the history
This reverts commit 668af96.
  • Loading branch information
luigidellaquila committed Aug 27, 2018
1 parent 77e2528 commit fd03013
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 63 deletions.
Expand Up @@ -5,7 +5,6 @@
import com.orientechnologies.orient.core.db.OrientDBInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.metadata.schema.OImmutableClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OView;
Expand Down Expand Up @@ -170,12 +169,9 @@ public synchronized void updateView(OView view, ODatabaseDocument db) {
String originRidField = view.getOriginRidField();
String clusterName = db.getClusterNameById(cluster);

List<OIndex> indexes = createNewIndexesForView(view, cluster, db);

OScenarioThreadLocal.executeAsDistributed(new Callable<Object>() {
@Override
public Object call() {

OResultSet rs = db.query(query);
while (rs.hasNext()) {
OResult item = rs.next();
Expand All @@ -186,7 +182,6 @@ public Object call() {
}
db.save(newRow, clusterName);
}

return null;
}
});
Expand All @@ -209,12 +204,6 @@ public Object call() {
}
unlockView(view);
cleanUnusedViewClusters(db);

}

private List<OIndex> createNewIndexesForView(OView view, int cluster, ODatabaseDocument db) {
//TODO
return null;
}

private synchronized void unlockView(OView view) {
Expand Down Expand Up @@ -298,7 +287,7 @@ public void recordDeleted(OImmutableClass clazz, ODocument doc, ODatabaseDocumen
lastChangePerClass.put(clazz.getName().toLowerCase(Locale.ENGLISH), System.currentTimeMillis());
}

public String getViewFromOldCluster(int clusterId) {
public String getViewFromOldCluster(int clusterId){
return oldClustersPerViews.get(clusterId);
}
}
Expand Up @@ -5,13 +5,12 @@

public class OImmutableView extends OImmutableClass implements OView {

private final int updateIntervalSeconds;
private final List<String> watchClasses;
private final List<String> nodes;
private final List<OViewConfig.OViewIndexConfig> requiredIndexesInfo;
private String query;
private String originRidField;
private boolean updatable;
private final int updateIntervalSeconds;
private final List<String> watchClasses;
private final List<String> nodes;
private String query;
private String originRidField;
private boolean updatable;

public OImmutableView(OView view, OImmutableSchema schema) {
super(view, schema);
Expand All @@ -21,7 +20,6 @@ public OImmutableView(OView view, OImmutableSchema schema) {
this.originRidField = view.getOriginRidField();
this.updatable = view.isUpdatable();
this.nodes = view.getNodes() == null ? null : new ArrayList<>(view.getNodes());
this.requiredIndexesInfo = view.getRequiredIndexesInfo() == null ? null : new ArrayList(view.getRequiredIndexesInfo());
}

@Override
Expand Down Expand Up @@ -51,9 +49,4 @@ public boolean isUpdatable() {
public List<String> getNodes() {
return nodes;
}

@Override
public List<OViewConfig.OViewIndexConfig> getRequiredIndexesInfo() {
return requiredIndexesInfo;
}
}
Expand Up @@ -14,6 +14,4 @@ public interface OView extends OClass {
boolean isUpdatable();

List<String> getNodes();

List<OViewConfig.OViewIndexConfig> getRequiredIndexesInfo();
}
Expand Up @@ -13,8 +13,13 @@ public class OViewConfig {
public static String UPDATE_STRATEGY_LIVE = "live";

public static class OViewIndexConfig {
protected String name;
protected List<OPair<String, OType>> props = new ArrayList<>();

OViewIndexConfig(String name) {
this.name = name;
}

public void addProperty(String name, OType type) {
this.props.add(new OPair<>(name, type));
}
Expand All @@ -39,7 +44,7 @@ public OViewConfig copy() {
OViewConfig result = new OViewConfig(this.name, this.query);
result.updatable = this.updatable;
for (OViewIndexConfig index : indexes) {
OViewIndexConfig idx = result.addIndex();
OViewIndexConfig idx = result.addIndex(index.name);
index.props.forEach(x -> idx.addProperty(x.key, x.value));
}
result.updateStrategy = this.updateStrategy;
Expand All @@ -50,8 +55,8 @@ public OViewConfig copy() {
return result;
}

public OViewIndexConfig addIndex() {
OViewIndexConfig result = new OViewIndexConfig();
public OViewIndexConfig addIndex(String name) {
OViewIndexConfig result = new OViewIndexConfig(name);
indexes.add(result);
return result;
}
Expand Down
Expand Up @@ -730,6 +730,18 @@ public OClass addClusterId(final int clusterId) {

acquireSchemaWriteLock();
try {
final OStorage storage = database.getStorage();

if (isDistributedCommand(database)) {

final String cmd = String.format("alter class `%s` addcluster %d", name, clusterId);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());

database.command(commandSQL).execute();

addClusterIdInternal(database, clusterId);
} else
addClusterIdInternal(database, clusterId);

} finally {
Expand All @@ -747,6 +759,18 @@ public OClass removeClusterId(final int clusterId) {

acquireSchemaWriteLock();
try {

final OStorage storage = database.getStorage();
if (isDistributedCommand(database)) {
final String cmd = String.format("alter class `%s` removecluster %d", name, clusterId);

final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());

database.command(commandSQL).execute();

removeClusterIdInternal(database, clusterId);
} else
removeClusterIdInternal(database, clusterId);
} finally {
releaseSchemaWriteLock();
Expand Down Expand Up @@ -1028,5 +1052,4 @@ private void tryDropCluster(final int defaultClusterId) {
getDatabase().getStorage().dropCluster(defaultClusterId, true);
}
}

}
Expand Up @@ -3,7 +3,6 @@
import com.orientechnologies.common.util.OPair;
import com.orientechnologies.orient.core.record.impl.ODocument;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -28,10 +27,10 @@ public void fromStream() {
this.cfg = new OViewConfig(getName(), query);
this.cfg.setUpdatable(Boolean.TRUE.equals(document.getProperty("updatable")));

List<Map<String, String>> idxData = document.getProperty("indexes");
for (Map<String, String> idx : idxData) {
OViewConfig.OViewIndexConfig indexConfig = this.cfg.addIndex();
for (Map.Entry<String, String> prop : idx.entrySet()) {
Map<String, Map<String, String>> idxData = document.getProperty("indexes");
for (Map.Entry<String, Map<String, String>> idx : idxData.entrySet()) {
OViewConfig.OViewIndexConfig indexConfig = this.cfg.addIndex(idx.getKey());
for (Map.Entry<String, String> prop : idx.getValue().entrySet()) {
indexConfig.addProperty(prop.getKey(), OType.valueOf(prop.getValue()));
}
}
Expand Down Expand Up @@ -59,13 +58,13 @@ public ODocument toStream() {
result.setProperty("query", cfg.getQuery());
result.setProperty("updatable", cfg.isUpdatable());

List<Map<String, String>> indexes = new ArrayList<>();
Map<String, Map<String, String>> indexes = new HashMap<>();
for (OViewConfig.OViewIndexConfig idx : cfg.indexes) {
Map<String, String> indexDescriptor = new HashMap<>();
for (OPair<String, OType> s : idx.props) {
indexDescriptor.put(s.key, s.value.toString());
}
indexes.add(indexDescriptor);
indexes.put(idx.name, indexDescriptor);
}
result.setProperty("indexes", indexes);
result.setProperty("updateIntervalSeconds", cfg.getUpdateIntervalSeconds());
Expand All @@ -81,13 +80,13 @@ public ODocument toNetworkStream() {
ODocument result = super.toNetworkStream();
result.setProperty("query", cfg.getQuery());
result.setProperty("updatable", cfg.isUpdatable());
List<Map<String, String>> indexes = new ArrayList<>();
Map<String, Map<String, String>> indexes = new HashMap<>();
for (OViewConfig.OViewIndexConfig idx : cfg.indexes) {
Map<String, String> indexDescriptor = new HashMap<>();
for (OPair<String, OType> s : idx.props) {
indexDescriptor.put(s.key, s.value.toString());
}
indexes.add(indexDescriptor);
indexes.put(idx.name, indexDescriptor);
}
result.setProperty("indexes", indexes);
result.setProperty("updateIntervalSeconds", cfg.getUpdateIntervalSeconds());
Expand Down Expand Up @@ -135,9 +134,4 @@ public boolean isUpdatable() {
public List<String> getNodes() {
return cfg.getNodes();
}

@Override
public List<OViewConfig.OViewIndexConfig> getRequiredIndexesInfo() {
return cfg.getIndexes();
}
}
@@ -1,14 +1,11 @@
package com.orientechnologies.orient.core.metadata.schema;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.viewmanager.ViewCreationListener;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;

public class OViewTest {

private ODatabaseDocumentTx db;
Expand All @@ -25,21 +22,8 @@ public void after() {
}

@Test
public void testSimple() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
db.getMetadata().getSchema().createView(new OViewConfig("testSimple", "SELECT FROM V"), new ViewCreationListener() {
@Override
public void afterCreate(String viewName) {
latch.countDown();
}

@Override
public void onError(String viewName, Exception exception) {

}
});
latch.await();

public void testSimple() {
db.getMetadata().getSchema().createView("testSimple", "SELECT FROM V");
Assert.assertNotNull(db.getMetadata().getSchema().getView("testSimple"));
Assert.assertNull(db.getMetadata().getSchema().getClass("testSimple"));
Assert.assertNull(db.getMetadata().getSchema().getView("V"));
Expand Down

0 comments on commit fd03013

Please sign in to comment.