Search in sources :

Example 21 with Span

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();
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span) IteratorFetchHints(org.vertexium.accumulo.iterator.model.IteratorFetchHints) PropertyMetadataColumnQualifier(org.vertexium.accumulo.iterator.model.PropertyMetadataColumnQualifier) StreamingPropertyValueRef(org.vertexium.property.StreamingPropertyValueRef) PropertyColumnQualifier(org.vertexium.accumulo.iterator.model.PropertyColumnQualifier) HistoricalPropertyValueBuilder(org.vertexium.HistoricalPropertyValue.HistoricalPropertyValueBuilder) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 22 with Span

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();
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span)

Example 23 with Span

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();
    }
}
Also used : ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Span(org.apache.accumulo.core.trace.Span)

Example 24 with Span

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);
    }
}
Also used : HashMap(java.util.HashMap) ScannerBase(org.apache.accumulo.core.client.ScannerBase) Span(org.apache.accumulo.core.trace.Span) VertexiumException(org.vertexium.VertexiumException) IOException(java.io.IOException) VertexiumException(org.vertexium.VertexiumException) org.vertexium.accumulo(org.vertexium.accumulo) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) HashMap(java.util.HashMap) Map(java.util.Map) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) Key(org.apache.accumulo.core.data.Key)

Example 25 with Span

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);
    }
}
Also used : TimestampFilter(org.apache.accumulo.core.iterators.user.TimestampFilter) ScannerBase(org.apache.accumulo.core.client.ScannerBase) Range(org.apache.accumulo.core.data.Range) Span(org.apache.accumulo.core.trace.Span) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Map(java.util.Map) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) Key(org.apache.accumulo.core.data.Key)

Aggregations

Span (org.apache.accumulo.core.trace.Span)56 Key (org.apache.accumulo.core.data.Key)12 Value (org.apache.accumulo.core.data.Value)12 IOException (java.io.IOException)11 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)10 Text (org.apache.hadoop.io.Text)9 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 PartialKey (org.apache.accumulo.core.data.PartialKey)6 Mutation (org.apache.accumulo.core.data.Mutation)5 IndexHint (org.vertexium.search.IndexHint)5 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 Connector (org.apache.accumulo.core.client.Connector)4 Scanner (org.apache.accumulo.core.client.Scanner)4 ReplicationTableOfflineException (org.apache.accumulo.core.replication.ReplicationTableOfflineException)4 Status (org.apache.accumulo.server.replication.proto.Replication.Status)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3