use of org.apache.accumulo.core.trace.Span in project vertexium by visallo.
the class AccumuloGraph method getHistoricalPropertyValues.
public Iterable<HistoricalPropertyValue> getHistoricalPropertyValues(Element element, String key, String name, Visibility visibility, Long startTime, Long endTime, Authorizations authorizations) {
Span trace = Trace.start("getHistoricalPropertyValues");
if (Trace.isTracing()) {
trace.data("key", key);
trace.data("name", name);
trace.data("visibility", visibility.getVisibilityString());
if (startTime != null) {
trace.data("startTime", Long.toString(startTime));
}
if (endTime != null) {
trace.data("endTime", Long.toString(endTime));
}
}
try {
ElementType elementType = ElementType.getTypeFromElement(element);
FetchHints fetchHints = FetchHints.PROPERTIES_AND_METADATA;
traceDataFetchHints(trace, fetchHints);
org.apache.accumulo.core.data.Range range = RangeUtils.createRangeFromString(element.getId());
final ScannerBase scanner = createElementScanner(fetchHints, elementType, ALL_VERSIONS, startTime, endTime, Lists.newArrayList(range), false, authorizations);
try {
Map<String, HistoricalPropertyValue> results = new HashMap<>();
ArrayListMultimap<String, String> activeVisibilities = ArrayListMultimap.create();
Map<String, Key> softDeleteObserved = Maps.newHashMap();
for (Map.Entry<Key, Value> column : scanner) {
String cq = column.getKey().getColumnQualifier().toString();
String columnVisibility = column.getKey().getColumnVisibility().toString();
if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY)) {
if (visibility != null && !columnVisibility.equals(visibility.getVisibilityString())) {
continue;
}
PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
if (name != null && !propertyColumnQualifier.getPropertyName().equals(name)) {
continue;
}
if (key != null && !propertyColumnQualifier.getPropertyKey().equals(key)) {
continue;
}
String resultsKey = propertyColumnQualifier.getDiscriminator(columnVisibility, column.getKey().getTimestamp());
long timestamp = column.getKey().getTimestamp();
Object value = vertexiumSerializer.bytesToObject(column.getValue().get());
Metadata metadata = new Metadata();
// TODO should we preserve these over time
Set<Visibility> hiddenVisibilities = null;
if (value instanceof StreamingPropertyValueRef) {
// noinspection unchecked
value = ((StreamingPropertyValueRef) value).toStreamingPropertyValue(this, timestamp);
}
String propertyKey = propertyColumnQualifier.getPropertyKey();
String propertyName = propertyColumnQualifier.getPropertyName();
Visibility propertyVisibility = accumuloVisibilityToVisibility(columnVisibility);
HistoricalPropertyValue hpv = new HistoricalPropertyValueBuilder(propertyKey, propertyName, timestamp).propertyVisibility(propertyVisibility).value(value).metadata(metadata).hiddenVisibilities(hiddenVisibilities).build();
String propIdent = propertyKey + ":" + propertyName;
activeVisibilities.put(propIdent, columnVisibility);
results.put(resultsKey, hpv);
} else if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY_SOFT_DELETE)) {
PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
String propertyKey = propertyColumnQualifier.getPropertyKey();
String propertyName = propertyColumnQualifier.getPropertyName();
String propIdent = propertyKey + ":" + propertyName;
activeVisibilities.remove(propIdent, columnVisibility);
softDeleteObserved.put(propIdent, column.getKey());
} else if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY_METADATA)) {
PropertyMetadataColumnQualifier propertyMetadataColumnQualifier = KeyHelper.createPropertyMetadataColumnQualifier(cq, getNameSubstitutionStrategy());
String resultsKey = propertyMetadataColumnQualifier.getPropertyDiscriminator(column.getKey().getTimestamp());
HistoricalPropertyValue hpv = results.get(resultsKey);
if (hpv == null) {
continue;
}
Object value = vertexiumSerializer.bytesToObject(column.getValue().get());
Visibility metadataVisibility = accumuloVisibilityToVisibility(columnVisibility);
hpv.getMetadata().add(propertyMetadataColumnQualifier.getMetadataKey(), value, metadataVisibility);
}
}
for (Key entry : softDeleteObserved.values()) {
String cq = entry.getColumnQualifier().toString();
PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
String propertyKey = propertyColumnQualifier.getPropertyKey();
String propertyName = propertyColumnQualifier.getPropertyName();
String propIdent = propertyKey + ":" + propertyName;
List<String> active = activeVisibilities.get(propIdent);
if (active == null || active.isEmpty()) {
long timestamp = entry.getTimestamp() + 1;
String columnVisibility = entry.getColumnVisibility().toString();
Visibility propertyVisibility = accumuloVisibilityToVisibility(columnVisibility);
HistoricalPropertyValue hpv = new HistoricalPropertyValueBuilder(propertyKey, propertyName, timestamp).propertyVisibility(propertyVisibility).isDeleted(true).build();
String resultsKey = propertyColumnQualifier.getDiscriminator(columnVisibility, timestamp);
results.put(resultsKey, hpv);
}
}
return new TreeSet<>(results.values());
} finally {
scanner.close();
}
} finally {
trace.stop();
}
}
use of org.apache.accumulo.core.trace.Span in project vertexium by visallo.
the class AccumuloGraph method deleteExtendedDataRow.
@Override
public void deleteExtendedDataRow(ExtendedDataRowId rowId, Authorizations authorizations) {
checkNotNull(rowId);
Span trace = Trace.start("deleteExtendedDataRow");
trace.data("rowId", rowId.toString());
try {
getSearchIndex().deleteExtendedData(this, rowId, authorizations);
addMutations(VertexiumObjectType.EXTENDED_DATA, getDeleteExtendedDataMutations(rowId));
if (hasEventListeners()) {
queueEvent(new DeleteExtendedDataRowEvent(this, rowId));
}
} finally {
trace.stop();
}
}
use of org.apache.accumulo.core.trace.Span in project vertexium by visallo.
the class AccumuloGraph method markPropertyVisible.
@SuppressWarnings("unused")
public void markPropertyVisible(AccumuloElement element, Property property, Long timestamp, Visibility visibility, Authorizations authorizations) {
checkNotNull(element);
Span trace = Trace.start("markPropertyVisible");
trace.data("elementId", element.getId());
trace.data("propertyName", property.getName());
trace.data("propertyKey", property.getKey());
try {
if (timestamp == null) {
timestamp = IncreasingTime.currentTimeMillis();
}
ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(visibility);
if (element instanceof Vertex) {
addMutations(VertexiumObjectType.VERTEX, getMarkVisiblePropertyMutation(element.getId(), property, timestamp, columnVisibility));
} else if (element instanceof Edge) {
addMutations(VertexiumObjectType.EDGE, getMarkVisiblePropertyMutation(element.getId(), property, timestamp, columnVisibility));
}
getSearchIndex().markPropertyVisible(this, element, property, visibility, authorizations);
if (hasEventListeners()) {
fireGraphEvent(new MarkVisiblePropertyEvent(this, element, property, visibility));
}
} finally {
trace.stop();
}
}
use of org.apache.accumulo.core.trace.Span in project vertexium by visallo.
the class OverflowIntoHdfsStreamingPropertyValueStorageStrategy method streamingPropertyValueTableDatas.
private Map<String, byte[]> streamingPropertyValueTableDatas(List<String> dataRowKeys) {
try {
if (dataRowKeys.size() == 0) {
return Collections.emptyMap();
}
List<org.apache.accumulo.core.data.Range> ranges = dataRowKeys.stream().map(RangeUtils::createRangeFromString).collect(Collectors.toList());
final long timerStartTime = System.currentTimeMillis();
ScannerBase scanner = graph.createBatchScanner(graph.getDataTableName(), ranges, new org.apache.accumulo.core.security.Authorizations());
graph.getGraphLogger().logStartIterator(scanner);
Span trace = Trace.start("streamingPropertyValueTableData");
trace.data("dataRowKeyCount", Integer.toString(dataRowKeys.size()));
try {
Map<String, byte[]> results = new HashMap<>();
for (Map.Entry<Key, Value> col : scanner) {
results.put(col.getKey().getRow().toString(), col.getValue().get());
}
return results;
} finally {
scanner.close();
trace.stop();
graph.getGraphLogger().logEndIterator(System.currentTimeMillis() - timerStartTime);
}
} catch (Exception ex) {
throw new VertexiumException(ex);
}
}
use of org.apache.accumulo.core.trace.Span in project vertexium by visallo.
the class StreamingPropertyValueTable method streamingPropertyValueTableData.
public byte[] streamingPropertyValueTableData(String dataRowKey, Long timestamp) {
try {
List<Range> ranges = Lists.newArrayList(RangeUtils.createRangeFromString(dataRowKey));
long timerStartTime = System.currentTimeMillis();
ScannerBase scanner = graph.createBatchScanner(graph.getDataTableName(), ranges, new org.apache.accumulo.core.security.Authorizations());
if (timestamp != null && !DataTableRowKey.isLegacy(dataRowKey)) {
IteratorSetting iteratorSetting = new IteratorSetting(80, TimestampFilter.class.getSimpleName(), TimestampFilter.class);
TimestampFilter.setStart(iteratorSetting, timestamp, true);
TimestampFilter.setEnd(iteratorSetting, timestamp, true);
scanner.addScanIterator(iteratorSetting);
}
GRAPH_LOGGER.logStartIterator(scanner);
Span trace = Trace.start("streamingPropertyValueTableData");
trace.data("dataRowKeyCount", Integer.toString(1));
try {
byte[] result = null;
for (Map.Entry<Key, Value> col : scanner) {
String foundKey = col.getKey().getRow().toString();
byte[] value = col.getValue().get();
if (foundKey.equals(dataRowKey)) {
result = value;
}
}
if (result == null) {
throw new VertexiumException("Could not find data with key: " + dataRowKey);
}
return result;
} finally {
scanner.close();
trace.stop();
GRAPH_LOGGER.logEndIterator(System.currentTimeMillis() - timerStartTime);
}
} catch (Exception ex) {
throw new VertexiumException(ex);
}
}
Aggregations