Skip to content
Snippets Groups Projects
Commit cced021f authored by Dimitrii's avatar Dimitrii
Browse files

Throw away indexes, when the score is too low

parent a50b4452
No related branches found
No related tags found
No related merge requests found
...@@ -185,7 +185,7 @@ public class ErisMQuATBuilder { ...@@ -185,7 +185,7 @@ public class ErisMQuATBuilder {
} }
Component directOrIndirectComponent = new Component(); Component directOrIndirectComponent = new Component();
directOrIndirectComponent.setName(new Name("direct_or_indirect_" + createName(erisContainer, erisLivingPartition, attribute))); directOrIndirectComponent.setName(new Name("directOrIndirect_" + createName(erisContainer, erisLivingPartition, attribute)));
Implementation directOrIndirectImplementation = new Implementation(); Implementation directOrIndirectImplementation = new Implementation();
directOrIndirectImplementation.setName(new Name("directOrIndirectAccessPathSelector")); directOrIndirectImplementation.setName(new Name("directOrIndirectAccessPathSelector"));
......
...@@ -17,6 +17,7 @@ import java.net.URI; ...@@ -17,6 +17,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
...@@ -143,4 +144,18 @@ public class ERISAccessPath { ...@@ -143,4 +144,18 @@ public class ERISAccessPath {
this.indexOrderPreserving = indexOrderPreserving; this.indexOrderPreserving = indexOrderPreserving;
} }
public double getLookupTime(int att_count) {
// get the correct size
double lookuptime = 0;
int dist = Integer.MAX_VALUE;
for (ERISBenchmarkResult i : resultList) {
if (Math.abs(att_count - i.getDataSize()) < dist) {
dist = Math.abs(att_count - i.getDataSize());
lookuptime = i.getLookup();
}
}
return lookuptime;
}
} }
...@@ -217,7 +217,85 @@ public class ERISConnector { ...@@ -217,7 +217,85 @@ public class ERISConnector {
* *
*/ */
Map<String, Map<List<String>, List<String>>> partitionStorageConfigAttributes = new HashMap<>(); Map<String, Map<List<String>, List<String>>> partitionStorageConfigAttributes = new HashMap<>();
// go through direct access paths
boolean searchIndexes = false;
partitionStorageConfigAttributes = formOutputDataStructute(solution, partitionStorageConfigAttributes, searchIndexes);
// go through indexes and decide whether they are viable
searchIndexes = true;
partitionStorageConfigAttributes = formOutputDataStructute(solution, partitionStorageConfigAttributes, searchIndexes);
//Sort by Container / Node / Local --> APid - attr[]
/**
* POST /swctrl/lp/<container id>/<node id>/<local id>
*
* Body: {storageConfigurationGroups: [<group>, <group>]}
* <group>: {attributes: [<attr>, <attr>], newAPId: <id>, newAPisDynamic: bool, isIndex: bool }
* <attr>: {id: <id>}
*
*/
JSONObject result = new JSONObject();
for (String path : partitionStorageConfigAttributes.keySet()) {
JSONArray storageConfigurationGroups = new JSONArray();
// for each living partition
for (List<String> accessPathList : partitionStorageConfigAttributes.get(path).keySet()) {
boolean configChanged = false;
for (String attributeId : partitionStorageConfigAttributes.get(path).get(accessPathList)) {
if (attributeId.equals(""))
continue;
JSONObject jsonGroup = new JSONObject();
jsonGroup.put("newAPId", Integer.valueOf(accessPathList.get(0)));
jsonGroup.put("newAPisDynamic", Boolean.valueOf(accessPathList.get(1)));
jsonGroup.put("isIndex", Boolean.valueOf(accessPathList.get(2)));
JSONArray jsonArrayAttributes = new JSONArray();
JSONObject attribute = new JSONObject();
attribute.put("id", Integer.valueOf(attributeId));
String key = path + "/" + attributeId;
String value = accessPathList.get(0) + "_" + accessPathList.get(1) + "_" + accessPathList.get(2);
if (this.currentAccessPaths.containsKey(key) && this.currentAccessPaths.get(key).contains(value)) {
} else {
configChanged = true;
}
jsonArrayAttributes.put(attribute);
jsonGroup.put("attributes", jsonArrayAttributes);
if (!jsonArrayAttributes.isEmpty() && configChanged) {
storageConfigurationGroups.put(jsonGroup);
}
}
}
result.put("storageConfigurationGroups", storageConfigurationGroups);
// send result
logger.info("Sending result: {}", result);
if (path.equals("Config/Linkage/"))
continue;
try {
StringEntity params = new StringEntity(result.toString());
URI uri = new URIBuilder()
.setHost(ERIS_URL)
.setScheme("http")
.setPath("swctrl/lp/" + path)
.setParameter("id", sessionID)
.build();
HttpPost post = new HttpPost(uri);
post.setEntity(params);
String serverResponse = writeResult(post);
logger.info("Server responded with: {}", serverResponse);
} catch (UnsupportedEncodingException | URISyntaxException e) {
logger.error("Getting living partition failed: {}", e.getMessage());
throw new RuntimeException(e);
}
}
}
private Map<String, Map<List<String>, List<String>>> formOutputDataStructute(Solution solution, Map<String,
Map<List<String>, List<String>>> partitionStorageConfigAttributes, boolean searchIndexes){
for (Assignment assignment : solution.getAssignmentList()) { for (Assignment assignment : solution.getAssignmentList()) {
// logger.debug(assignment.getRequest().getTarget().getRef().name()); // logger.debug(assignment.getRequest().getTarget().getRef().name());
...@@ -228,9 +306,9 @@ public class ERISConnector { ...@@ -228,9 +306,9 @@ public class ERISConnector {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String containerNodePartitionPath; String containerNodePartitionPath;
String attributeId = ""; String attributeId = "";
int j = 0; int j = 1;
if (attributeGlobal[0].equals("direct")) // if (attributeGlobal[0].equals("directOrIndirect" ))
j = 1; // j = 1;
for (int i = j; i < attributeGlobal.length; i++) { for (int i = j; i < attributeGlobal.length; i++) {
if (i < 2 + j) { if (i < 2 + j) {
// can be direct // can be direct
...@@ -251,6 +329,8 @@ public class ERISConnector { ...@@ -251,6 +329,8 @@ public class ERISConnector {
boolean isDynamic = false; boolean isDynamic = false;
boolean isIndex = false; boolean isIndex = false;
// parse access path // parse access path
// can be dynamic 0 // can be dynamic 0
// accessPathName 0 // accessPathName 0
...@@ -273,9 +353,11 @@ public class ERISConnector { ...@@ -273,9 +353,11 @@ public class ERISConnector {
isIndex = true; isIndex = true;
} }
} }
}
if (isIndex != searchIndexes)
continue;
}
if (!partitionStorageConfigAttributes.containsKey(containerNodePartitionPath)) { if (!partitionStorageConfigAttributes.containsKey(containerNodePartitionPath)) {
Map<List<String>, List<String>> tempAccessPathAttributes = new HashMap<>(); Map<List<String>, List<String>> tempAccessPathAttributes = new HashMap<>();
...@@ -286,6 +368,7 @@ public class ERISConnector { ...@@ -286,6 +368,7 @@ public class ERISConnector {
tempAccessPathList.add(accessPathId); tempAccessPathList.add(accessPathId);
tempAccessPathList.add(Boolean.toString(isDynamic)); tempAccessPathList.add(Boolean.toString(isDynamic));
tempAccessPathList.add(String.valueOf(isIndex)); tempAccessPathList.add(String.valueOf(isIndex));
tempAccessPathAttributes.put(tempAccessPathList, tempAttrList); tempAccessPathAttributes.put(tempAccessPathList, tempAttrList);
partitionStorageConfigAttributes.put(containerNodePartitionPath, tempAccessPathAttributes); partitionStorageConfigAttributes.put(containerNodePartitionPath, tempAccessPathAttributes);
...@@ -306,76 +389,49 @@ public class ERISConnector { ...@@ -306,76 +389,49 @@ public class ERISConnector {
partitionStorageConfigAttributes.get(containerNodePartitionPath).get(tempAccessPathList).add(attributeId); partitionStorageConfigAttributes.get(containerNodePartitionPath).get(tempAccessPathList).add(attributeId);
} }
} }
if (searchIndexes == true) {
} ERISContainer container = containers.stream().filter(c -> c.getId() == Integer.parseInt(attributeGlobal[1])).findFirst().get();
//Sort by Container / Node / Local --> APid - attr[] ERISAttribute attribute = container.getAttributeInstance(Integer.parseInt(attributeGlobal[3]), Integer.parseInt(attributeGlobal[4])); //container [1] lp [3] id [4]
/** double lookupTime = 0;
* POST /swctrl/lp/<container id>/<node id>/<local id> double score = assignment.computeObjective();
* // must be a direct access path corresponding to the same attribute
* Body: {storageConfigurationGroups: [<group>, <group>]} for (List<String> key : partitionStorageConfigAttributes.get(containerNodePartitionPath).keySet()){
* <group>: {attributes: [<attr>, <attr>], newAPId: <id>, newAPisDynamic: bool, isIndex: bool } ArrayList<String> tempAccessPathList = new ArrayList<>();
* <attr>: {id: <id>} tempAccessPathList.add(accessPathId);
* tempAccessPathList.add(Boolean.toString(isDynamic));
*/ tempAccessPathList.add(String.valueOf(isIndex));
JSONObject result = new JSONObject(); if (!key.equals(tempAccessPathList)){
if (partitionStorageConfigAttributes.get(containerNodePartitionPath).get(key).contains(attributeId)){
ERISAccessPath accessPath = accessPaths.stream().filter(ap -> ap.getId() == Integer.parseInt(key.get(0))).findFirst().get();
lookupTime = accessPath.getLookupTime(attribute.getStatistics().getLookups());
for (String path : partitionStorageConfigAttributes.keySet()) {
JSONArray storageConfigurationGroups = new JSONArray();
// for each living partition
for (List<String> accessPathList : partitionStorageConfigAttributes.get(path).keySet()) {
boolean configChanged = false;
for (String attributeId : partitionStorageConfigAttributes.get(path).get(accessPathList)) {
if (attributeId.equals(""))
continue;
JSONObject jsonGroup = new JSONObject();
jsonGroup.put("newAPId", Integer.valueOf(accessPathList.get(0)));
jsonGroup.put("newAPisDynamic", Boolean.valueOf(accessPathList.get(1)));
jsonGroup.put("isIndex", Boolean.valueOf(accessPathList.get(2)));
JSONArray jsonArrayAttributes = new JSONArray();
JSONObject attribute = new JSONObject();
attribute.put("id", Integer.valueOf(attributeId));
String key = path + "/" + attributeId;
String value = accessPathList.get(0) + "_" + accessPathList.get(1) + "_" + accessPathList.get(2);
if (this.currentAccessPaths.containsKey(key) && this.currentAccessPaths.get(key).contains(value)) {
} else {
configChanged = true;
}
jsonArrayAttributes.put(attribute);
jsonGroup.put("attributes", jsonArrayAttributes);
if (!jsonArrayAttributes.isEmpty() && configChanged) {
storageConfigurationGroups.put(jsonGroup);
} }
} }
} }
result.put("storageConfigurationGroups", storageConfigurationGroups);
// send result int lookupCount = attribute.getStatistics().getLookups();
logger.info("Sending result: {}", result); // System.out.println("Index score: " + score);
if (path.equals("Config/Linkage/")) // System.out.println("Direct: " + (lookupTime * lookupCount));
continue; score += lookupTime * lookupCount;
try { if (score < 0) {
StringEntity params = new StringEntity(result.toString());
URI uri = new URIBuilder()
.setHost(ERIS_URL)
.setScheme("http")
.setPath("swctrl/lp/" + path)
.setParameter("id", sessionID)
.build();
HttpPost post = new HttpPost(uri);
post.setEntity(params);
String serverResponse = writeResult(post); ArrayList<String> tempAccessPathList = new ArrayList<>();
logger.info("Server responded with: {}", serverResponse); tempAccessPathList.add(accessPathId);
tempAccessPathList.add(Boolean.toString(isDynamic));
tempAccessPathList.add(String.valueOf(isIndex));
} catch (UnsupportedEncodingException | URISyntaxException e) { partitionStorageConfigAttributes.get(containerNodePartitionPath).get(tempAccessPathList).remove(attributeId);
logger.error("Getting living partition failed: {}", e.getMessage()); if (partitionStorageConfigAttributes.get(containerNodePartitionPath).get(tempAccessPathList).isEmpty()) {
throw new RuntimeException(e); partitionStorageConfigAttributes.get(containerNodePartitionPath).remove(tempAccessPathList);
if (partitionStorageConfigAttributes.get(containerNodePartitionPath).isEmpty()) {
partitionStorageConfigAttributes.remove(containerNodePartitionPath);
}
}
}
} }
} }
return partitionStorageConfigAttributes;
} }
private String writeResult(HttpPost httpPost) { private String writeResult(HttpPost httpPost) {
...@@ -401,4 +457,6 @@ public class ERISConnector { ...@@ -401,4 +457,6 @@ public class ERISConnector {
public ERISModel getErisModel() { public ERISModel getErisModel() {
return new ERISModel(containers, accessPaths); return new ERISModel(containers, accessPaths);
} }
} }
...@@ -72,4 +72,8 @@ public class ERISContainer { ...@@ -72,4 +72,8 @@ public class ERISContainer {
public void setPartitionList(List<ERISLivingPartition> partitionList) { public void setPartitionList(List<ERISLivingPartition> partitionList) {
this.partitionList = partitionList; this.partitionList = partitionList;
} }
public ERISAttribute getAttributeInstance(int partitionId, int attributeId){
return attributeList.stream().filter(a -> a.getId() == attributeId).findFirst().get();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment