<commit_before>#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <getopt.h>
#include <zs.h>

static int verbose_flag = 0;
static int btree_opt = 0;    
static int flog_opt = 1;    // must always be run
static int pot_opt = 0;    
static char *logfile = NULL;

static struct ZS_state* zs_state;
static __thread struct ZS_thread_state *_zs_thd_state;

static struct option long_options[] = { 
    {"verbose", no_argument,       &verbose_flag, 1}, 
    {"btree",   no_argument,       0, 'b'}, 
//  {"flog",    no_argument,       0, 'f'}, 
    {"pot",     no_argument,       0, 'p'}, 
    {"help",    no_argument,       0, 'h'}, 
    {"logfile", required_argument, 0, 'l'}, 
    {0, 0, 0, 0} 
};

void print_help(char *pname) 
{
    fprintf(stderr, "\nExecute validation of ZetaScale persistent metadata, btree strucutres and recovery logs.\n\n");
    fprintf(stderr, "%s --btree --pot --logfile=file --help\n\n", pname);
}

int get_options(int argc, char *argv[])
{
    int option_index = 0;
    int c;

    while (1) { 
        c = getopt_long (argc, argv, "bl:pt:vh", long_options, &option_index); 

        if (c == -1) 
            break;
     
        switch (c) { 
     
        case 'l': 
            logfile = optarg; 
            break;
     
        case 'b': 
            btree_opt = 1; 
            break;

        case 'p': 
            pot_opt = 1; 
            break;

        case 'v': 
            verbose_flag = 1;
            break;

        case 'h': 
            print_help(argv[0]); 
            return -1;

        default:
            print_help(argv[0]); 
            return -1;
        }
    }

    return 0;
}

int init_zs() {
    ZS_status_t status = ZS_FAILURE;

    if ( ZS_SUCCESS != ( status = ZSInit( &zs_state ) ) ) {
        fprintf(stderr, "Failed to initialize ZS API!\n");
        return status;
    }

    if ( ZS_SUCCESS != ( status = ZSInitPerThreadState(zs_state, &_zs_thd_state ) ) ) {
        fprintf(stderr, "Failed to initialize ZS API!\n");
        return status;
    }

    return status;
}

int close_zs()
{
    ZS_status_t status = ZS_FAILURE;

    ZSCheckClose();

    if ( ZS_SUCCESS != ( status = ZSReleasePerThreadState(&_zs_thd_state ) ) ) {
        fprintf(stderr, "Failed to release ZS thread state!\n");
        return status;
    }

    if ( ZS_SUCCESS != (status = ZSShutdown( zs_state ) ) ) {
        fprintf(stderr, "Failed to shutdown ZS API!\n");
        return status;
    }

    return status;
}

ZS_status_t check_meta()
{
    return ZSCheckMeta();
}

ZS_status_t check_btree()
{
    return ZSCheck( _zs_thd_state );
}

ZS_status_t check_flog()
{
    return ZSCheckFlog( );
}

ZS_status_t check_pot()
{
    return ZSCheckPOT( );
}

int main(int argc, char *argv[])
{
    ZS_status_t status = ZS_FAILURE;
    char *prop_file = NULL;

    if ( get_options( argc, argv) ) {
        return -1;
    }

    prop_file = getenv("ZS_PROPERTY_FILE");
    if (prop_file)
        ZSLoadProperties(prop_file);

    ZSCheckInit(logfile);

    // always check superblock and shard metadata
    if (ZS_SUCCESS != check_meta()) {
        fprintf(stderr, "meta check failed, unable to continue\n");
        return -1;
    } else {
        fprintf(stderr, "meta check succeeded\n");
    }

    if (init_zs() < 0) {
        fprintf(stderr, "ZS init failed\n");
        return -1;
    }

    // must always be run
    if (flog_opt) {
        if (ZS_SUCCESS != (status = check_flog())) {
            fprintf(stderr, "flog check failed: %s\n", ZSStrError(status));
        } else {
            fprintf(stderr, "flog check succeeded\n");
        }
    }

    if (pot_opt) {<commit_msg>#0000 Set required properties within zsck  TESTS_RAN: manual<commit_after>#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <getopt.h>
#include <zs.h>

static int verbose_flag = 0;
static int btree_opt = 0;    
static int flog_opt = 1;    // must always be run
static int pot_opt = 0;    
static char *logfile = NULL;

static struct ZS_state* zs_state;
static __thread struct ZS_thread_state *_zs_thd_state;

static struct option long_options[] = { 
    {"verbose", no_argument,       &verbose_flag, 1}, 
    {"btree",   no_argument,       0, 'b'}, 
    {"pot",     no_argument,       0, 'p'}, 
    {"help",    no_argument,       0, 'h'}, 
    {"logfile", required_argument, 0, 'l'}, 
    {0, 0, 0, 0} 
};

void print_help(char *pname) 
{
    fprintf(stderr, "\nExecute validation of ZetaScale persistent metadata, btree strucutres and recovery logs.\n\n");
    fprintf(stderr, "%s --btree --pot --logfile=file --help\n\n", pname);
}

int get_options(int argc, char *argv[])
{
    int option_index = 0;
    int c;

    while (1) { 
        c = getopt_long (argc, argv, "bl:pt:vh", long_options, &option_index); 

        if (c == -1) 
            break;
     
        switch (c) { 
     
        case 'l': 
            logfile = optarg; 
            break;
     
        case 'b': 
            btree_opt = 1; 
            break;

        case 'p': 
            pot_opt = 1; 
            break;

        case 'v': 
            verbose_flag = 1;
            break;

        case 'h': 
            print_help(argv[0]); 
            return -1;

        default:
            print_help(argv[0]); 
            return -1;
        }
    }

    return 0;
}

int init_zs() {
    ZS_status_t status = ZS_FAILURE;

    if ( ZS_SUCCESS != ( status = ZSInit( &zs_state ) ) ) {
        fprintf(stderr, "Failed to initialize ZS API!\n");
        return status;
    }

    if ( ZS_SUCCESS != ( status = ZSInitPerThreadState(zs_state, &_zs_thd_state ) ) ) {
        fprintf(stderr, "Failed to initialize ZS API!\n");
        return status;
    }

    return status;
}

int close_zs()
{
    ZS_status_t status = ZS_FAILURE;

    ZSCheckClose();

    if ( ZS_SUCCESS != ( status = ZSReleasePerThreadState(&_zs_thd_state ) ) ) {
        fprintf(stderr, "Failed to release ZS thread state!\n");
        return status;
    }

    if ( ZS_SUCCESS != (status = ZSShutdown( zs_state ) ) ) {
        fprintf(stderr, "Failed to shutdown ZS API!\n");
        return status;
    }

    return status;
}

ZS_status_t check_meta()
{
    return ZSCheckMeta();
}

ZS_status_t check_btree()
{
    return ZSCheck( _zs_thd_state );
}

ZS_status_t check_flog()
{
    return ZSCheckFlog( );
}

ZS_status_t check_pot()
{
    return ZSCheckPOT( );
}

void set_props()
{
    ZSLoadProperties(getenv("ZS_PROPERTY_FILE"));
    ZSSetProperty("ZS_CHECK_MODE", "1");
    ZSSetProperty("ZS_REFORMAT", "0");
    unsetenv("ZS_PROPERTY_FILE");
}

int main(int argc, char *argv[])
{
    ZS_status_t status = ZS_FAILURE;

    if ( get_options( argc, argv) ) {
        return -1;
    }

    set_props();

    ZSCheckInit(logfile);

    // always check superblock and shard metadata
    if (ZS_SUCCESS != check_meta()) {
        fprintf(stderr, "meta check failed, unable to continue\n");
        return -1;
    } else {
        fprintf(stderr, "meta check succeeded\n");
    }

    if (init_zs() < 0) {
        fprintf(stderr, "ZS init failed\n");
        return -1;
    }

    // must always be run
    if (flog_opt) {
        if (ZS_SUCCESS != (status = check_flog())) {
            fprintf(stderr, "flog check failed: %s\n", ZSStrError(status));
        } else {
            fprintf(stderr, "flog check succeeded\n");
        }
    }

    if (pot_opt) {
{'fraction_non_alphanumeric': 0.13199946287095474, 'fraction_numerical': 0.008459782462736673, 'mean_word_length': 2.149260042283298, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4570868', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2633, 'n_words': 642}