Search in sources :

Example 1 with CommitEvent

use of com.tencent.angel.master.ps.CommitEvent in project angel by Tencent.

the class MasterService method save.

/**
 * Save model to files.
 *
 * @param controller rpc controller of protobuf
 * @param request save request that contains all matrices need save
 * @throws ServiceException some matrices do not exist or save operation is interrupted
 */
@SuppressWarnings("unchecked")
@Override
public SaveResponse save(RpcController controller, SaveRequest request) throws ServiceException {
    List<String> needSaveMatrices = request.getMatrixNamesList();
    List<Integer> matrixIds = new ArrayList<Integer>(needSaveMatrices.size());
    AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager();
    int size = needSaveMatrices.size();
    for (int i = 0; i < size; i++) {
        MatrixMeta matrixMeta = matrixMetaManager.getMatrix(needSaveMatrices.get(i));
        if (matrixMeta == null) {
            throw new ServiceException("matrix " + needSaveMatrices.get(i) + " does not exist");
        }
        LOG.info("Need save matrix " + matrixMeta.getName());
        matrixIds.add(matrixMeta.getId());
    }
    context.getEventHandler().handle(new CommitEvent(matrixIds));
    context.getEventHandler().handle(new AppEvent(AppEventType.COMMIT));
    return SaveResponse.newBuilder().build();
}
Also used : AppEvent(com.tencent.angel.master.app.AppEvent) ServiceException(com.google.protobuf.ServiceException) AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) CommitEvent(com.tencent.angel.master.ps.CommitEvent)

Aggregations

ServiceException (com.google.protobuf.ServiceException)1 AppEvent (com.tencent.angel.master.app.AppEvent)1 AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)1 CommitEvent (com.tencent.angel.master.ps.CommitEvent)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1