Sends an incremental block report to the Namenode.

@param startTime
the time when we started processing the last heartbeat
@throws Exception
if there is an error in reporting blocks to the NameNode
321883
private void sendIncrementalBlockReport(long startTime) throws Exception {

    // check if there are newly received blocks
    Block[] receivedAndDeletedBlockArray = null;
    int numBlocksReceivedAndDeleted = 0;
    int currentPendingRequests = 0;

    synchronized (receivedAndDeletedBlockList) {
      
      // construct the ACKs array
      lastDeletedReport = startTime;
      numBlocksReceivedAndDeleted = receivedAndDeletedBlockList.size();
      if (numBlocksReceivedAndDeleted > 0) {
        receivedAndDeletedBlockArray = receivedAndDeletedBlockList
            .toArray(new Block[numBlocksReceivedAndDeleted]);
        receivedAndDeletedBlockList.clear();
        currentPendingRequests = pendingReceivedRequests;
        pendingReceivedRequests = 0;
      }
    }
    // process received + deleted
    // if exception is thrown, add all blocks to the retry list
    if (receivedAndDeletedBlockArray != null) {            
      long[] failed = null;
      try {
        IncrementalBlockReport ibr = new IncrementalBlockReport(receivedAndDeletedBlockArray);

        long rpcStartTime = 0;
        if (LOG.isDebugEnabled()) {
          rpcStartTime = System.nanoTime();
          LOG.debug("sending blockReceivedAndDeletedNew "
                    + receivedAndDeletedBlockArray.length +
                    " blocks to " + namenodeAddress);
        }
        failed = avatarnode.blockReceivedAndDeletedNew(nsRegistration, ibr);
        if (LOG.isDebugEnabled()) {
          LOG.debug("finished blockReceivedAndDeletedNew " +
                    "to " + namenodeAddress +
                    " time: " + (System.nanoTime() - rpcStartTime) + " ns");
        }

        boolean isPrimaryCached = isPrimaryServiceCached();
        // if we talk to primary failed must be null
        // if we talk to standby failed shouldn't be null
        if(isPrimaryCached && failed!=null){
          //this should never happen
          //the primary can't switch to standby
          throw new IOException("Primary started acting as standby");
        } else if (!isPrimaryCached && failed == null) {
          String msg = "Received null response from standby for incremental"
              + " block report. ";
          if (clearPrimaryCommandProcessed) {
            LOG.info(msg + "Failover is in progress"
                + " - will not clear primary again");
          } else {
            LOG.info(msg + "Standby is acting as primary. Clearing primary");
            // failover - we need to refresh our knowledge
            this.clearPrimary();
          }
        }
      } catch (Exception e) {
        processFailedBlocks(
            receivedAndDeletedBlockArray, currentPendingRequests);
        throw e;
      }
      if(failed != null && failed.length != 0){
        processFailedReceivedDeleted(failed, receivedAndDeletedBlockArray);
      }
    }
  }
808773
public void blocksBeingWrittenReport(DatanodeRegistration nodeReg,
      BlockReport blocks) throws IOException {
    verifyRequest(nodeReg);
    long[] blocksAsLong = blocks.getBlockReportInLongs();
    BlockListAsLongs blist = new BlockListAsLongs(blocksAsLong);
    boolean processed = namesystem.processBlocksBeingWrittenReport(nodeReg, blist);

    String message = "*BLOCK* NameNode.blocksBeingWrittenReport: "
        +"from "+nodeReg.getName()+" "+blist.getNumberOfBlocks() +" blocks";
    if (!processed) {
      message += " was discarded.";
    }
    stateChangeLog.info(message);
  }
970057
public DatanodeCommand[] sendHeartbeat(DatanodeRegistration nodeReg,
                                       long capacity,
                                       long dfsUsed,
                                       long remaining,
                                       long namespaceUsed,
                                       int xmitsInProgress,
                                       int xceiverCount) throws IOException {
    verifyRequest(nodeReg);
    myMetrics.numHeartbeat.inc();
    return namesystem.handleHeartbeat(nodeReg, capacity, dfsUsed, remaining, namespaceUsed,
        xceiverCount, xmitsInProgress);
  }
731565
public void heartbeatNode (String nodeName)
    {
        updatePartial(NodeRecord.getKey(nodeName),
                      NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis()));
    }
105452
private void addRuntimeNameProperty() throws RepositoryException {
		
		String statement = 
				"/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + 
				"//*[@className='ro.nextreports.server.domain.Report']" + 
				"//*[fn:name()='parametersValues']";
		  
		QueryResult queryResult = getTemplate().query(statement);

		NodeIterator nodes = queryResult.getNodes();
		
		LOG.info("RuntimeHistory : Found " + nodes.getSize() + " parameterValues nodes");
		while (nodes.hasNext()) {			
			Node node = nodes.nextNode();
			NodeIterator childrenIt = node.getNodes();
			while (childrenIt.hasNext()) {
				Node child = childrenIt.nextNode();				
				child.setProperty("runtimeName", child.getName());
			}
		}	
		getTemplate().save();		
	}
1301644
@Override
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
        long initialDelay = startTime.getTime() - System.currentTimeMillis();
        try {
            return this.scheduledExecutor.scheduleAtFixedRate(decorateTask(task, true), initialDelay, period,
                    TimeUnit.MILLISECONDS);
        } catch (RejectedExecutionException ex) {
            throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task,
                    ex);
        }
    }
957724
@Override
  public void start() throws Exception {
    SynchronousQueue<Runnable> synchronousQueue = new SynchronousQueue<>();
    mThreadPool =
        new ThreadPoolExecutor(mMinNumberOfThreads, mMaxNumberOfThreads,
            THREAD_KEEP_ALIVE_TIME_MS, TimeUnit.MILLISECONDS, synchronousQueue);
    mStopped = false;
    try {
      mServerSocket = new ServerSocket(mPort);
    } catch (IOException e) {
      throw new RuntimeException("Failed to bind to port {}.", e);
    }
    while (!mStopped) {
      Socket client;
      try {
        client = mServerSocket.accept();
      } catch (IOException e) {
        if (mServerSocket.isClosed()) {
          break;
        } else {
          continue;
        }
      }
      String clientAddress = client.getInetAddress().getHostAddress();
      LOG.info("Starting thread to read logs from {}", clientAddress);
      AlluxioLog4jSocketNode clientSocketNode = new AlluxioLog4jSocketNode(mBaseLogsDir, client);
      synchronized (mClientSockets) {
        mClientSockets.add(client);
      }
      try {
        CompletableFuture.runAsync(clientSocketNode, mThreadPool)
            .whenComplete((r, e) -> {
              synchronized (mClientSockets) {
                mClientSockets.remove(client);
              }
            });
      } catch (RejectedExecutionException e) {
        // Alluxio log clients (master, secondary master, proxy and workers) establish
        // long-living connections with the log server. Therefore, if the log server cannot
        // find a thread to service a log client, it is very likely due to low number of
        // worker threads. If retry fails, then it makes sense just to let system throw
        // an exception. The system admin should increase the thread pool size.
        String errorMessage = String.format(
            "Log server cannot find a worker thread to service log requests from %s. Increase"
                + " the number of worker threads in the thread pool by configuring"
                + " alluxio.logserver.threads.max in alluxio-site.properties. Current value"
                + " is %d.", clientAddress, mMaxNumberOfThreads);
        throw new RuntimeException(errorMessage, e);
      }
    }
  }
1210414
private void startAppendTimer() {
    // Set a timer that will be used to periodically synchronize with other nodes
    // in the cluster. This timer acts as a heartbeat to ensure this node remains
    // the leader.
    log.trace("Starting append timer");
    appendTimer = raft.getThreadContext().schedule(Duration.ZERO, raft.getHeartbeatInterval(), this::appendMembers);
  }
360158
public void writeStartDocument() throws XMLStreamException {
		this.init();
		try {
			encoder.encodeStartDocument();
		} catch (Exception e) {
			throw new XMLStreamException(e.getLocalizedMessage(), e);
		}
	}
1305685
static int run(List<InetSocketAddress> namenodes,
      Configuration conf) throws IOException, InterruptedException {
    final long sleepms = 1000L * 2 * conf.getLong("dfs.heartbeat.interval", 3);
    LOG.info("namenodes = " + namenodes);
    Formatter formatter = new Formatter(System.out);
    System.out.println("Time Stamp               Iteration#  Bytes Already Moved  Bytes Left To Move  Bytes Being Moved  Iterations Left  Seconds Left");

    final List<Balancer> balancers
        = new ArrayList<Balancer>(namenodes.size());
    boolean failNN = false;
    try {
      for(InetSocketAddress isa : namenodes) {
        try{
          Balancer b = Balancer.getBalancerInstance(conf);
          b.init(isa);
          balancers.add(b);
        } catch (IOException e) {
          e.printStackTrace();
          LOG.error("Cannot connect to namenode: " + isa);
          failNN = true;
        }
      }

      boolean done = false;
      for(int iterations = 0; !done && balancers.size() > 0; iterations++) {
        done = true;
        Collections.shuffle(balancers);
        Iterator<Balancer> iter = balancers.iterator();
        while (iter.hasNext()) {
          Balancer b = iter.next();
          b.resetData();
          final int r = b.run(iterations, formatter);
          if (r == IN_PROGRESS) {
            done = false;
          } else if (r != SUCCESS) {
            //Remove this balancer
            b.close();
            LOG.info("Namenode " + b.namenodeAddress + " balancing exits...");
            iter.remove();
            continue;
          }
        }

        if (!done) {
          Thread.sleep(sleepms);
        }
      }
    } finally {
      for(Balancer b : balancers) {
        b.close();
      }
    }
    if (failNN) {
      LOG.warn("Could not initialize all balancers");
      return NOT_ALL_BALANCED;
    }
    return SUCCESS;
  }
215042
private void writeDuration(long beginTime) throws XMLStreamException {
        xmlStreamWriter.writeStartElement("duration");
        xmlStreamWriter.writeCharacters(Long.toString(System.currentTimeMillis() - beginTime));
        xmlStreamWriter.writeEndElement(); // duration
    }
628571
public void finalizeAndNotifyNamenode(int namespaceId, Block blk)
      throws IOException {
    this.getFSDataset().finalizeBlock(namespaceId, blk);
    this.notifyNamenodeReceivedBlock(namespaceId, blk, null);
  }
653601
@Override
  public void onJobCompletion(JobContext jobContext)
      throws Exception {
    super.onJobCompletion(jobContext);
    long startTime = jobContext.getJobState().getPropAsLong(JOB_START_TIME);
    jobLauncherMetrics.totalJobsCompleted.incrementAndGet();
    Instrumented.updateTimer(Optional.of(jobLauncherMetrics.timeForCompletedJobs), System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
    if (jobContext.getJobState().getState() == JobState.RunningState.FAILED) {
      jobLauncherMetrics.totalJobsFailed.incrementAndGet();
      Instrumented.updateTimer(Optional.of(jobLauncherMetrics.timeForFailedJobs), System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
    } else {
      jobLauncherMetrics.totalJobsCommitted.incrementAndGet();
      Instrumented.updateTimer(Optional.of(jobLauncherMetrics.timeForCommittedJobs), System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
    }
  }
823539
@Override
    public void start() throws Exception {

        String thisMethodName = CLASS_NAME + ".start()";

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            // SibTr.entry(tc, thisMethodName);
        }

        Enumeration meEnum = _messagingEngines.elements();

        while (meEnum.hasMoreElements()) {
            Object o = meEnum.nextElement();
            Object c = ((MessagingEngine) o).getRuntime();
            try {

                ((BaseMessagingEngineImpl) c).startConditional();
                Dictionary<String, Object> properties = new Hashtable<String, Object>();
                properties.put("service.vendor", "IBM");
                properties.put("jmx.objectname", "WebSphere:feature=wasJmsServer,type=MessagingEngine,name=" + ((BaseMessagingEngineImpl) c)._name);
                mbeanServiceReg = (ServiceRegistration<MessagingEngineMBean>) this.bContext.registerService(MessagingEngineMBean.class.getName(), c, properties);

            } catch (Exception w) {
                // Not serious enough to warrant server stop.
                FFDCFilter.processException(w, thisMethodName, "1:725:1.108",
                                            this);
                SibTr.exception(tc, w);
                SibTr.error(tc, "INTERNAL_ERROR_SIAS0003", w);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            SibTr.exit(tc, thisMethodName);
        }
    }
910653
public void start() throws Exception {
        installShutdownHook();

        System.out.println();
        System.out.printf("Starting benchmark(s) [msgs=%d, msgsize=%d, pubs=%d, subs=%d]\n", numMsgs,
                size, numPubs, numSubs);
        System.out.printf("Current memory usage is %s / %s / %s free/total/max\n", 
                            Utils.humanBytes(Runtime.getRuntime().freeMemory()),
                            Utils.humanBytes(Runtime.getRuntime().totalMemory()),
                            Utils.humanBytes(Runtime.getRuntime().maxMemory()));
        System.out.println("Use ctrl-C to cancel.");
        System.out.println();

        if (this.numPubs > 0) {
            runTest("Pub Only", this.numPubs, 0);
            runTest("Pub/Sub", this.numPubs, this.numSubs);
        } else {
            runTest("Sub", this.numPubs, this.numSubs);
        }

        System.out.println();
        System.out.printf("Final memory usage is %s / %s / %s free/total/max\n", 
                            Utils.humanBytes(Runtime.getRuntime().freeMemory()),
                            Utils.humanBytes(Runtime.getRuntime().totalMemory()),
                            Utils.humanBytes(Runtime.getRuntime().maxMemory()));
        Runtime.getRuntime().removeShutdownHook(shutdownHook);
    }
1291411
private void doWriteStartElement(String localName)
        throws XMLStreamException
    {
        mAnyOutput = true;
        // Need to finish an open start element?
        if (mStartElementOpen) {
            closeStartElement(mEmptyElement);
        } else if (mState == STATE_PROLOG) {
            // 20-Dec-2005, TSa: Does this match DOCTYPE declaration?
            verifyRootElement(localName, null);
        } else if (mState == STATE_EPILOG) {
            if (mCheckStructure) {
                reportNwfStructure(ErrorConsts.WERR_PROLOG_SECOND_ROOT, localName);
            }
            // Outputting fragment? Better reset to tree, then...
            mState = STATE_TREE;
        }

        /* Note: need not check for CONTENT_ALLOW_NONE here, since the
         * validator should handle this particular case...
         */
        /*if (mVldContent == XMLValidator.CONTENT_ALLOW_NONE) { // EMPTY content
            reportInvalidContent(START_ELEMENT);
            }*/
        if (mValidator != null) {
            mValidator.validateElementStart(localName, XmlConsts.ELEM_NO_NS_URI, XmlConsts.ELEM_NO_PREFIX);
        }       

        mStartElementOpen = true;
        mElements.addString(localName);
        try {
            mWriter.writeStartTagStart(localName);
        } catch (IOException ioe) {
            throwFromIOE(ioe);
        }
    }
1341451
public void report(long arrivalTime) {
    checkArgument(arrivalTime >= 0, "arrivalTime must not be negative");
    long latestHeartbeat = history.latestHeartbeatTime();
    history.samples().addValue(arrivalTime - latestHeartbeat);
    history.setLatestHeartbeatTime(arrivalTime);
  }