Update replication metrics

@param work record for all scheduled replication
338724
private void updateReplicationMetrics(List<ReplicationWork> work) {
    for(ReplicationWork rw : work){
      DatanodeDescriptor[] targets = rw.targets;
      if (targets == null) continue;
      for (DatanodeDescriptor target : targets) {
        if (clusterMap.isOnSameRack(rw.srcNode, target)) {
          myFSMetrics.numLocalRackReplications.inc();
        } else {
          myFSMetrics.numAcrossRackReplications.inc();
        }
      }
    }
  }
632346
protected void update(CmsPublishJobInfoBean publishJob) {

        if (OpenCms.getMemoryMonitor().requiresPersistency()) {
            CmsDbContext dbc = m_publishEngine.getDbContext(null);
            try {
                m_publishEngine.getDriverManager().writePublishJob(dbc, publishJob);
            } catch (CmsException e) {
                dbc.rollback();
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            } finally {
                dbc.clear();
            }
        }
    }
1223396
public Metric updateAsync() throws ExecutionException, InterruptedException {
    // [START updateAsync]
    Future<Metric> future =
        metric.toBuilder().setDescription("A more detailed description").build().updateAsync();
    // ...
    Metric updatedMetric = future.get();
    // [END updateAsync]
    return updatedMetric;
  }
914068
public void setReplicationJobList(java.util.Collection<ReplicationJob> replicationJobList) {
        if (replicationJobList == null) {
            this.replicationJobList = null;
            return;
        }

        this.replicationJobList = new java.util.ArrayList<ReplicationJob>(replicationJobList);
    }
869292
@Override
    public void changed(ChangeEvent event) {
        // forget cached IDs (Should be executed in workExecutor)
        final long lastSeqPushed = (isPull() || replicationInternal.lastSequence == null) ? -1L :
                Long.valueOf(replicationInternal.lastSequence);
        if (lastSeqPushed >= 0 && lastSeqPushed != _lastSequencePushed) {
            db.runAsync(new AsyncTask() {
                @Override
                public void run(Database database) {
                    synchronized (_lockPendingDocIDs) {
                        _lastSequencePushed = lastSeqPushed;
                        _pendingDocIDs = null;
                    }
                }
            });
        }

        for (ChangeListener changeListener : changeListeners) {
            try {
                changeListener.changed(event);
            } catch (Exception e) {
                Log.e(Log.TAG_SYNC, "Exception calling changeListener.changed", e);
            }
        }
    }
683725
def update_node(self, job_record):
        
        if job_record.process_name not in self.process_hierarchy:
            raise ValueError('unable to update the node due to unknown process: {0}'.format(job_record.process_name))

        time_qualifier = self.process_hierarchy[job_record.process_name].process_entry.time_qualifier
        node = self._get_node(time_qualifier, job_record.timeperiod)
        node.job_record = job_record
140323
def update_stats(job_stats)
      s = @stats.stats
      current_speed = job_stats.stats[:current_speed] *
                      @stats.penalty(@threads)

      s[:resolution][:completed_records] +=
        job_stats.stats[:resolution][:completed_records]
      @stats.update_eta(current_speed)
      s[:resolution][:time_span] = Time.now - s[:resolution][:start_time]
      s[:matches][7] += job_stats.stats[:matches][7]
    end
1347546
@Override
  public void doUpdates(MetricsContext unused) {
    synchronized (this) {
      for (MetricsBase m : registry.getMetricsList()) {
        m.pushMetric(metricsRecord);
      }
    }
    metricsRecord.update();
  }
1104424
private void updateLocalKeyLoadStatus(Throwable t) {
        Operation op = new KeyLoadStatusOperation(mapName, t);
        // This updates the local record store on the partition thread.
        // If invoked by the SENDER_BACKUP however it's the replica index has to be set to 1, otherwise
        // it will be a remote call to the SENDER who is the owner of the given partitionId.
        if (hasBackup && role.is(Role.SENDER_BACKUP)) {
            opService.createInvocationBuilder(SERVICE_NAME, op, partitionId).setReplicaIndex(1).invoke();
        } else {
            opService.createInvocationBuilder(SERVICE_NAME, op, partitionId).invoke();
        }
    }
106932
public void update( Key job_key ) { 
    Log.debug(Log.Tag.Sys.LOCKS,"update write-locked "+_key+" by job "+job_key);
    new Update(job_key).invoke(_key); 
  }
650665
private synchronized void updateRecordsWrittenMeter() {
    if (this.recordsWrittenMeter.isPresent()) {
      this.recordsWrittenMeter.get().mark(recordsWritten() - this.recordsWrittenMeter.get().getCount());
    }
  }
722016
public void setReplicationTaskAssessmentResults(java.util.Collection<ReplicationTaskAssessmentResult> replicationTaskAssessmentResults) {
        if (replicationTaskAssessmentResults == null) {
            this.replicationTaskAssessmentResults = null;
            return;
        }

        this.replicationTaskAssessmentResults = new java.util.ArrayList<ReplicationTaskAssessmentResult>(replicationTaskAssessmentResults);
    }
136700
private void generateWork() {
        List<DataSource> tables = db().getAllDataSources();
        long now = System.currentTimeMillis();
        List<List<StatusTrail>> stPerDataSource = new ArrayList<>();
        for (DataSource ds:tables) {
            if (ds.getStatus() == null) {
                log.error("DataSource {}'s status is null", ds);
                continue;
            }
            if (JobStatus.valueOf(ds.getStatus()) == JobStatus.done) {                
                continue;
            }
            long currentSpinOffTime = ds.getSpinFromTime();            
            //If startTime = spinOffTime = 00 hr. If now = getTaskAttemptDelay() + 03 hr, and job is hourly job then
            // The following will materialize 00, 01, 02 , 03 adds them to StatusTrail, updates the spinnOff Time to 03.
            // NOTE: All the above times should be within endTime.
            while (now > (currentSpinOffTime + getTaskAttemptDelayInMillis()) && currentSpinOffTime < ds.getEndTime()) {                                
                StatusTrail st = new StatusTrail().setNominalTime(currentSpinOffTime).
                        setAttemptsDone(0).
                        setDataSourceId(ds.getId()).
                        setGivenUp(0).
                        setStatus(JobStatus.not_done);
                db().addStatusTrail(st);
                currentSpinOffTime += JobFreq.valueOf(ds.getFrequency()).inMillis();
                log.info("Generated work : {}", st);
            }
            if (currentSpinOffTime > ds.getEndTime()) {
                ds.setStatus(JobStatus.done);
            }
            stPerDataSource.add(db().getIncompleteTasks(ds));
            //Update the spinOff Time to point to time from which next set of materialization will happen.
            db().updateDataSource(ds.setSpinFromTime(currentSpinOffTime));
        }
        newWorkQueue.clearAndMergeKLists(stPerDataSource);
    }
801471
private void schedulePeriodicWorks() {
        // JMX stats broadcast
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                // A null here was causing a steady stream of annoying but apparently inconsequential
                // NPEs during a debug session of an unrelated unit test.
                if (m_statsManager != null) {
                    m_statsManager.sendNotification();
                }
            }
        }, 0, StatsManager.POLL_INTERVAL, TimeUnit.MILLISECONDS));

        // clear login count
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                ScheduledExecutorService es = VoltDB.instance().getSES(false);
                if (es != null && !es.isShutdown()) {
                    es.submit(new Runnable() {
                        @Override
                        public void run()
                        {
                            long timestamp = System.currentTimeMillis();
                            m_flc.checkCounter(timestamp);
                        }
                    });
                }
            }
        }, 0, 10, TimeUnit.SECONDS));

        // small stats samples
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                SystemStatsCollector.asyncSampleSystemNow(false, false);
            }
        }, 0, 5, TimeUnit.SECONDS));

        // medium stats samples
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                SystemStatsCollector.asyncSampleSystemNow(true, false);
            }
        }, 0, 1, TimeUnit.MINUTES));

        // large stats samples
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                SystemStatsCollector.asyncSampleSystemNow(true, true);
            }
        }, 0, 6, TimeUnit.MINUTES));

        // export stream master check
        m_periodicWorks.add(scheduleWork(new Runnable() {
            @Override
            public void run() {
                checkExportStreamMastership();
            }
        }, 0, 1, TimeUnit.MINUTES));

        // other enterprise setup
        EnterpriseMaintenance em = EnterpriseMaintenance.get();
        if (em != null) { em.setupMaintenaceTasks(); }

        GCInspector.instance.start(m_periodicPriorityWorkThread, m_gcStats);
    }
1097041
public void updateJobStatus(final JobIdentifier jobIdentifier, final JobState jobState) throws Exception {
        // have to synchronize at stage-level because cancellation happens at stage-level
        final String stageMutex = mutexForStageInstance(jobIdentifier);
        synchronized (stageMutex) {
            synchronized (mutexForJob(jobIdentifier)) {
                final JobInstance job = jobInstanceService.buildByIdWithTransitions(jobIdentifier.getBuildId());

                transactionTemplate.executeWithExceptionHandling(new com.thoughtworks.go.server.transaction.TransactionCallbackWithoutResult() {
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        if (job.isNull() || job.getState() == JobState.Rescheduled || job.getResult() == JobResult.Cancelled) {
                            return;
                        }

                        job.changeState(jobState);
                        //TODO: #2318 JobInstance should contain identifier after it's loaded from database
                        job.setIdentifier(jobIdentifier);
                        jobInstanceService.updateStateAndResult(job);

                        synchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                            @Override
                            public void afterCommit() {
                                stageDao.clearCachedAllStages(jobIdentifier.getPipelineName(), jobIdentifier.getPipelineCounter(), jobIdentifier.getStageName());
                            }
                        });

                        if (job.isCompleted()) {
                            Stage stage = stageService.stageById(job.getStageId());
                            stageService.updateResult(stage);
                        }
                    }
                });

                // this has to be in a separate transaction because the above should not fail due to errors when scheduling a the next stage
                // (e.g. CannotScheduleException thrown when there are no agents for run-on-all-agent jobs)
                transactionTemplate.executeWithExceptionHandling(new com.thoughtworks.go.server.transaction.TransactionCallbackWithoutResult() {
                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
                        if (job.isCompleted()) {
                            Stage stage = stageService.stageById(job.getStageId());
                            automaticallyTriggerRelevantStagesFollowingCompletionOf(stage);
                        }
                    }
                });
            }
        }
    }
493872
protected void updateCache(@Nonnull Job<?,?> job, @Nullable Run<?,?> b) {
        final int n = b==null ? RESOLVES_TO_NONE : b.getNumber();

        File cache = getPermalinkFile(job);
        cache.getParentFile().mkdirs();

        try {
            String target = String.valueOf(n);
            if (b != null && !new File(job.getBuildDir(), target).exists()) {
                // (re)create the build Number->Id symlink
                Util.createSymlink(job.getBuildDir(),b.getId(),target,TaskListener.NULL);
            }
            writeSymlink(cache, target);
        } catch (IOException | InterruptedException e) {
            LOGGER.log(Level.WARNING, "Failed to update "+job+" "+getId()+" permalink for " + b, e);
            cache.delete();
        }
    }
1051310
public Rec updateRecord(Rec record, boolean bRefresh)
    {
        try {
            Object bookmark = null;
            if (record.getEditMode() == Constant.EDIT_IN_PROGRESS)
            {
                if (bRefresh)
                    bookmark = record.getTable().getHandle(0);
                record.getTable().set(record);
            }
            else if ((record.getEditMode() == Constant.EDIT_ADD) && (record.isModified()))
            {
                record.getTable().add(record);
                if (bRefresh)
                    bookmark = record.getTable().getLastModified(0);
            }
            if (bRefresh)
                if (bookmark != null)
                {
                    record.getTable().setHandle(bookmark, 0);
                    record.getTable().edit();
                }
        } catch (DBException ex) {
            ex.printStackTrace();
            if (record != null)
                if (record.getTask() != null)
                    record.getTask().setLastError(ex.getMessage());
            return null;
        }
        return record;
    }