<commit_before>//===----------------------------------------------------------------------===//
//
//                         PelotonDB
//
// manager.cpp
//
// Identification: src/backend/catalog/manager.cpp
//
// Copyright (c) 2015, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <cassert>

#include "backend/catalog/manager.h"
#include "backend/storage/database.h"
#include "backend/storage/data_table.h"

namespace peloton {
namespace catalog {

Manager &Manager::GetInstance() {
  static Manager manager;
  return manager;
}

//===--------------------------------------------------------------------===//
// OBJECT MAP
//===--------------------------------------------------------------------===//

void Manager::SetTileGroup(const oid_t oid, storage::TileGroup *location) {
  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    locator.insert(std::pair<oid_t, storage::TileGroup *>(oid, location));
  }
}

storage::TileGroup *Manager::GetTileGroup(const oid_t oid) {
  storage::TileGroup *location = nullptr;

  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    location = locator.at(oid);
  }

  return location;
}

//used for logging test
void Manager::ClearTileGroup(){
  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    locator.clear();
  }
}

//===--------------------------------------------------------------------===//
// DATABASE
//===--------------------------------------------------------------------===//

void Manager::AddDatabase(storage::Database *database) {
  {
    std::lock_guard<std::mutex> lock(catalog_mutex);
    databases.push_back(database);
  }
}

storage::Database *Manager::GetDatabaseWithOid(const oid_t database_oid) const {
  for (auto database : databases)
    if (database->GetOid() == database_oid) return database;

  return nullptr;
}<commit_msg>Fix GetTileGroup bug. Should return nullptr when group not exist.<commit_after>//===----------------------------------------------------------------------===//
//
//                         PelotonDB
//
// manager.cpp
//
// Identification: src/backend/catalog/manager.cpp
//
// Copyright (c) 2015, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <cassert>

#include "backend/catalog/manager.h"
#include "backend/storage/database.h"
#include "backend/storage/data_table.h"

namespace peloton {
namespace catalog {

Manager &Manager::GetInstance() {
  static Manager manager;
  return manager;
}

//===--------------------------------------------------------------------===//
// OBJECT MAP
//===--------------------------------------------------------------------===//

void Manager::SetTileGroup(const oid_t oid, storage::TileGroup *location) {
  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    locator.insert(std::pair<oid_t, storage::TileGroup *>(oid, location));
  }
}

storage::TileGroup *Manager::GetTileGroup(const oid_t oid) {
  storage::TileGroup *location = nullptr;

  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    if (locator.find(oid) != locator.end())
      location = locator.at(oid);
  }

  return location;
}

//used for logging test
void Manager::ClearTileGroup(){
  {
    std::lock_guard<std::mutex> lock(locator_mutex);
    locator.clear();
  }
}

//===--------------------------------------------------------------------===//
// DATABASE
//===--------------------------------------------------------------------===//

void Manager::AddDatabase(storage::Database *database) {
  {
    std::lock_guard<std::mutex> lock(catalog_mutex);
    databases.push_back(database);
  }
}

storage::Database *Manager::GetDatabaseWithOid(const oid_t database_oid) const {
  for (auto database : databases)
    if (database->GetOid() == database_oid) return database;

  return nullptr;
}
{'fraction_non_alphanumeric': 0.3483606557377049, 'fraction_numerical': 0.0020491803278688526, 'mean_word_length': 1.6968232044198894, 'pattern_counts': {'":': 0, '<': 15, '<?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': '7565987', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1020, 'n_words': 194}