Search in sources :

Example 21 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class MatrixFormatImpl method save.

private void save(ServerMatrix matrix, Path matrixPath, FileSystem fs, List<Integer> partIds, PSMatrixSaveContext saveContext, int startPos, int endPos, PSMatrixFilesMeta dataFilesMeta) throws IOException {
    Path destFile = new Path(matrixPath, ModelFilesUtils.fileName(partIds.get(startPos)));
    Path tmpDestFile = HdfsUtil.toTmpPath(destFile);
    if (fs.exists(tmpDestFile)) {
        fs.delete(tmpDestFile, true);
    }
    FSDataOutputStream out = fs.create(tmpDestFile, true, conf.getInt(AngelConf.ANGEL_PS_IO_FILE_BUFFER_SIZE, AngelConf.DEFAULT_ANGEL_PS_IO_FILE_BUFFER_SIZE));
    long streamPos = 0;
    ServerPartition partition;
    for (int i = startPos; i < endPos; i++) {
        LOG.info("Write partition " + partIds.get(i) + " of matrix " + matrix.getName() + " to " + tmpDestFile);
        streamPos = out.getPos();
        partition = matrix.getPartition(partIds.get(i));
        PartitionKey partKey = partition.getPartitionKey();
        MatrixPartitionMeta partMeta;
        long startCol = 0;
        long endCol = 0;
        if (useRange) {
            startCol = partKey.getStartCol();
            endCol = partKey.getEndCol();
        }
        partMeta = new MatrixPartitionMeta(partKey.getPartitionId(), partKey.getStartRow(), partKey.getEndRow(), startCol, endCol, partition.getElemNum(), destFile.getName(), streamPos, 0);
        save(partition, partMeta, saveContext, out);
        partMeta.setLength(out.getPos() - streamPos);
        dataFilesMeta.addPartitionMeta(partIds.get(i), partMeta);
    }
    out.flush();
    out.close();
    HdfsUtil.rename(tmpDestFile, destFile, fs);
}
Also used : Path(org.apache.hadoop.fs.Path) PartitionKey(com.tencent.angel.PartitionKey) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 22 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GetPartHandler method handle.

@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
    GetPartitionRequest request = (GetPartitionRequest) data;
    ServerPartition partition = MatrixUtils.getPart(context.getMatrixStorageManager(), header.matrixId, header.partId);
    return new GetPartitionResponse(partition);
}
Also used : GetPartitionResponse(com.tencent.angel.ps.server.data.response.GetPartitionResponse) GetPartitionRequest(com.tencent.angel.ps.server.data.request.GetPartitionRequest) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 23 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class MatrixUtils method getPart.

public static ServerPartition getPart(MatrixStorageManager storageManager, int matrixId, int partId) {
    ServerMatrix matrix = storageManager.getMatrix(matrixId);
    if (matrix == null) {
        throw new ObjectNotFoundException("Can not find matrix " + matrixId);
    }
    ServerPartition part = matrix.getPartition(partId);
    if (part == null) {
        throw new ObjectNotFoundException("Can not find partition " + partId + " of matrix " + matrixId);
    }
    return part;
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) ObjectNotFoundException(com.tencent.angel.ps.server.data.exception.ObjectNotFoundException) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 24 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class MatrixUtils method getRow.

public static ServerRow getRow(MatrixStorageManager storageManager, int matrixId, int partId, int rowId) {
    ServerMatrix matrix = storageManager.getMatrix(matrixId);
    if (matrix == null) {
        throw new ObjectNotFoundException("Can not find matrix " + matrixId);
    }
    ServerPartition part = matrix.getPartition(partId);
    if (part == null) {
        throw new ObjectNotFoundException("Can not find partition " + partId + " of matrix " + matrixId);
    }
    if (!(part instanceof RowBasedPartition)) {
        throw new UnsupportedOperationException("Get row only support for RowBasedPartition");
    }
    ServerRow row = ((RowBasedPartition) part).getRow(rowId);
    if (row == null) {
        throw new ObjectNotFoundException("Can not find row " + rowId + " of matrix " + matrixId + " in partition " + partId);
    }
    return row;
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) ObjectNotFoundException(com.tencent.angel.ps.server.data.exception.ObjectNotFoundException) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 25 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GraphMatrixUtils method getPSLongKeyRow.

public static ServerLongAnyRow getPSLongKeyRow(PSContext psContext, PartitionUpdateParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    return (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Aggregations

ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)30 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)22 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)11 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 Path (org.apache.hadoop.fs.Path)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 IOException (java.io.IOException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 ServiceException (com.google.protobuf.ServiceException)1 PartitionKey (com.tencent.angel.PartitionKey)1 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)1