use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.
the class IndexGetRowHandler method handle.
@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
IndexPartGetRowRequest request = (IndexPartGetRowRequest) data;
KeyPart keyPart = request.getKeyPart();
ServerRow row = MatrixUtils.getRow(context.getMatrixStorageManager(), header.matrixId, header.partId, request.getRowId());
ValuePart result;
StreamIndexPartGetRowResponse response;
row.startRead();
try {
result = ServerRowUtils.getByKeys(row, keyPart);
response = new StreamIndexPartGetRowResponse(result);
return response;
} finally {
row.endRead();
}
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.
the class IndexGetRowsHandler method handle.
@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
IndexPartGetRowsRequest request = (IndexPartGetRowsRequest) data;
int[] rowIds = request.getRowIds();
KeyPart keyPart = request.getKeyPart();
ServerRow[] rows = new ServerRow[rowIds.length];
ValuePart[] results = new ValuePart[rowIds.length];
for (int i = 0; i < rowIds.length; i++) {
rows[i] = context.getMatrixStorageManager().getRow(header.matrixId, rowIds[i], header.partId);
rows[i].startRead();
try {
results[i] = ServerRowUtils.getByKeys(rows[i], keyPart);
} finally {
rows[i].endRead();
}
}
IndexPartGetRowsResponse response = new IndexPartGetRowsResponse(results);
return response;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.
the class UserRequestAdapter method get.
private FutureResult<Vector> get(IndexGetRowRequest request) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(request.getMatrixId());
PartitionKey[] parts = matrixMeta.getPartitionKeys();
// Split the user request to partition requests
FutureResult<Vector> result = new FutureResult<>();
KeyPart[] splits;
long startTs = System.currentTimeMillis();
if (request instanceof IntIndexGetRowRequest) {
splits = RouterUtils.split(matrixMeta, -1, ((IntIndexGetRowRequest) request).getKeys());
} else if (request instanceof LongIndexGetRowRequest) {
splits = RouterUtils.split(matrixMeta, -1, ((LongIndexGetRowRequest) request).getKeys());
} else {
throw new UnsupportedOperationException("Unsupport index request type " + request.getClass().toString());
}
LOG.info("Get by indices split use time: " + (System.currentTimeMillis() - startTs));
assert parts.length == splits.length;
// filter empty partition requests
int needRequestPartNum = noEmptyPartNum(splits);
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
// Create partition results cache
ResponseCache cache = new MapResponseCache(needRequestPartNum);
int requestId = request.getRequestId();
requestIdToResponseCache.put(requestId, cache);
requestIdToResultMap.put(requestId, result);
requests.put(requestId, request);
// Send all the partition requests
MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
for (int i = 0; i < splits.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
sendIndexGetRowRequest(matrixClient, requestId, request.getMatrixId(), request.getRowId(), parts[i].getPartitionId(), splits[i], request.getFunc());
}
}
return result;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.
the class GeneralGetUtils method partitionGet.
public static PartitionGetResult partitionGet(PSContext psContext, PartitionGetParam partParam) {
GeneralPartGetParam param = (GeneralPartGetParam) partParam;
KeyPart keyPart = param.getIndicesPart();
// Long type node id
long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
// Get data
IElement[] data = new IElement[nodeIds.length];
for (int i = 0; i < nodeIds.length; i++) {
data[i] = row.get(nodeIds[i]);
}
MatrixMeta meta = psContext.getMatrixMetaManager().getMatrixMeta(param.getMatrixId());
try {
return new PartGeneralGetResult(meta.getValueClass(), nodeIds, data);
} catch (ClassNotFoundException e) {
throw new AngelException("Can not get value class ");
}
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.
the class IntKeysGetParam method split.
@Override
public List<PartitionGetParam> split() {
// Get matrix meta
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = meta.getPartitionKeys();
// Split
KeyPart[] nodeIdsParts = RouterUtils.split(meta, 0, nodeIds, false);
// Generate Part psf get param
List<PartitionGetParam> partParams = new ArrayList<>(parts.length);
assert parts.length == nodeIdsParts.length;
for (int i = 0; i < parts.length; i++) {
if (nodeIdsParts[i] != null && nodeIdsParts[i].size() > 0) {
partParams.add(new GeneralPartGetParam(matrixId, parts[i], nodeIdsParts[i]));
}
}
return partParams;
}
Aggregations