Search in sources :

Example 71 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class ServerPartition method deserialize.

@Override
public void deserialize(ByteBuf buf) {
    partitionKey = new PartitionKey();
    partitionKey.deserialize(buf);
    rowType = RowType.valueOf(buf.readInt());
    int rowNum = buf.readInt();
    RowType rowType;
    for (int i = 0; i < rowNum; i++) {
        rowType = RowType.valueOf(buf.readInt());
        ServerRow row = initRow(rowType);
        row.deserialize(buf);
        rows.put(row.getRowId(), row);
    }
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) RowType(com.tencent.angel.ml.matrix.RowType)

Example 72 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class WorkerPool method putPart.

private ByteBuf putPart(int seqId, int methodId, ByteBuf in) {
    PartitionKey partKey = new PartitionKey();
    partKey.deserialize(in);
    ByteBuf buf = ByteBufUtils.newByteBuf(8 + 4);
    buf.writeInt(seqId);
    buf.writeInt(methodId);
    try {
        // context.getMatrixStorageManager().update(partKey, in);
        Response resposne = new Response(ResponseType.SUCCESS);
    // resposne.encode(buf);
    // TODO:
    } catch (Exception x) {
        x.printStackTrace();
        Response resposne = new Response(ResponseType.SERVER_HANDLE_FATAL, x.getMessage());
    // resposne.encode(buf);
    // TODO:
    }
    return buf;
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) ByteBuf(io.netty.buffer.ByteBuf) ServiceException(com.google.protobuf.ServiceException)

Example 73 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class WorkerPool method getRowsSplit.

/**
 * Get a batch of row splits
 * @param seqId rpc request id
 * @param request rpc request
 * @return serialized rpc response contains row splits
 */
private ByteBuf getRowsSplit(int seqId, GetRowsSplitRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("get row request=" + request);
    }
    PartitionKey partKey = request.getPartKey();
    int clock = request.getClock();
    GetRowsSplitResponse response = new GetRowsSplitResponse();
    if (!isClockReady(partKey, clock)) {
        response.setResponseType(ResponseType.CLOCK_NOTREADY);
    } else {
        List<ServerRow> rows = new ArrayList<ServerRow>();
        List<Integer> rowIndexes = request.getRowIndexes();
        if (rowIndexes != null) {
            int size = rowIndexes.size();
            for (int i = 0; i < size; i++) {
                ServerRow row = context.getMatrixStorageManager().getRow(partKey.getMatrixId(), rowIndexes.get(i), partKey.getPartitionId());
                if (row != null) {
                    rows.add(row);
                }
            }
        }
        response.setResponseType(ResponseType.SUCCESS);
        response.setRowsSplit(rows);
    }
    ByteBuf buf = ByteBufUtils.newByteBuf(4 + response.bufferLen(), useDirectorBuffer);
    buf.writeInt(seqId);
    response.serialize(buf);
    return buf;
}
Also used : ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) ByteBuf(io.netty.buffer.ByteBuf)

Example 74 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class WorkerPool method getClocks.

/**
 * Get clocks for all matrices partition
 * @param seqId rpc request id
 * @param request rpc request
 * @return serialized rpc response contains clocks
 */
private ByteBuf getClocks(int seqId, GetClocksRequest request) {
    Map<PartitionKey, Integer> clocks = context.getClockVectorManager().getPartClocksFromCache();
    GetClocksResponse response = new GetClocksResponse(ResponseType.SUCCESS, null, clocks);
    ByteBuf buf = ByteBufUtils.newByteBuf(4 + response.bufferLen(), useDirectorBuffer);
    buf.writeInt(seqId);
    response.serialize(buf);
    return buf;
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) ByteBuf(io.netty.buffer.ByteBuf)

Example 75 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class WorkerPool method getPartition.

/**
 * Get matrix partition
 * @param seqId rpc request id
 * @param request rpc request
 * @return serialized rpc response contains whole partition
 */
private ByteBuf getPartition(int seqId, GetPartitionRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("get partition request=" + request);
    }
    PartitionKey partKey = request.getPartKey();
    int clock = request.getClock();
    long startTs = System.currentTimeMillis();
    GetPartitionResponse response = new GetPartitionResponse();
    if (!isClockReady(partKey, clock)) {
        response.setResponseType(ResponseType.CLOCK_NOTREADY);
    } else {
        ServerPartition partition = context.getMatrixStorageManager().getPart(partKey.getMatrixId(), partKey.getPartitionId());
        response.setResponseType(ResponseType.SUCCESS);
        response.setPartition(partition);
    }
    ByteBuf buf = ByteBufUtils.newByteBuf(4 + response.bufferLen(), useDirectorBuffer);
    buf.writeInt(seqId);
    response.serialize(buf);
    return buf;
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

PartitionKey (com.tencent.angel.PartitionKey)80 ArrayList (java.util.ArrayList)17 ByteBuf (io.netty.buffer.ByteBuf)12 Test (org.junit.Test)9 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)8 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)7 PartitionLocation (com.tencent.angel.ml.matrix.PartitionLocation)4 ServerRow (com.tencent.angel.ps.impl.matrix.ServerRow)4 ParameterServerId (com.tencent.angel.ps.ParameterServerId)3 RecoverPartKey (com.tencent.angel.ps.recovery.ha.RecoverPartKey)3 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)3 Map (java.util.Map)3 Location (com.tencent.angel.common.location.Location)2 TVector (com.tencent.angel.ml.math.TVector)2 RowType (com.tencent.angel.ml.matrix.RowType)2 PSLocation (com.tencent.angel.ml.matrix.transport.PSLocation)2 MatrixStorageManager (com.tencent.angel.ps.impl.MatrixStorageManager)2 ClockCache (com.tencent.angel.psagent.clock.ClockCache)2 Worker (com.tencent.angel.worker.Worker)2