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

#include "backend/storage/backend_file.h"
#include "backend/logging/log_manager.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <fstream>
#include <unistd.h>

namespace peloton {
namespace storage {

BackendFile::BackendFile() {
  if (EnableBackFileType()) {
    // create a big file
    std::ofstream backend_file(file_name, std::ios::binary | std::ios::out);
    backend_file.seekp(file_size - 1);
    backend_file.write("", 1);

    // do mmap
    fd = open(file_name.c_str(), O_RDWR, 0);
    backend_space = (char *) mmap(nullptr, file_size, PROT_READ | PROT_WRITE,
                                  MAP_FILE | MAP_SHARED, fd, 0);
    close(fd);
    assert(backend_space != nullptr);
    // create vmem pool
    vmp = vmem_create_in_region(backend_space, file_size);
    assert(vmp != nullptr);
  }
}

BackendFile::~BackendFile() {
  if (vmp != nullptr) {
    vmem_delete(vmp);
  }
  if (backend_space != nullptr) {
    munmap(backend_space, file_size);
    //remove(file_name.c_str());<commit_msg>Backend file should finish creating file before map it.<commit_after>//===----------------------------------------------------------------------===//
//
//                         PelotonDB
//
// abstract_backend.h
//
// Identification: src/backend/storage/backend_file.cpp
//
// Copyright (c) 2015, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "backend/storage/backend_file.h"
#include "backend/logging/log_manager.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <fstream>
#include <unistd.h>

namespace peloton {
namespace storage {

BackendFile::BackendFile() {
  if (EnableBackFileType()) {
    // create a big file
    std::ofstream backend_file(file_name, std::ios::binary | std::ios::out);
    backend_file.seekp(file_size - 1);
    backend_file.write("", 1);
    backend_file.close();

    // do mmap
    fd = open(file_name.c_str(), O_RDWR, 0);
    backend_space = (char *) mmap(nullptr, file_size, PROT_READ | PROT_WRITE,
                                  MAP_FILE | MAP_SHARED, fd, 0);
    close(fd);
    assert(backend_space != nullptr);
    // create vmem pool
    vmp = vmem_create_in_region(backend_space, file_size);
    assert(vmp != nullptr);
  }
}

BackendFile::~BackendFile() {
  if (vmp != nullptr) {
    vmem_delete(vmp);
  }
  if (backend_space != nullptr) {
    munmap(backend_space, file_size);
    //remove(file_name.c_str());
{'fraction_non_alphanumeric': 0.2408062234794908, 'fraction_numerical': 0.005657708628005658, 'mean_word_length': 2.1363636363636362, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2747751', 'n_tokens_mistral': 905, 'n_tokens_neox': 879, 'n_words': 172}