Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use cloning rather than save/restore to for request specialization

  • Loading branch information...
commit b3255628b5d874f89da6f839891aaec8a894dcb8 1 parent b818d8c
Joshua Hartman authored
View
27 sensei-core/src/main/java/com/senseidb/search/node/AbstractConsistentHashBroker.java
@@ -5,6 +5,7 @@
import com.linkedin.norbert.network.common.ExceptionIterator;
import com.linkedin.norbert.network.common.PartialIterator;
import com.linkedin.norbert.network.common.TimeoutIterator;
+import com.senseidb.search.req.SenseiRequest;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
@@ -98,11 +99,7 @@ public AbstractConsistentHashBroker(PartitionedNetworkClient<String> networkClie
public <T> T customizeRequest(REQUEST request)
{
- return null;
- }
-
- public <T> T restoreRequest(REQUEST request,T state){
- return state;
+ return (T) request;
}
protected IntSet getPartitions(Set<Node> nodes)
@@ -220,18 +217,13 @@ public RESULT call() throws Exception {
private int count = 0;
@Override
public REQUEST apply(Node node, Set<Integer> nodePartitions) {
- synchronized (req) {
- req.setPartitions(nodePartitions);
-
- if(count != 0)
- req.restoreState();
+ // TODO: Cloning is yucky per http://www.artima.com/intv/bloch13.html
+ REQUEST clone = (REQUEST) (((SenseiRequest) req).clone());
+
+ clone.setPartitions(nodePartitions);
- req.saveState();
- REQUEST customizedRequest = customizeRequest(req);
-
- count++;
- return customizedRequest;
- }
+ REQUEST customizedRequest = customizeRequest(clone);
+ return customizedRequest;
}
}, _serializer));
@@ -239,9 +231,6 @@ public REQUEST apply(Node node, Set<Integer> nodePartitions) {
resultList.add(responseIterator.next());
}
- // restore the last customization
- req.restoreState();
-
logger.debug(String.format("There are %d responses", resultList.size()));
return resultList;
View
1  sensei-core/src/main/java/com/senseidb/search/node/SenseiBroker.java
@@ -111,7 +111,6 @@ private void recoverSrcData(SenseiHit[] hits, boolean isFetchStoredFields)
@Override
public SenseiResult mergeResults(SenseiRequest request, List<SenseiResult> resultList)
{
- request.restoreState();
SenseiResult res = ResultMerger.merge(request, resultList, false);
if (request.isFetchStoredFields() || request.isFetchStoredValue())
View
4 sensei-core/src/main/java/com/senseidb/search/req/AbstractSenseiRequest.java
@@ -8,6 +8,6 @@
public void setPartitions(Set<Integer> partitions);
public Set<Integer> getPartitions();
public String getRouteParam();
- public void saveState();
- public void restoreState();
+// public void saveState();
+// public void restoreState();
}
View
13 sensei-core/src/main/java/com/senseidb/search/req/SenseiRequest.java
@@ -471,8 +471,8 @@ public String toString(){
return buf.toString();
}
- public SenseiRequest clone()
- {
+ @Override
+ public SenseiRequest clone() {
SenseiRequest clone = new SenseiRequest();
clone.setTid(this.getTid());
@@ -483,7 +483,13 @@ public SenseiRequest clone()
for(SortField sort : this.getSort())
clone.addSortField(sort);
- clone.setFacetSpecs(this.getFacetSpecs());
+
+ Map<String, FacetSpec> cloneFacetSpecs = new HashMap<String, FacetSpec>();
+ for(Entry<String, FacetSpec> facetSpec : this.getFacetSpecs().entrySet()) {
+ cloneFacetSpecs.put(facetSpec.getKey(), facetSpec.getValue().clone());
+ }
+
+ clone.setFacetSpecs(cloneFacetSpecs);
clone.setQuery(this.getQuery());
clone.setOffset(this.getOffset());
clone.setCount(this.getCount());
@@ -498,6 +504,7 @@ public SenseiRequest clone()
clone.setTermVectorsToFetch(this.getTermVectorsToFetch());
clone.setSelectList(this.getSelectList());
clone.setMapReduceFunction(this.getMapReduceFunction());
+
return clone;
}
Please sign in to comment.
Something went wrong with that request. Please try again.