<commit_before>// -------------------------------------------------------------------
//
// hot_backup.cc
//
// Copyright (c) 2011-2016 Basho Technologies, Inc. All Rights Reserved.
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// -------------------------------------------------------------------

#include <unistd.h>

#include "leveldb/atomics.h"
#include "leveldb/env.h"

#include "db/dbformat.h"
#include "db/db_impl.h"
#include "db/filename.h"
#include "util/db_list.h"
#include "util/hot_backup.h"
#include "util/hot_threads.h"

namespace leveldb {


// this local static is used during normal operations.  unit tests
//  create independent object.
static HotBackup LocalHotBackupObj;
HotBackup * HotBackup::gHotBackup(&LocalHotBackupObj);
void HotBackup::ResetHotBackupObject() {gHotBackup=&LocalHotBackupObj;};


/**
 * Called by throttle.cc's thread once a minute.  Used to
 *  test for trigger condition
 */
void
CheckHotBackupTrigger()
{
    // add_and_fetch for memory fences
    if (0 == HotBackup::Ptr()->GetJobsPending())
    {
        if (HotBackup::Ptr()->IsTriggerSet())
        {
            // two instance counts held for "trigger management"
            //  (protects against hot backups happening as fast as
            //   ScanDB() makes calls ... causing trigger to reset too
            //   early)
            HotBackup::Ptr()->HotBackupScheduled();
            HotBackup::Ptr()->HotBackupScheduled();

            // Log() routes to syslog as an error
            Log(NULL, "leveldb HotBackup triggered.");
            gPerfCounters->Inc(ePerfBackupStarted);

            DBList()->ScanDBs(true,  &DBImpl::HotBackup);
            DBList()->ScanDBs(false, &DBImpl::HotBackup);

            // reduce to one instance count now that events posted
            //  (trigger reset now enabled)
            HotBackup::Ptr()->HotBackupFinished();
        }   // if
    }   // if

    return;

}   // CheckHotBackupTrigger


/**
 * Look for external trigger
 */
bool
HotBackup::IsTriggerSet()
{
    bool ret_flag;
    int ret_val;

    //
    // This is code polls for existence of /etc/riak/hot_backup
    //
    ret_val=access(GetTriggerPath(), F_OK);
    ret_flag=(-1!=ret_val);

    return(ret_flag);

}   // HotBackup::IsTriggerSet


/**
 * Let external trigger know that hot backup is complete.  Put
 *  message to syslog if unable to delete trigger file
 */
void
HotBackup::ResetTrigger()
{
    bool ret_flag;
    int ret_val;

    ret_val=unlink(GetTriggerPath());
    if (0==ret_val)
    {
        // release last counter, enabling future backups
        HotBackupFinished();
    }   // if
    else
    {
        // one count left, effectively disabling trigger forever (or next program restart)
        Log(NULL, "leveldb HotBackup unable to delete trigger file %s", GetTriggerPath());
        Log(NULL, "leveldb HotBackup now disabled until program restart");
    }   // if

    return;

}   // ResetHotBackupTrigger


/**
 * A database instance marks its intent to backup
 */
void<commit_msg>remove dead variable in ResetTrigger()<commit_after>// -------------------------------------------------------------------
//
// hot_backup.cc
//
// Copyright (c) 2011-2016 Basho Technologies, Inc. All Rights Reserved.
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// -------------------------------------------------------------------

#include <unistd.h>

#include "leveldb/atomics.h"
#include "leveldb/env.h"

#include "db/dbformat.h"
#include "db/db_impl.h"
#include "db/filename.h"
#include "util/db_list.h"
#include "util/hot_backup.h"
#include "util/hot_threads.h"

namespace leveldb {


// this local static is used during normal operations.  unit tests
//  create independent object.
static HotBackup LocalHotBackupObj;
HotBackup * HotBackup::gHotBackup(&LocalHotBackupObj);
void HotBackup::ResetHotBackupObject() {gHotBackup=&LocalHotBackupObj;};


/**
 * Called by throttle.cc's thread once a minute.  Used to
 *  test for trigger condition
 */
void
CheckHotBackupTrigger()
{
    // add_and_fetch for memory fences
    if (0 == HotBackup::Ptr()->GetJobsPending())
    {
        if (HotBackup::Ptr()->IsTriggerSet())
        {
            // two instance counts held for "trigger management"
            //  (protects against hot backups happening as fast as
            //   ScanDB() makes calls ... causing trigger to reset too
            //   early)
            HotBackup::Ptr()->HotBackupScheduled();
            HotBackup::Ptr()->HotBackupScheduled();

            // Log() routes to syslog as an error
            Log(NULL, "leveldb HotBackup triggered.");
            gPerfCounters->Inc(ePerfBackupStarted);

            DBList()->ScanDBs(true,  &DBImpl::HotBackup);
            DBList()->ScanDBs(false, &DBImpl::HotBackup);

            // reduce to one instance count now that events posted
            //  (trigger reset now enabled)
            HotBackup::Ptr()->HotBackupFinished();
        }   // if
    }   // if

    return;

}   // CheckHotBackupTrigger


/**
 * Look for external trigger
 */
bool
HotBackup::IsTriggerSet()
{
    bool ret_flag;
    int ret_val;

    //
    // This is code polls for existence of /etc/riak/hot_backup
    //
    ret_val=access(GetTriggerPath(), F_OK);
    ret_flag=(-1!=ret_val);

    return(ret_flag);

}   // HotBackup::IsTriggerSet


/**
 * Let external trigger know that hot backup is complete.  Put
 *  message to syslog if unable to delete trigger file
 */
void
HotBackup::ResetTrigger()
{
    int ret_val;

    ret_val=unlink(GetTriggerPath());
    if (0==ret_val)
    {
        // release last counter, enabling future backups
        HotBackupFinished();
    }   // if
    else
    {
        // one count left, effectively disabling trigger forever (or next program restart)
        Log(NULL, "leveldb HotBackup unable to delete trigger file %s", GetTriggerPath());
        Log(NULL, "leveldb HotBackup now disabled until program restart");
    }   // if

    return;

}   // ResetHotBackupTrigger


/**
 * A database instance marks its intent to backup
 */
void
{'fraction_non_alphanumeric': 0.1486410759316335, 'fraction_numerical': 0.004202857943401513, 'mean_word_length': 2.346929207688701, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4849392', 'n_tokens_mistral': 2020, 'n_tokens_neox': 2017, 'n_words': 641}