<commit_before>#include <extern/json/src/json.hpp>

#include <libdariadb/engines/engine.h>
#include <libdariadb/engines/shard.h>
#include <libdariadb/storage/subscribe.h>
#include <libdariadb/utils/async/thread_manager.h>
#include <libdariadb/utils/fs.h>
#include <libdariadb/utils/utils.h>
#include <shared_mutex>

#include <fstream>

const std::string SHARD_KEY_NAME = "shards";
const std::string SHARD_KEY_PATH = "path";
const std::string SHARD_KEY_ALIAS = "alias";
const std::string SHARD_KEY_IDS = "ids";

using namespace dariadb;
using namespace dariadb::storage;
using namespace dariadb::utils::async;

using json = nlohmann::json;

class ShardEngine::Private : public IEngine {
  struct ShardRef {
    std::string path;
    IEngine_Ptr storage;
  };

public:
  Private(const std::string &path) {
    _stoped = false;
    _settings = Settings::create(path);
    auto fname = shardFileName();
    if (!utils::fs::file_exists(fname)) {
      saveShardFile();
    }

    ThreadManager::Params tpm_params(_settings->thread_pools_params());
    ThreadManager::start(tpm_params);
    _subscribe_notify.start();

    loadShardFile();
  }

  ~Private() { this->stop(); }

  void stop() {
    if (!_stoped) {
      logger_info("shards: stopping");
      _subscribe_notify.stop();
      _id2shard.clear();
      for (auto s : _sub_storages) {
        s.storage->stop();
      }
      ThreadManager::stop();
    }
  }
<commit_msg>shard stoping.<commit_after>#include <extern/json/src/json.hpp>

#include <libdariadb/engines/engine.h>
#include <libdariadb/engines/shard.h>
#include <libdariadb/storage/subscribe.h>
#include <libdariadb/utils/async/thread_manager.h>
#include <libdariadb/utils/fs.h>
#include <libdariadb/utils/utils.h>
#include <shared_mutex>

#include <fstream>

const std::string SHARD_KEY_NAME = "shards";
const std::string SHARD_KEY_PATH = "path";
const std::string SHARD_KEY_ALIAS = "alias";
const std::string SHARD_KEY_IDS = "ids";

using namespace dariadb;
using namespace dariadb::storage;
using namespace dariadb::utils::async;

using json = nlohmann::json;

class ShardEngine::Private : public IEngine {
  struct ShardRef {
    std::string path;
    IEngine_Ptr storage;
  };

public:
  Private(const std::string &path) {
    _stoped = false;
    _settings = Settings::create(path);
    auto fname = shardFileName();
    if (!utils::fs::file_exists(fname)) {
      saveShardFile();
    }

    ThreadManager::Params tpm_params(_settings->thread_pools_params());
    ThreadManager::start(tpm_params);
    _subscribe_notify.start();

    loadShardFile();
  }

  ~Private() { this->stop(); }

  void stop() {
    if (!_stoped) {
      logger_info("shards: stopping");
      _subscribe_notify.stop();
      _id2shard.clear();
      for (auto s : _sub_storages) {
        s.storage->stop();
      }
      ThreadManager::stop();
	  _stoped = true;
    }
  }

{'fraction_non_alphanumeric': 0.14380222841225626, 'fraction_numerical': 0.0006963788300835655, 'mean_word_length': 4.1765765765765765, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '7292581', 'n_tokens_mistral': 1031, 'n_tokens_neox': 1019, 'n_words': 185}