<commit_before>// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#define intabs(x) ((x) >= 0 ? (x):(-(x)))

#include <mpi.h>

#include <sys/stat.h>
#include <iostream>
#include <string>
using namespace std;

#include <fcntl.h>

#include "config.h"

#include "mds/MDS.h"
#include "osd/OSD.h"
#include "mon/Monitor.h"
#include "client/Client.h"
#include "client/SyntheticClient.h"

#include "msg/SimpleMessenger.h"

#include "common/Timer.h"


class C_Test : public Context {
public:
  void finish(int r) {
    cout << "C_Test->finish(" << r << ")" << std::endl;
  }
};

extern std::map<entity_name_t,float> g_fake_kill_after;


/*
 * start up NewMessenger via MPI.
 */ 

pair<int,int> mpi_bootstrap_new(int& argc, char**& argv, MonMap *monmap)
{
  MPI_Init(&argc, &argv);
  
  int mpi_world;
  int mpi_rank;
  MPI_Comm_size(MPI_COMM_WORLD, &mpi_world);
  MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

  // first, synchronize clocks.
  if (g_conf.clock_tare) {
    if (1) {
      // use an MPI barrier.  probably not terribly precise.
      MPI_Barrier(MPI_COMM_WORLD);
      g_clock.tare();
    } else {
      // use wall clock; assume NTP has all nodes synchronized already.
      // FIXME someday: this hangs for some reason.  whatever.
      utime_t z = g_clock.now();
      MPI_Bcast( &z, sizeof(z), MPI_CHAR,
		 0, MPI_COMM_WORLD);
      cout << "z is " << z << std::endl;
      g_clock.tare(z);
    }
  }
  
  // start up all monitors at known addresses.
  entity_inst_t moninst[mpi_world];  // only care about first g_conf.num_mon of these.

  rank.start_rank();   // bind and listen

  if (mpi_rank < g_conf.num_mon) {
    moninst[mpi_rank].addr = rank.rank_addr;
    moninst[mpi_rank].name = entity_name_t(entity_name_t::TYPE_MON, mpi_rank);

    //cerr << mpi_rank << " at " << rank.get_listen_addr() << std::endl;
  } 

  MPI_Gather( &moninst[mpi_rank], sizeof(entity_inst_t), MPI_CHAR,
              moninst, sizeof(entity_inst_t), MPI_CHAR,
              0, MPI_COMM_WORLD);
  
  if (mpi_rank == 0) {
    for (int i=0; i<g_conf.num_mon; i++) {
      cerr << "mon" << i << " is at " << moninst[i] << std::endl;
      monmap->mon_inst[i] = moninst[i];
    }
  }


  // distribute monmap
  bufferlist bl;
  if (mpi_rank == 0) {
    monmap->encode(bl);
    monmap->write(".ceph_monmap");
  } else {
    int l = g_conf.num_mon * 1000;   // nice'n big.
    bufferptr bp(l); 
    bl.append(bp);
  }
  
  MPI_Bcast(bl.c_str(), bl.length(), MPI_CHAR,
            0, MPI_COMM_WORLD);

  if (mpi_rank > 0) {
    monmap->decode(bl);
  }
  
  // wait for everyone!
  MPI_Barrier(MPI_COMM_WORLD);

  return pair<int,int>(mpi_rank, mpi_world);
}

utime_t tick_start;
int tick_count = 0;

class C_Tick : public Context {
public:
  void finish(int) {
    utime_t now = g_clock.now() - tick_start;
    cout << "tick +" << g_conf.tick << " -> " << now << "  (" << tick_count << ")" << std::endl;
    tick_count += g_conf.tick;
    utime_t next = tick_start;
    next.sec_ref() += tick_count;
    g_timer.add_event_at(next, new C_Tick);
  }
};

class C_Die : public Context {
public:
  void finish(int) {
    cerr << "die" << std::endl;
    _exit(1);
  }
};

class C_Debug : public Context {
  public:
  void finish(int) {
    int size = (long)&g_conf.debug_after - (long)&g_conf.debug;
    memcpy((char*)&g_conf.debug, (char*)&g_debug_after_conf.debug, size);
    cout << "debug_after flipping debug settings" << std::endl;
    //g_conf.debug_ms = 1;
  }
};


int main(int argc, char **argv) 
{
  vector<char*> args;
  argv_to_vec(argc, argv, args);

  map<int,int> kill_osd_after;
  int share_single_client = 0;
  if (1) {
    vector<char*> nargs;
    for (unsigned i=0; i<args.size(); i++) {
      if (strcmp(args[i],"--kill_osd_after") == 0) {
        int o = atoi(args[++i]);
        int w = atoi(args[++i]);
        kill_osd_after[o] = w;
      }
      else if (strcmp(args[i], "--share_single_client") == 0) {
	share_single_client = 1;
      } else {<commit_msg>newsyn can reuse an existing monmap<commit_after>// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#define intabs(x) ((x) >= 0 ? (x):(-(x)))

#include <mpi.h>

#include <sys/stat.h>
#include <iostream>
#include <string>
using namespace std;

#include <fcntl.h>

#include "config.h"

#include "mds/MDS.h"
#include "osd/OSD.h"
#include "mon/Monitor.h"
#include "client/Client.h"
#include "client/SyntheticClient.h"

#include "msg/SimpleMessenger.h"

#include "common/Timer.h"


class C_Test : public Context {
public:
  void finish(int r) {
    cout << "C_Test->finish(" << r << ")" << std::endl;
  }
};

extern std::map<entity_name_t,float> g_fake_kill_after;

bool use_existing_monmap = false;
char *monmap_fn = ".ceph_monmap";
/*
 * start up NewMessenger via MPI.
 */ 

pair<int,int> mpi_bootstrap_new(int& argc, char**& argv, MonMap *monmap)
{
  MPI_Init(&argc, &argv);
  
  int mpi_world;
  int mpi_rank;
  MPI_Comm_size(MPI_COMM_WORLD, &mpi_world);
  MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

  if (use_existing_monmap && mpi_rank < g_conf.num_mon) {
    int r = monmap->read(monmap_fn);
    assert(r >= 0);
    g_my_addr = monmap->get_inst(mpi_rank).addr;
    cout << "i am monitor, will bind to " << g_my_addr 
	 << " from existing " << monmap_fn << std::endl;
  }

  // first, synchronize clocks.
  if (g_conf.clock_tare) {
    if (1) {
      // use an MPI barrier.  probably not terribly precise.
      MPI_Barrier(MPI_COMM_WORLD);
      g_clock.tare();
    } else {
      // use wall clock; assume NTP has all nodes synchronized already.
      // FIXME someday: this hangs for some reason.  whatever.
      utime_t z = g_clock.now();
      MPI_Bcast( &z, sizeof(z), MPI_CHAR,
		 0, MPI_COMM_WORLD);
      cout << "z is " << z << std::endl;
      g_clock.tare(z);
    }
  }
  
  // start up all monitors at known addresses.
  entity_inst_t moninst[mpi_world];  // only care about first g_conf.num_mon of these.

  rank.start_rank();   // bind and listen

  if (mpi_rank < g_conf.num_mon) {
    moninst[mpi_rank].addr = rank.rank_addr;
    moninst[mpi_rank].name = entity_name_t(entity_name_t::TYPE_MON, mpi_rank);

    //cerr << mpi_rank << " at " << rank.get_listen_addr() << std::endl;
  } 

  MPI_Gather( &moninst[mpi_rank], sizeof(entity_inst_t), MPI_CHAR,
              moninst, sizeof(entity_inst_t), MPI_CHAR,
              0, MPI_COMM_WORLD);
  
  if (mpi_rank == 0) {
    for (int i=0; i<g_conf.num_mon; i++) {
      cerr << "mon" << i << " is at " << moninst[i] << std::endl;
      monmap->mon_inst[i] = moninst[i];
    }
  }


  // distribute monmap
  bufferlist bl;
  if (mpi_rank == 0) {
    monmap->encode(bl);
    monmap->write(monmap_fn);
  } else {
    int l = g_conf.num_mon * 1000;   // nice'n big.
    bufferptr bp(l); 
    bl.append(bp);
  }
  
  MPI_Bcast(bl.c_str(), bl.length(), MPI_CHAR,
            0, MPI_COMM_WORLD);

  if (mpi_rank > 0) {
    monmap->decode(bl);
  }
  
  // wait for everyone!
  MPI_Barrier(MPI_COMM_WORLD);

  return pair<int,int>(mpi_rank, mpi_world);
}

utime_t tick_start;
int tick_count = 0;

class C_Tick : public Context {
public:
  void finish(int) {
    utime_t now = g_clock.now() - tick_start;
    cout << "tick +" << g_conf.tick << " -> " << now << "  (" << tick_count << ")" << std::endl;
    tick_count += g_conf.tick;
    utime_t next = tick_start;
    next.sec_ref() += tick_count;
    g_timer.add_event_at(next, new C_Tick);
  }
};

class C_Die : public Context {
public:
  void finish(int) {
    cerr << "die" << std::endl;
    _exit(1);
  }
};

class C_Debug : public Context {
  public:
  void finish(int) {
    int size = (long)&g_conf.debug_after - (long)&g_conf.debug;
    memcpy((char*)&g_conf.debug, (char*)&g_debug_after_conf.debug, size);
    cout << "debug_after flipping debug settings" << std::endl;
    //g_conf.debug_ms = 1;
  }
};


int main(int argc, char **argv) 
{
  vector<char*> args;
  argv_to_vec(argc, argv, args);

  map<int,int> kill_osd_after;
  int share_single_client = 0;
  if (1) {
    vector<char*> nargs;
    for (unsigned i=0; i<args.size(); i++) {
      if (strcmp(args[i],"--kill_osd_after") == 0) {
        int o = atoi(args[++i]);
        int w = atoi(args[++i]);
        kill_osd_after[o] = w;
      }
      else if (strcmp(args[i], "--use_existing_monmap") == 0) {
	use_existing_monmap = true;
      }
      else if (strcmp(args[i], "--share_single_client") == 0) {
	share_single_client = 1;
      } else {
{'fraction_non_alphanumeric': 0.1600790513833992, 'fraction_numerical': 0.008124725516029864, 'mean_word_length': 3.0719713902548054, 'pattern_counts': {'":': 0, '<': 160, '<?xml version=': 0, '>': 50, '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': '5355684', 'n_tokens_mistral': 3687, 'n_tokens_neox': 3523, 'n_words': 793}