<commit_before>
#include "arch/arch.hpp"
#include "arch/os_signal.hpp"
#include "clustering/administration/auto_reconnect.hpp"
#include "clustering/administration/http/server.hpp"
#include "clustering/administration/issues/global.hpp"
#include "clustering/administration/issues/local_to_global.hpp"
#include "clustering/administration/issues/machine_down.hpp"
#include "clustering/administration/issues/name_conflict.hpp"
#include "clustering/administration/issues/pinnings_shards_mismatch.hpp"
#include "clustering/administration/issues/unsatisfiable_goals.hpp"
#include "clustering/administration/issues/vector_clock_conflict.hpp"
#include "clustering/administration/logger.hpp"
#include "clustering/administration/main/initial_join.hpp"
#include "clustering/administration/main/serve.hpp"
#include "clustering/administration/main/watchable_fields.hpp"
#include "clustering/administration/metadata.hpp"
#include "clustering/administration/namespace_interface_repository.hpp"
#include "clustering/administration/parser_maker.hpp"
#include "clustering/administration/perfmon_collection_repo.hpp"
#include "clustering/administration/persist.hpp"
#include "clustering/administration/proc_stats.hpp"
#include "clustering/administration/reactor_driver.hpp"
// TODO: the multistore header doesn't really belong.
#include "clustering/immediate_consistency/branch/multistore.hpp"
#include <stdio.h>
#include "memcached/tcp_conn.hpp"
#include "mock/dummy_protocol.hpp"
#include "mock/dummy_protocol_parser.hpp"
#include "rpc/connectivity/cluster.hpp"
#include "rpc/connectivity/cluster.hpp"
#include "rpc/connectivity/multiplexer.hpp"
#include "rpc/directory/read_manager.hpp"
#include "rpc/directory/write_manager.hpp"
#include "rpc/mailbox/mailbox.hpp"
#include "rpc/semilattice/semilattice_manager.hpp"
#include "rpc/semilattice/view/field.hpp"
#include "rpc/semilattice/view/function.hpp"
#include "rpc/semilattice/view/member.hpp"

// TODO: This doesn't really belong here.
template <class protocol_t>
class file_based_svs_by_namespace_t : public svs_by_namespace_t<protocol_t> {
public:
    file_based_svs_by_namespace_t(const std::string &file_path) : file_path_(file_path) { }

    void get_svs(perfmon_collection_t *perfmon_collection, namespace_id_t namespace_id,
                 boost::scoped_array<boost::scoped_ptr<typename protocol_t::store_t> > *stores_out,
                 boost::scoped_ptr<multistore_ptr_t<protocol_t> > *svs_out) {

        // TODO: Obviously, the hard-coded numeric constant here might
        // be regarded as a problem.
        const int num_stores = 24;
        const std::string file_name_base = file_path_ + "/" + uuid_to_str(namespace_id);

        debugf("actually calling get_svs...\n");

        // TODO: This is quite suspicious in that we check if the file
        // exists and then assume it exists or does not exist when
        // loading or creating it.

        // TODO: Also we only check file 0.

        stores_out->reset(new boost::scoped_ptr<typename protocol_t::store_t>[num_stores]);

        int res = access((file_name_base + "_" + strprintf("%d", 0)).c_str(), R_OK | W_OK);
        if (res == 0) {
            // The files already exist, thus we don't create them.
            boost::scoped_array<store_view_t<protocol_t> *> store_views(new store_view_t<protocol_t> *[num_stores]);

            for (int i = 0; i < num_stores; ++i) {
                const std::string file_name = file_name_base + "_" + strprintf("%d", i);
                (*stores_out)[i].reset(new typename protocol_t::store_t(file_name, false, perfmon_collection));
                store_views[i] = (*stores_out)[i].get();
            }

            svs_out->reset(new multistore_ptr_t<protocol_t>(store_views.get(), num_stores));
        } else {
            // TODO: How do we specify what the stores' regions are?

            // The files do not exist, create them.
            boost::scoped_array<store_view_t<protocol_t> *> store_views(new store_view_t<protocol_t> *[num_stores]);
            for (int i = 0; i < num_stores; ++i) {
                const std::string file_name = file_name_base + "_" + strprintf("%d", i);
                (*stores_out)[i].reset(new typename protocol_t::store_t(file_name, true, perfmon_collection));
                store_views[i] = (*stores_out)[i].get();
            }

            svs_out->reset(new multistore_ptr_t<protocol_t>(store_views.get(), num_stores));

            // Initialize the metadata in the underlying stores.
            boost::scoped_array<boost::scoped_ptr<fifo_enforcer_sink_t::exit_write_t> > write_tokens(new boost::scoped_ptr<fifo_enforcer_sink_t::exit_write_t>[num_stores]);

            (*svs_out)->new_write_tokens(write_tokens.get(), num_stores);

            cond_t dummy_interruptor;

            (*svs_out)->set_all_metainfos(region_map_t<protocol_t, binary_blob_t>((*svs_out)->get_multistore_joined_region(),
                                                                                  binary_blob_t(version_range_t(version_t::zero()))),
                                          order_token_t::ignore,  // TODO
                                          write_tokens.get(),
                                          num_stores,
                                          &dummy_interruptor);
        }
    }


private:<commit_msg>Reduced num_stores in file_based_svs_by_namespace_t to 5, added a debugf for get_svs actually returning, for debugging.<commit_after>
#include "arch/arch.hpp"
#include "arch/os_signal.hpp"
#include "clustering/administration/auto_reconnect.hpp"
#include "clustering/administration/http/server.hpp"
#include "clustering/administration/issues/global.hpp"
#include "clustering/administration/issues/local_to_global.hpp"
#include "clustering/administration/issues/machine_down.hpp"
#include "clustering/administration/issues/name_conflict.hpp"
#include "clustering/administration/issues/pinnings_shards_mismatch.hpp"
#include "clustering/administration/issues/unsatisfiable_goals.hpp"
#include "clustering/administration/issues/vector_clock_conflict.hpp"
#include "clustering/administration/logger.hpp"
#include "clustering/administration/main/initial_join.hpp"
#include "clustering/administration/main/serve.hpp"
#include "clustering/administration/main/watchable_fields.hpp"
#include "clustering/administration/metadata.hpp"
#include "clustering/administration/namespace_interface_repository.hpp"
#include "clustering/administration/parser_maker.hpp"
#include "clustering/administration/perfmon_collection_repo.hpp"
#include "clustering/administration/persist.hpp"
#include "clustering/administration/proc_stats.hpp"
#include "clustering/administration/reactor_driver.hpp"
// TODO: the multistore header doesn't really belong.
#include "clustering/immediate_consistency/branch/multistore.hpp"
#include <stdio.h>
#include "memcached/tcp_conn.hpp"
#include "mock/dummy_protocol.hpp"
#include "mock/dummy_protocol_parser.hpp"
#include "rpc/connectivity/cluster.hpp"
#include "rpc/connectivity/cluster.hpp"
#include "rpc/connectivity/multiplexer.hpp"
#include "rpc/directory/read_manager.hpp"
#include "rpc/directory/write_manager.hpp"
#include "rpc/mailbox/mailbox.hpp"
#include "rpc/semilattice/semilattice_manager.hpp"
#include "rpc/semilattice/view/field.hpp"
#include "rpc/semilattice/view/function.hpp"
#include "rpc/semilattice/view/member.hpp"

// TODO: This doesn't really belong here.
template <class protocol_t>
class file_based_svs_by_namespace_t : public svs_by_namespace_t<protocol_t> {
public:
    file_based_svs_by_namespace_t(const std::string &file_path) : file_path_(file_path) { }

    void get_svs(perfmon_collection_t *perfmon_collection, namespace_id_t namespace_id,
                 boost::scoped_array<boost::scoped_ptr<typename protocol_t::store_t> > *stores_out,
                 boost::scoped_ptr<multistore_ptr_t<protocol_t> > *svs_out) {

        // TODO: Obviously, the hard-coded numeric constant here might
        // be regarded as a problem.
        const int num_stores = 4;
        const std::string file_name_base = file_path_ + "/" + uuid_to_str(namespace_id);

        debugf("actually calling get_svs...\n");

        // TODO: This is quite suspicious in that we check if the file
        // exists and then assume it exists or does not exist when
        // loading or creating it.

        // TODO: Also we only check file 0.

        // TODO: We should use N slices on M serializers, not N slices
        // on N serializers.

        stores_out->reset(new boost::scoped_ptr<typename protocol_t::store_t>[num_stores]);

        int res = access((file_name_base + "_" + strprintf("%d", 0)).c_str(), R_OK | W_OK);
        if (res == 0) {
            // The files already exist, thus we don't create them.
            boost::scoped_array<store_view_t<protocol_t> *> store_views(new store_view_t<protocol_t> *[num_stores]);

            // TODO: This should use pmap.
            for (int i = 0; i < num_stores; ++i) {
                const std::string file_name = file_name_base + "_" + strprintf("%d", i);
                (*stores_out)[i].reset(new typename protocol_t::store_t(file_name, false, perfmon_collection));
                store_views[i] = (*stores_out)[i].get();
            }

            svs_out->reset(new multistore_ptr_t<protocol_t>(store_views.get(), num_stores));
        } else {
            // TODO: How do we specify what the stores' regions are?

            // The files do not exist, create them.
            // TODO: This should use pmap.
            boost::scoped_array<store_view_t<protocol_t> *> store_views(new store_view_t<protocol_t> *[num_stores]);
            for (int i = 0; i < num_stores; ++i) {
                const std::string file_name = file_name_base + "_" + strprintf("%d", i);
                (*stores_out)[i].reset(new typename protocol_t::store_t(file_name, true, perfmon_collection));
                store_views[i] = (*stores_out)[i].get();
            }

            svs_out->reset(new multistore_ptr_t<protocol_t>(store_views.get(), num_stores));

            // Initialize the metadata in the underlying stores.
            boost::scoped_array<boost::scoped_ptr<fifo_enforcer_sink_t::exit_write_t> > write_tokens(new boost::scoped_ptr<fifo_enforcer_sink_t::exit_write_t>[num_stores]);

            (*svs_out)->new_write_tokens(write_tokens.get(), num_stores);

            cond_t dummy_interruptor;

            (*svs_out)->set_all_metainfos(region_map_t<protocol_t, binary_blob_t>((*svs_out)->get_multistore_joined_region(),
                                                                                  binary_blob_t(version_range_t(version_t::zero()))),
                                          order_token_t::ignore,  // TODO
                                          write_tokens.get(),
                                          num_stores,
                                          &dummy_interruptor);
        }

        debugf("get_svs actually returning...\n");
    }


private:
{'fraction_non_alphanumeric': 0.11521699654984566, 'fraction_numerical': 0.0012711094970038134, 'mean_word_length': 3.274350019402406, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756134', 'n_tokens_mistral': 3484, 'n_tokens_neox': 3311, 'n_words': 613}