Search in sources :

Example 6 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class ComplexRowFormat method save.

@Override
public void save(RowBasedPartition part, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
    List<Integer> rowIds = saveContext.getRowIndexes();
    if (rowIds == null || rowIds.isEmpty()) {
        Iterator<Entry<Integer, ServerRow>> iter = part.getRowsStorage().iterator();
        rowIds = new ArrayList<>();
        while (iter.hasNext()) {
            rowIds.add(iter.next().getKey());
        }
    } else {
        rowIds = filter(part, rowIds);
    }
    FSDataOutputStream dataOutputStream = new FSDataOutputStream(output, null, partMeta != null ? partMeta.getOffset() : 0);
    partMeta.setSaveRowNum(rowIds.size());
    for (int rowId : rowIds) {
        ServerRow row = part.getRow(rowId);
        RowPartitionMeta rowMeta = new RowPartitionMeta(rowId, 0, 0);
        if (row != null) {
            rowMeta.setElementNum(row.size());
            rowMeta.setOffset(dataOutputStream.getPos());
            save(part.getRow(rowId), saveContext, partMeta, output);
        } else {
            rowMeta.setElementNum(0);
            rowMeta.setOffset(dataOutputStream.getPos());
        }
        partMeta.setRowMeta(rowMeta);
    }
}
Also used : Entry(java.util.Map.Entry) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream)

Example 7 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class SnapshotFormat method save.

/**
 * Matrix partition data
 *
 * @param part matrix partition
 * @param partMeta matrix partition data meta
 * @param saveContext save context
 * @param output output stream
 */
public void save(RowBasedPartition part, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
    List<Integer> rowIds = saveContext.getRowIndexes();
    ServerRowsStorage rows = part.getRowsStorage();
    if (rowIds == null || rowIds.isEmpty()) {
        int rowStart = part.getPartitionKey().getStartRow();
        int rowEnd = part.getPartitionKey().getEndRow();
        rowIds = new ArrayList<>(rowEnd - rowStart);
        for (int i = rowStart; i < rowEnd; i++) {
            rowIds.add(i);
        }
    } else {
        rowIds = filter(part, rowIds);
    }
    FSDataOutputStream dataOutputStream = new FSDataOutputStream(output, null, partMeta != null ? partMeta.getOffset() : 0);
    partMeta.setSaveRowNum(rowIds.size());
    for (int rowId : rowIds) {
        ServerRow row = rows.getRow(rowId);
        RowPartitionMeta rowMeta = new RowPartitionMeta(rowId, 0, 0);
        if (row != null) {
            rowMeta.setElementNum(row.size());
            rowMeta.setOffset(dataOutputStream.getPos());
            if (row.isDense()) {
                rowMeta.setSaveType(SaveType.DENSE.getTypeId());
            } else {
                rowMeta.setSaveType(SaveType.SPARSE.getTypeId());
            }
            save(rows.getRow(rowId), saveContext, partMeta, output);
        } else {
            rowMeta.setElementNum(0);
            rowMeta.setOffset(dataOutputStream.getPos());
        }
        partMeta.setRowMeta(rowMeta);
    }
}
Also used : ServerRowsStorage(com.tencent.angel.ps.storage.partition.storage.ServerRowsStorage) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream)

Example 8 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class GetRowsHandler method merge.

private Vector[] merge(int matrixId, int[] rowIds, Collection<Response> responses) {
    Map<Integer, List<ServerRow>> rowIdToserverRows = new HashMap<>(rowIds.length);
    int valueNum = responses.size();
    for (Response response : responses) {
        ServerRow[] serverRows = ((GetRowsSplitResponse) (response.getData())).getRowsSplit();
        for (int j = 0; j < serverRows.length; j++) {
            int rowId = serverRows[j].getRowId();
            List<ServerRow> rowSplits = rowIdToserverRows.get(rowId);
            if (rowSplits == null) {
                rowSplits = new ArrayList<>(valueNum);
                rowIdToserverRows.put(rowId, rowSplits);
            }
            rowSplits.add(serverRows[j]);
        }
    }
    Vector[] vectors = new Vector[rowIds.length];
    for (int i = 0; i < rowIds.length; i++) {
        vectors[i] = MergeUtils.combineServerRowSplits(rowIdToserverRows.get(rowIds[i]), matrixId, rowIds[i]);
        vectors[i].setMatrixId(matrixId);
        vectors[i].setRowId(rowIds[i]);
    }
    return vectors;
}
Also used : HashMap(java.util.HashMap) Response(com.tencent.angel.ps.server.data.response.Response) GetRowsSplitResponse(com.tencent.angel.ps.server.data.response.GetRowsSplitResponse) GetRowsSplitResponse(com.tencent.angel.ps.server.data.response.GetRowsSplitResponse) ArrayList(java.util.ArrayList) List(java.util.List) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 9 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class GetRowHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    GetRowRequest getRowRequest = (GetRowRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Merge the sub-response
    List<ServerRow> serverRows = new ArrayList<>(cache.expectedResponseNum);
    for (Response response : cache.getResponses().values()) {
        serverRows.add(((GetRowSplitResponse) (response.getData())).getRowSplit());
    }
    Vector vector = MergeUtils.combineServerRowSplits(serverRows, getRowRequest.getMatrixId(), getRowRequest.getRowId());
    // Set matrix/row information
    vector.setMatrixId(getRowRequest.getMatrixId());
    vector.setRowId(getRowRequest.getRowId());
    // Set result
    finalResult.set(vector);
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) GetRowSplitResponse(com.tencent.angel.ps.server.data.response.GetRowSplitResponse) GetRowRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetRowRequest) ArrayList(java.util.ArrayList) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 10 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class UpdatePartFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    CSRPartUpdateParam param = (CSRPartUpdateParam) partParam;
    PartitionKey pkey = partParam.getPartKey();
    pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
    try {
        while (param.buf.isReadable()) {
            int row = param.buf.readInt();
            int len = param.buf.readInt();
            ServerRow serverRow = psContext.getMatrixStorageManager().getRow(pkey, row);
            try {
                serverRow.startWrite();
                if (serverRow.isDense())
                    updateDenseIntRow((ServerIntIntRow) serverRow, param.buf, len);
                if (serverRow.isSparse())
                    updateSparseIntRow((ServerIntIntRow) serverRow, param.buf, len);
            } finally {
                serverRow.endWrite();
            }
        }
    } finally {
        param.buf.release();
    }
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Aggregations

ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)42 Vector (com.tencent.angel.ml.math2.vector.Vector)13 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)6 PartIncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam)5 RowUpdateSplit (com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit)5 ArrayList (java.util.ArrayList)5 PartitionKey (com.tencent.angel.PartitionKey)4 ServerIntIntRow (com.tencent.angel.ps.storage.vector.ServerIntIntRow)4 AngelException (com.tencent.angel.exception.AngelException)2 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)2 RowType (com.tencent.angel.ml.matrix.RowType)2 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam)2 GetRowSplitResponse (com.tencent.angel.ps.server.data.response.GetRowSplitResponse)2 GetRowsSplitResponse (com.tencent.angel.ps.server.data.response.GetRowsSplitResponse)2 Response (com.tencent.angel.ps.server.data.response.Response)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)2 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)2 ServerRowsStorage (com.tencent.angel.ps.storage.partition.storage.ServerRowsStorage)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2