Example usage for org.apache.hadoop.util StringUtils formatTimeDiff

List of usage examples for org.apache.hadoop.util StringUtils formatTimeDiff

Introduction

In this page you can find the example usage for org.apache.hadoop.util StringUtils formatTimeDiff.

Prototype

public static String formatTimeDiff(long finishTime, long startTime) 

Source Link

Document

Given a finish and start time in long milliseconds, returns a String in the format Xhrs, Ymins, Z sec, for the time difference between two times.

Usage

From source file:com.alibaba.wasp.fserver.SplitRequest.java

License:Apache License

@Override
public void run() {
    if (this.server.isStopping() || this.server.isStopped()) {
        LOG.debug("Skipping split because server is stopping=" + this.server.isStopping() + " or stopped="
                + this.server.isStopped());
        return;//from w ww .  j  a  v a2 s.  c  o m
    }
    final long startTime = System.currentTimeMillis();
    try {
        SplitTransaction st = new SplitTransaction(parent, midKey, server.getConfiguration());
        // If prepare does not return true, for some reason -- logged inside in
        // the prepare call -- we are not ready to split just now. Just return.
        if (!st.prepare())
            return;
        try {
            st.execute(this.server, this.server);
            // this.server.getMetrics().incrementSplitSuccessTime(System.currentTimeMillis()
            // - startTime);
        } catch (Exception e) {
            if (this.server.isStopping() || this.server.isStopped()) {
                LOG.info("Skip rollback/cleanup of failed split of " + parent.getEntityGroupNameAsString()
                        + " because server is stopping=" + this.server.isStopping() + " or stopped="
                        + this.server.isStopped(), e);
                return;
            }
            try {
                LOG.info("Running rollback/cleanup of failed split of " + parent.getEntityGroupNameAsString()
                        + "; " + e.getMessage(), e);
                if (st.rollback(this.server, this.server)) {
                    LOG.info("Successful rollback of failed split of " + parent.getEntityGroupNameAsString());
                    // this.server.getMetrics().incrementSplitFailureTime(System.currentTimeMillis()
                    // - startTime);
                } else {
                    this.server.abort("Abort; we got an error after point-of-no-return");
                }
            } catch (RuntimeException ee) {
                String msg = "Failed rollback of failed split of " + parent.getEntityGroupNameAsString()
                        + " -- aborting server";
                // If failed rollback, kill this server to avoid having a hole in table.
                LOG.info(msg, ee);
                this.server.abort(msg);
            }
            return;
        }
        LOG.info("EntityGroup split, FMETA updated, and report to master. Parent="
                + parent.getEntityGroupInfo().getEntityGroupNameAsString() + ", new entityGroups: "
                + st.getFirstDaughter().getEntityGroupNameAsString() + ", "
                + st.getSecondDaughter().getEntityGroupNameAsString() + ". Split took "
                + StringUtils.formatTimeDiff(System.currentTimeMillis(), startTime));
    } catch (IOException ex) {
        LOG.error("Split failed " + this, RemoteExceptionHandler.checkIOException(ex));
        // this.server.getMetrics().incrementSplitFailureTime(System.currentTimeMillis()
        // - startTime);
        server.checkStorageSystem();
    }
}