use of org.vertexium.VertexiumException in project vertexium by visallo.
the class DataInDataTableStreamingPropertyValueStorageStrategy method saveStreamingPropertyValue.
@Override
public StreamingPropertyValueRef saveStreamingPropertyValue(ElementMutationBuilder elementMutationBuilder, String rowKey, Property property, StreamingPropertyValue streamingPropertyValue) {
try {
String dataTableRowKey = new DataTableRowKey(rowKey, property).getRowKey();
InputStream in = streamingPropertyValue.getInputStream();
byte[] buffer = new byte[dataInDataTablePartSize];
long offset = 0;
while (true) {
int read = in.read(buffer);
if (read <= 0) {
break;
}
Mutation dataMutation = new Mutation(dataTableRowKey);
Text columnQualifier = new Text(String.format("%08x", offset));
dataMutation.put(DATA_COLUMN_FAMILY, columnQualifier, property.getTimestamp(), new Value(buffer, 0, read));
elementMutationBuilder.saveDataMutation(dataMutation);
offset += read;
}
Mutation dataMutation = new Mutation(dataTableRowKey);
dataMutation.put(METADATA_COLUMN_FAMILY, METADATA_LENGTH_COLUMN_QUALIFIER, property.getTimestamp(), new Value(Longs.toByteArray(offset)));
elementMutationBuilder.saveDataMutation(dataMutation);
return new StreamingPropertyValueTableDataRef(dataTableRowKey, streamingPropertyValue, offset);
} catch (Exception ex) {
throw new VertexiumException("Could not store streaming property value", ex);
}
}
use of org.vertexium.VertexiumException 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.vertexium.VertexiumException in project vertexium by visallo.
the class OverflowIntoHdfsStreamingPropertyValueStorageStrategy method saveStreamingPropertyValue.
@Override
public StreamingPropertyValueRef saveStreamingPropertyValue(ElementMutationBuilder elementMutationBuilder, String rowKey, Property property, StreamingPropertyValue streamingPropertyValue) {
try {
HdfsLargeDataStore largeDataStore = new HdfsLargeDataStore(this.fileSystem, this.dataDir, rowKey, property);
LimitOutputStream out = new LimitOutputStream(largeDataStore, maxStreamingPropertyValueTableDataSize);
try {
IOUtils.copy(streamingPropertyValue.getInputStream(), out);
} finally {
out.close();
}
if (out.hasExceededSizeLimit()) {
LOGGER.debug("saved large file to \"%s\" (length: %d)", largeDataStore.getFullHdfsPath(), out.getLength());
return new StreamingPropertyValueHdfsRef(largeDataStore.getRelativeFileName(), streamingPropertyValue);
} else {
return saveStreamingPropertyValueSmall(elementMutationBuilder, rowKey, property, out.getSmall(), streamingPropertyValue);
}
} catch (IOException ex) {
throw new VertexiumException(ex);
}
}
use of org.vertexium.VertexiumException 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);
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class IdStrategy method extendedDataRowIdFromSearchHit.
public ExtendedDataRowId extendedDataRowIdFromSearchHit(SearchHit hit) {
SearchHitField elementTypeField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
if (elementTypeField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
}
ElementType elementType = ElasticsearchDocumentType.parse(elementTypeField.getValue().toString()).toElementType();
SearchHitField elementIdField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_ID_FIELD_NAME);
if (elementIdField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_ID_FIELD_NAME);
}
String elementId = elementIdField.getValue();
SearchHitField tableNameField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
if (tableNameField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
}
String tableName = tableNameField.getValue();
SearchHitField rowIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
if (rowIdField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
}
String rowId = rowIdField.getValue();
return new ExtendedDataRowId(elementType, elementId, tableName, rowId);
}
Aggregations