List of usage examples for org.apache.hadoop.mapreduce TaskAttemptContext getCounter
public Counter getCounter(Enum<?> counterName);
counterName
. From source file:com.marklogic.contentpump.DatabaseContentWriter.java
License:Apache License
@Override public void close(TaskAttemptContext context) throws IOException, InterruptedException { if (batchSize > 1) { int len, sid; if (countBased) { len = 1;// w w w .ja v a 2s . c om sid = sfId; } else { len = fastLoad ? forestIds.length : 1; sid = 0; } if (isCopyProps) { for (int i = 0; i < len; i++, sid++) { if (counts[i] > 0) { Content[] remainder = new Content[counts[i]]; System.arraycopy(forestContents[i], 0, remainder, 0, counts[i]); if (sessions[sid] == null) { String forestId = forestIds[i]; sessions[sid] = getSession(forestId); } insertBatch(remainder, sid); stmtCounts[sid]++; if (!isCopyProps) { continue; } for (int j = 0; j < counts[i]; j++) { DocumentMetadata m = metadatas[i][j].getMeta(); String u = metadatas[i][j].getUri(); if (m != null && m.getProperties() != null) { setDocumentProperties(u, m.getProperties(), null, null, null, sessions[sid]); stmtCounts[sid]++; } } } } } } for (int i = 0; i < sessions.length; i++) { if (sessions[i] != null) { if (stmtCounts[i] > 0 && needCommit) { try { sessions[i].commit(); succeeded += commitUris[i].size(); } catch (RequestException e) { // log error and continue on RequestServerException LOG.error("Error commiting transaction", e); failed += commitUris[i].size(); for (DocumentURI failedUri : commitUris[i]) { LOG.warn("Failed document " + failedUri); } commitUris[i].clear(); } finally { sessions[i].close(); } } else { sessions[i].close(); } } } context.getCounter(MarkLogicCounter.OUTPUT_RECORDS_COMMITTED).increment(succeeded); context.getCounter(MarkLogicCounter.OUTPUT_RECORDS_FAILED).increment(failed); }
From source file:com.marklogic.mapreduce.ContentWriter.java
License:Apache License
@Override public void close(TaskAttemptContext context) throws IOException, InterruptedException { if (batchSize > 1) { int len, sid; if (countBased) { len = 1;// ww w. ja va2 s . com sid = sfId; } else { len = fastLoad ? forestIds.length : 1; sid = 0; } for (int i = 0; i < len; i++, sid++) { if (counts[i] > 0) { Content[] remainder = new Content[counts[i]]; System.arraycopy(forestContents[i], 0, remainder, 0, counts[i]); if (sessions[sid] == null) { String forestId = forestIds[sid]; sessions[sid] = getSession(forestId); } insertBatch(remainder, sid); stmtCounts[sid]++; } } } for (int i = 0; i < sessions.length; i++) { if (sessions[i] != null) { if (stmtCounts[i] > 0 && needCommit) { try { sessions[i].commit(); succeeded += commitUris[i].size(); } catch (RequestServerException e) { // log error and continue on RequestServerException LOG.error("Error commiting transaction", e); failed += commitUris[i].size(); for (DocumentURI failedUri : commitUris[i]) { LOG.warn("Failed document " + failedUri); } commitUris[i].clear(); } catch (RequestException e) { if (sessions[i] != null) { sessions[i].close(); } if (countBased) { rollbackCount(i); } failed += commitUris[i].size(); commitUris[i].clear(); throw new IOException(e); } finally { sessions[i].close(); } } else { sessions[i].close(); } } } if (is != null) { is.close(); if (is instanceof ZipEntryInputStream) { ((ZipEntryInputStream) is).closeZipInputStream(); } } Counter committedCounter = context.getCounter(MarkLogicCounter.OUTPUT_RECORDS_COMMITTED); synchronized (committedCounter) { committedCounter.increment(succeeded); } Counter failedCounter = context.getCounter(MarkLogicCounter.OUTPUT_RECORDS_FAILED); synchronized (failedCounter) { committedCounter.increment(failed); } }
From source file:org.apache.rya.reasoning.mr.AbstractReasoningTool.java
License:Apache License
/** * Increment the schema or instance triple counter, as appropriate. *///from ww w.j ava2 s. c o m protected static void countInput(boolean schema, TaskAttemptContext context) { if (schema) { context.getCounter(COUNTERS.TBOX).increment(1); } else { context.getCounter(COUNTERS.ABOX).increment(1); } }
From source file:simsql.runtime.OutputFileSerializer.java
License:Apache License
public synchronized void close(TaskAttemptContext context) throws IOException { if (writeToMe != null) writeToMe.close();//from ww w . j av a 2s .c o m // add up the number of bytes written to our special counter... context.getCounter(Counters.BYTES_WRITTEN).increment(totalBytesWritten); }