Search in sources :

Example 1 with GetRowFunc

use of com.tencent.angel.ml.matrix.psf.get.single.GetRowFunc in project angel by Tencent.

the class ConsistencyController method getRow.

/**
 * Get row from storage/cache or pss.
 *
 * @param taskContext task context
 * @param matrixId matrix id
 * @param rowIndex row index
 * @return TVector matrix row
 * @throws Exception
 */
public TVector getRow(TaskContext taskContext, int matrixId, int rowIndex) throws Exception {
    int staleness = getStaleness(matrixId);
    if (staleness >= 0) {
        // Get row from cache.
        TVector row = PSAgentContext.get().getMatrixStorageManager().getRow(matrixId, rowIndex);
        // if row clock is satisfy ssp staleness limit, just return.
        if (row != null && (taskContext.getPSMatrixClock(matrixId) <= row.getClock()) && (taskContext.getMatrixClock(matrixId) - row.getClock() <= staleness)) {
            LOG.debug("task " + taskContext.getIndex() + " matrix " + matrixId + " clock " + taskContext.getMatrixClock(matrixId) + ", row clock " + row.getClock() + ", staleness " + staleness + ", just get from global storage");
            return cloneRow(matrixId, rowIndex, row, taskContext);
        }
        // Get row from ps.
        row = PSAgentContext.get().getMatrixClientAdapter().getRow(matrixId, rowIndex, taskContext.getMatrixClock(matrixId) - staleness);
        return cloneRow(matrixId, rowIndex, row, taskContext);
    } else {
        // For ASYNC mode, just get from pss.
        GetRowFunc func = new GetRowFunc(new GetRowParam(matrixId, rowIndex));
        GetRowResult result = ((GetRowResult) PSAgentContext.get().getMatrixClientAdapter().get(func));
        if (result.getResponseType() == ResponseType.FAILED) {
            throw new IOException("get row from ps failed.");
        } else {
            return result.getRow();
        }
    }
}
Also used : GetRowFunc(com.tencent.angel.ml.matrix.psf.get.single.GetRowFunc) GetRowParam(com.tencent.angel.ml.matrix.psf.get.single.GetRowParam) IOException(java.io.IOException) TVector(com.tencent.angel.ml.math.TVector) GetRowResult(com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)

Aggregations

TVector (com.tencent.angel.ml.math.TVector)1 GetRowFunc (com.tencent.angel.ml.matrix.psf.get.single.GetRowFunc)1 GetRowParam (com.tencent.angel.ml.matrix.psf.get.single.GetRowParam)1 GetRowResult (com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)1 IOException (java.io.IOException)1