Search in sources :

Example 1 with Result

use of org.honu.thrift.Result in project Honu by jboulon.

the class MessageSender method sendChunk.

protected void sendChunk(TChunk chunk) {
    boolean firstTryFailed = false;
    boolean hasBeenSent = false;
    int errorCount = 0;
    int tryLaterErrorCount = 0;
    Result result = null;
    do {
        try {
            Tracer t = Tracer.startNewTracer("honu.client.processChunk");
            try {
                if ((collector == null) || (tryLaterErrorCount >= 3)) {
                    tryLaterErrorCount = 0;
                    initConnection();
                }
                result = collector.process(chunk);
                if (t != null) {
                    t.stopAndLogTracer();
                }
                if (result.getResultCode() == ResultCode.TRY_LATER) {
                    Counter.increment("honu.client.tryLater");
                    Counter.increment("honu.client." + chunk.getApplication() + ".tryLater");
                    tryLaterErrorCount++;
                    // on a collector the switch
                    if (tryLaterErrorCount > 3) {
                        collector = null;
                        errorCount++;
                    } else {
                        randomSleep(5 * tryLaterErrorCount, true);
                    }
                } else {
                    Counter.increment("honu.client.chunkCount");
                    Counter.increment("honu.client.logCount", chunk.getLogEventsSize());
                    Counter.increment("honu.client." + chunk.getApplication() + ".chunkCount");
                    Counter.increment("honu.client." + chunk.getApplication() + ".logCount", chunk.getLogEventsSize());
                }
            } catch (Throwable e) {
                try {
                    log.warn("exception in sendChunk", e);
                    if (t != null) {
                        t.stopAndLogTracer();
                    }
                    Counter.increment("honu.client.exceptionCount");
                    exceptionCount++;
                    collector = null;
                    errorCount++;
                    randomSleep(300, false);
                } catch (Throwable eIgnored) {
                /* Ignore */
                }
            }
            if (errorCount >= CollectorRegistry.getInstance().getCollectorCount()) {
                if (firstTryFailed == true) {
                    randomSleep(30, true);
                    collector = null;
                    errorCount = 0;
                } else {
                    firstTryFailed = true;
                    randomSleep(15, true);
                    collector = null;
                    errorCount = 0;
                }
            }
            if (result != null && result.getResultCode() == ResultCode.OK && result.isSetMessage()) {
                hasBeenSent = true;
            }
            if (hasBeenSent == false && shutDownNow()) {
                System.err.println("Need to shutdown now --" + Thread.currentThread().getName() + " -- Data has not been sent over:" + chunk.toString());
                hasBeenSent = true;
            }
        } catch (Throwable e2) {
            logApp.warn("Error in sendChunk", e2);
        }
    } while (!hasBeenSent);
}
Also used : Tracer(org.honu.util.Tracer) Result(org.honu.thrift.Result)

Example 2 with Result

use of org.honu.thrift.Result in project Honu by jboulon.

the class ThriftCollectorLockFreeImpl method process.

public Result process(TChunk tChunk) throws TException {
    // Stop adding chunks if it's no running
    if (!isRunning) {
        Log.warn("Rejecting some incoming trafic!");
        Result result = new Result();
        result.setMessage("Shutting down");
        result.setResultCode(ResultCode.TRY_LATER);
        return result;
    }
    // If there's no log Events then return OK
    if (tChunk.getLogEventsSize() == 0) {
        Result result = new Result();
        result.setMessage("" + tChunk.getSeqId());
        result.setResultCode(ResultCode.OK);
        return result;
    }
    Tracer t = Tracer.startNewTracer("honu.server.processChunk");
    //this.counters.get(chunkCountField).incrementAndGet();
    ChunkBuilder cb = new ChunkBuilder();
    List<String> logEvents = tChunk.getLogEvents();
    for (String logEvent : logEvents) {
        cb.addRecord(logEvent.getBytes());
    }
    Chunk c = cb.getChunk();
    c.setApplication(tChunk.getApplication());
    c.setDataType(tChunk.getDataType());
    c.setSeqID(tChunk.getSeqId());
    c.setSource(tChunk.getSource());
    c.setTags(tChunk.getTags());
    if (isDebug) {
        System.out.println("\n\t ===============");
        System.out.println("tChunk.getApplication() :" + tChunk.getApplication());
        System.out.println("tChunk.getDataType() :" + tChunk.getDataType());
        System.out.println("tChunk.getSeqId() :" + tChunk.getSeqId());
        System.out.println("tChunk.getSource() :" + tChunk.getSource());
        System.out.println("tChunk.getStreamName() :" + tChunk.getStreamName());
        System.out.println("tChunk.getTags() :" + tChunk.getTags());
        System.out.println("c.getApplication() :" + c.getApplication());
        System.out.println("c.getDataType() :" + c.getDataType());
        System.out.println("c.getSeqID() :" + c.getSeqID());
        System.out.println("c.getSource() :" + c.getSource());
        System.out.println("c.getTags() :" + c.getTags());
        System.out.println("c.getData()" + new String(c.getData()));
    }
    boolean addResult = false;
    try {
        addResult = chunkQueue.offer(c, 2000, TimeUnit.MILLISECONDS);
    } catch (OutOfMemoryError ex) {
        ex.printStackTrace();
        DaemonWatcher.bailout(-1);
    } catch (Throwable e) {
        e.printStackTrace();
        addResult = false;
    }
    Result result = new Result();
    if (addResult) {
        try {
            Counter.increment("honu.server.chunkCount");
            Counter.increment("honu.server.logCount", logEvents.size());
            Counter.increment("honu.server." + tChunk.getApplication() + ".chunkCount");
            Counter.increment("honu.server." + tChunk.getApplication() + ".logCount", logEvents.size());
            (new Tracer("honu.server.chunkSize [messages, not msec]", logEvents.size())).logTracer();
            (new Tracer("honu.server." + tChunk.getApplication() + ".chunkSize [messages, not msec]", logEvents.size())).logTracer();
        } catch (Exception ignored) {
        }
        result.setMessage("" + tChunk.getSeqId());
        result.setResultCode(ResultCode.OK);
    } else {
        try {
            Counter.increment("honu.server.tryLater");
            Counter.increment("honu.server." + tChunk.getApplication() + ".tryLater");
        } catch (Exception ignored) {
        }
        result.setMessage("" + tChunk.getSeqId());
        result.setResultCode(ResultCode.TRY_LATER);
    }
    if (t != null) {
        t.stopAndLogTracer();
    }
    return result;
}
Also used : Tracer(org.honu.util.Tracer) ChunkBuilder(org.apache.hadoop.chukwa.ChunkBuilder) TChunk(org.honu.thrift.TChunk) Chunk(org.apache.hadoop.chukwa.Chunk) TException(org.apache.thrift.TException) Result(org.honu.thrift.Result)

Aggregations

Result (org.honu.thrift.Result)2 Tracer (org.honu.util.Tracer)2 Chunk (org.apache.hadoop.chukwa.Chunk)1 ChunkBuilder (org.apache.hadoop.chukwa.ChunkBuilder)1 TException (org.apache.thrift.TException)1 TChunk (org.honu.thrift.TChunk)1