Refactor AccumuloIndex put into IndexTableWrapper

This commit is contained in:
Michael Lieberman
2015-01-21 13:37:17 -05:00
parent e59c590eae
commit eacf44c755
2 changed files with 24 additions and 23 deletions

View File

@@ -15,9 +15,6 @@
package edu.jhuapl.tinkerpop;
import java.util.Iterator;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.data.Mutation;
import com.tinkerpop.blueprints.CloseableIterable;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Index;
@@ -66,16 +63,7 @@ public class AccumuloIndex<T extends Element> implements Index<T> {
@Override
public void put(String key, Object value, Element element) {
element.setProperty(key, value);
Mutation m = new Mutation(AccumuloByteSerializer.serialize(value));
m.put(key.getBytes(), element.getId().toString().getBytes(), "".getBytes());
BatchWriter w = getWriter();
try {
w.addMutation(m);
w.flush();
} catch (MutationsRejectedException e) {
throw new AccumuloGraphException(e);
}
indexWrapper.setPropertyForIndex(element, key, value, true);
}
@Override
@@ -105,8 +93,4 @@ public class AccumuloIndex<T extends Element> implements Index<T> {
public void remove(String key, Object value, Element element) {
indexWrapper.removePropertyFromIndex(element, key, value);
}
private BatchWriter getWriter() {
return globals.getGraph().getWriter(getTableName());
}
}

View File

@@ -29,6 +29,7 @@ import org.apache.hadoop.io.Text;
import com.tinkerpop.blueprints.CloseableIterable;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.IndexableGraph;
import com.tinkerpop.blueprints.Vertex;
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
@@ -56,18 +57,34 @@ public abstract class IndexTableWrapper extends BaseTableWrapper {
}
/**
* Add the property to this index.
*
* <p/>Note that this requires a round-trip to Accumulo to see
* if the property exists if the provided key has an index.
* So for best performance, create indices after bulk ingest.
* Add the property to this index, if autoindexing is enabled
* and/or the given key has indexing enabled.
* @param element
* @param key
* @param value
*/
public void setPropertyForIndex(Element element, String key, Object value) {
setPropertyForIndex(element, key, value, false);
}
/**
* Add the property to this index.
*
* <p/>Note that this requires a round-trip to Accumulo to see
* if the property exists if the provided key has an index.
* So for best performance, create indices after bulk ingest.
* <p/>If the force parameter is true, set the property regardless
* of whether indexing is enabled for the given key. This is needed
* for {@link IndexableGraph} operations.
* @param element
* @param key
* @param value
* @param force
*/
public void setPropertyForIndex(Element element, String key, Object value,
boolean force) {
AccumuloGraphUtils.validateProperty(key, value);
if (globals.getConfig().getAutoIndex() ||
if (force || globals.getConfig().getAutoIndex() ||
globals.getGraph().getIndexedKeys(elementType).contains(key)) {
BatchWriter writer = getWriter();