<commit_before><?php
/*=========================================================================

  Program:   CDash - Cross-Platform Dashboard System
  Module:    $Id$
  Language:  PHP
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

// To be able to access files in this CDash installation regardless
// of getcwd() value:
//
$cdashpath = dirname(dirname(__FILE__));
set_include_path($cdashpath . PATH_SEPARATOR . get_include_path());

require_once("cdash/common.php");
require_once("cdash/do_submit.php");
require_once("cdash/pdo.php");


ob_start();
set_time_limit(0);
ignore_user_abort(TRUE);


// Returns true if this call to processsubmissions.php should execute the
// processing loop. Returns false if another instance of processsubmissions.php
// is already executing the loop.
//
function AcquireProcessingLock($projectid, $force)
{
  $locked = false;

  $tables = array();
  $tables[] = 'submissionprocessor';
  $table_locked = pdo_lock_tables($tables);
  if (!$table_locked)
    {
    add_log("AcquireProcessingLock", "could not lock database tables",
      LOG_ERR, $projectid);
    }

  if ($table_locked)
    {
    // The submissionprocessor table should have at most one row for
    // each projectid value. Expect $c to be 0 or 1 here.
    //
    $c = pdo_get_field_value(
      "SELECT COUNT(*) AS c FROM submissionprocessor ".
      "WHERE projectid='".$projectid."'",
      'c', 0);

    $now_utc = gmdate(FMT_DATETIMESTD);
    $mypid = getmypid();

    if ($c == 0)
      {
      // No row yet for this projectid. Insert one and own the loop lock.
      //
      pdo_query(
        "INSERT INTO submissionprocessor (projectid, pid, lastupdated, locked) ".
        "VALUES ('$projectid', '$mypid', '$now_utc', '$now_utc')");
      add_last_sql_error("AcquireProcessingLock-1");
      $locked = true;
      //add_log("AcquireProcessingLock", "lock acquired -- and row created",
      //  LOG_INFO, $projectid);
      }
    else
      {
      // One row for this projectid. See if some other pid owns the lock.
      //
      if ($c != 1)
        {
        add_log("AcquireProcessingLock", "unexpected row count c='$c'",
          LOG_ERR, $projectid);
        }

      $row = pdo_single_row_query(
        "SELECT * FROM submissionprocessor WHERE projectid='".$projectid."'");
      $pid = $row['pid'];

      // By default, do not acquire the lock:
      //
      $acquire_lock = false;

      if ($force)
        {
        //add_log("AcquireProcessingLock", "taking lock: 'force' is true",
        //  LOG_INFO, $projectid);
        $acquire_lock = true;
        }
      elseif ($pid != 0)
        {
        // Another pid owns the lock and is presumably still alive
        // and processing...
        //
        // Verify that it has not been "too long" since the lastupdated
        // field was updated.
        //
        // If it was too long ago, assume something bad has happened, and take
        // the lock from that process. Ideally, we'd have a way to measure if
        // $pid represents a still running process, and only take the lock if
        // $pid is definitely *not* running anymore...
        //
        $lastupdated = $row['lastupdated'];

        $lastupdated_utc_ts = strtotime($lastupdated);
        $now_utc_ts = strtotime($now_utc);

        global $CDASH_SUBMISSION_PROCESSING_TIME_LIMIT;
        if ($lastupdated_utc_ts < ($now_utc_ts - $CDASH_SUBMISSION_PROCESSING_TIME_LIMIT))
          {
          //if ($pid is not presently running) // assumed, php-way to measure?
          //  {
            add_log("AcquireProcessingLock",
              "taking lock: projectid=$projectid, other processor pid='$pid' ".
              "apparently stalled, lastupdated='$lastupdated'",
              LOG_ERR, $projectid);
            $acquire_lock = true;
          //  }
          }

        if (!$acquire_lock)
          {
          add_log("AcquireProcessingLock",
            "lock not acquired, owned by other pid='$pid'",
            LOG_INFO, $projectid);
          }
        }
      else
        {
        // No other pid owns the lock. OK to acquire it.
        //
        $acquire_lock = true;
        }

      if ($acquire_lock)
        {
        // Update the one row with mypid and own the loop lock.
        //
        pdo_query(<commit_msg>STYLE: Removed logging info<commit_after><?php
/*=========================================================================

  Program:   CDash - Cross-Platform Dashboard System
  Module:    $Id$
  Language:  PHP
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

// To be able to access files in this CDash installation regardless
// of getcwd() value:
//
$cdashpath = dirname(dirname(__FILE__));
set_include_path($cdashpath . PATH_SEPARATOR . get_include_path());

require_once("cdash/common.php");
require_once("cdash/do_submit.php");
require_once("cdash/pdo.php");


ob_start();
set_time_limit(0);
ignore_user_abort(TRUE);


// Returns true if this call to processsubmissions.php should execute the
// processing loop. Returns false if another instance of processsubmissions.php
// is already executing the loop.
//
function AcquireProcessingLock($projectid, $force)
{
  $locked = false;

  $tables = array();
  $tables[] = 'submissionprocessor';
  $table_locked = pdo_lock_tables($tables);
  if (!$table_locked)
    {
    add_log("AcquireProcessingLock", "could not lock database tables",
      LOG_ERR, $projectid);
    }

  if ($table_locked)
    {
    // The submissionprocessor table should have at most one row for
    // each projectid value. Expect $c to be 0 or 1 here.
    //
    $c = pdo_get_field_value(
      "SELECT COUNT(*) AS c FROM submissionprocessor ".
      "WHERE projectid='".$projectid."'",
      'c', 0);

    $now_utc = gmdate(FMT_DATETIMESTD);
    $mypid = getmypid();

    if ($c == 0)
      {
      // No row yet for this projectid. Insert one and own the loop lock.
      //
      pdo_query(
        "INSERT INTO submissionprocessor (projectid, pid, lastupdated, locked) ".
        "VALUES ('$projectid', '$mypid', '$now_utc', '$now_utc')");
      add_last_sql_error("AcquireProcessingLock-1");
      $locked = true;
      //add_log("AcquireProcessingLock", "lock acquired -- and row created",
      //  LOG_INFO, $projectid);
      }
    else
      {
      // One row for this projectid. See if some other pid owns the lock.
      //
      if ($c != 1)
        {
        add_log("AcquireProcessingLock", "unexpected row count c='$c'",
          LOG_ERR, $projectid);
        }

      $row = pdo_single_row_query(
        "SELECT * FROM submissionprocessor WHERE projectid='".$projectid."'");
      $pid = $row['pid'];

      // By default, do not acquire the lock:
      //
      $acquire_lock = false;

      if ($force)
        {
        //add_log("AcquireProcessingLock", "taking lock: 'force' is true",
        //  LOG_INFO, $projectid);
        $acquire_lock = true;
        }
      elseif ($pid != 0)
        {
        // Another pid owns the lock and is presumably still alive
        // and processing...
        //
        // Verify that it has not been "too long" since the lastupdated
        // field was updated.
        //
        // If it was too long ago, assume something bad has happened, and take
        // the lock from that process. Ideally, we'd have a way to measure if
        // $pid represents a still running process, and only take the lock if
        // $pid is definitely *not* running anymore...
        //
        $lastupdated = $row['lastupdated'];

        $lastupdated_utc_ts = strtotime($lastupdated);
        $now_utc_ts = strtotime($now_utc);

        global $CDASH_SUBMISSION_PROCESSING_TIME_LIMIT;
        if ($lastupdated_utc_ts < ($now_utc_ts - $CDASH_SUBMISSION_PROCESSING_TIME_LIMIT))
          {
          //if ($pid is not presently running) // assumed, php-way to measure?
          //  {
            add_log("AcquireProcessingLock",
              "taking lock: projectid=$projectid, other processor pid='$pid' ".
              "apparently stalled, lastupdated='$lastupdated'",
              LOG_ERR, $projectid);
            $acquire_lock = true;
          //  }
          }

        if (!$acquire_lock)
          {
          //add_log("AcquireProcessingLock",
          //  "lock not acquired, owned by other pid='$pid'",
          //  LOG_INFO, $projectid);
          }
        }
      else
        {
        // No other pid owns the lock. OK to acquire it.
        //
        $acquire_lock = true;
        }

      if ($acquire_lock)
        {
        // Update the one row with mypid and own the loop lock.
        //
        pdo_query(
{'fraction_non_alphanumeric': 0.142570281124498, 'fraction_numerical': 0.0025364616360177552, 'mean_word_length': 2.3390966831333806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4864390', 'n_tokens_mistral': 2797, 'n_tokens_neox': 2718, 'n_words': 816}