<commit_before>// Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "io/tablet_io.h"

#include <stdint.h>
#include <gflags/gflags.h>
#include <glog/logging.h>

#include "common/this_thread.h"
#include "io/coding.h"
#include "io/default_compact_strategy.h"
#include "io/io_utils.h"
#include "io/tablet_writer.h"
#include "io/timekey_comparator.h"
#include "io/ttlkv_compact_strategy.h"
#include "io/utils_leveldb.h"
#include "leveldb/cache.h"
#include "leveldb/compact_strategy.h"
#include "leveldb/env.h"
#include "leveldb/env_cache.h"
#include "leveldb/env_dfs.h"
#include "leveldb/env_flash.h"
#include "leveldb/env_inmem.h"
#include "leveldb/filter_policy.h"
#include "types.h"
#include "utils/counter.h"
#include "utils/scan_filter.h"
#include "utils/string_util.h"
#include "utils/timer.h"
#include "utils/utils_cmd.h"

DECLARE_string(tera_leveldb_env_type);
DECLARE_int64(tera_tablet_log_file_size);
DECLARE_int64(tera_tablet_write_buffer_size);
DECLARE_int64(tera_tablet_write_block_size);
DECLARE_int32(tera_tablet_level0_file_limit);
DECLARE_int32(tera_tablet_max_block_log_number);
DECLARE_int64(tera_tablet_write_log_time_out);
DECLARE_bool(tera_log_async_mode);

DECLARE_int64(tera_tablet_living_period);
DECLARE_int32(tera_tablet_flush_log_num);

DECLARE_int32(tera_io_retry_period);
DECLARE_int32(tera_io_retry_max_times);

DECLARE_string(tera_master_meta_table_name);
DECLARE_string(tera_tabletnode_path_prefix);
DECLARE_int32(tera_tabletnode_retry_period);
DECLARE_string(tera_leveldb_compact_strategy);
DECLARE_bool(tera_leveldb_verify_checksums);
DECLARE_bool(tera_leveldb_ignore_corruption_in_compaction);

DECLARE_int32(tera_tabletnode_scan_pack_max_size);
DECLARE_bool(tera_tabletnode_cache_enabled);
DECLARE_int32(tera_leveldb_env_local_seek_latency);
DECLARE_int32(tera_leveldb_env_dfs_seek_latency);
DECLARE_int32(tera_memenv_table_cache_size);
DECLARE_int32(tera_memenv_block_cache_size);

DECLARE_bool(tera_tablet_use_memtable_on_leveldb);
DECLARE_int64(tera_tablet_memtable_ldb_write_buffer_size);
DECLARE_int64(tera_tablet_memtable_ldb_block_size);

extern tera::Counter row_read_delay;

namespace tera {
namespace io {

TabletIO::TabletIO()
    : m_async_writer(NULL),
      m_compact_status(kTableNotCompact),
      m_status(kNotInit),
      m_ref_count(1), m_db_ref_count(0), m_db(NULL),
      m_mem_store_activated(false),
      m_kv_only(false),
      m_key_operator(NULL) {
}

TabletIO::~TabletIO() {
    if (m_status != kNotInit && !Unload()) {
        if (m_async_writer != NULL) {
            m_async_writer->Stop();
            delete m_async_writer;
            m_async_writer = NULL;
        }
        delete m_db;
    }
}

std::string TabletIO::GetTableName() const {
    return m_table_schema.name();
}

std::string TabletIO::GetTablePath() const {
    if (!m_tablet_path.empty()) {
        return m_tablet_path.substr(FLAGS_tera_tabletnode_path_prefix.size());
    } else {
        return m_tablet_path;
    }
}

std::string TabletIO::GetStartKey() const {
    return m_start_key;
}

std::string TabletIO::GetEndKey() const {
    return m_end_key;
}

CompactStatus TabletIO::GetCompactStatus() const {
    MutexLock lock(&m_mutex);
    return m_compact_status;
}

const TableSchema& TabletIO::GetSchema() const {
    return m_table_schema;
}

TabletIO::StatCounter& TabletIO::GetCounter() {
    return m_counter;
}

bool TabletIO::Load(const TableSchema& schema,
                    const std::string& key_start,
                    const std::string& key_end,
                    const std::string& path,
                    const std::vector<uint64_t>& parent_tablets,<commit_msg>Revert "Hold lock in TabletIO::GetCompactStatus()"<commit_after>// Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "io/tablet_io.h"

#include <stdint.h>
#include <gflags/gflags.h>
#include <glog/logging.h>

#include "common/this_thread.h"
#include "io/coding.h"
#include "io/default_compact_strategy.h"
#include "io/io_utils.h"
#include "io/tablet_writer.h"
#include "io/timekey_comparator.h"
#include "io/ttlkv_compact_strategy.h"
#include "io/utils_leveldb.h"
#include "leveldb/cache.h"
#include "leveldb/compact_strategy.h"
#include "leveldb/env.h"
#include "leveldb/env_cache.h"
#include "leveldb/env_dfs.h"
#include "leveldb/env_flash.h"
#include "leveldb/env_inmem.h"
#include "leveldb/filter_policy.h"
#include "types.h"
#include "utils/counter.h"
#include "utils/scan_filter.h"
#include "utils/string_util.h"
#include "utils/timer.h"
#include "utils/utils_cmd.h"

DECLARE_string(tera_leveldb_env_type);
DECLARE_int64(tera_tablet_log_file_size);
DECLARE_int64(tera_tablet_write_buffer_size);
DECLARE_int64(tera_tablet_write_block_size);
DECLARE_int32(tera_tablet_level0_file_limit);
DECLARE_int32(tera_tablet_max_block_log_number);
DECLARE_int64(tera_tablet_write_log_time_out);
DECLARE_bool(tera_log_async_mode);

DECLARE_int64(tera_tablet_living_period);
DECLARE_int32(tera_tablet_flush_log_num);

DECLARE_int32(tera_io_retry_period);
DECLARE_int32(tera_io_retry_max_times);

DECLARE_string(tera_master_meta_table_name);
DECLARE_string(tera_tabletnode_path_prefix);
DECLARE_int32(tera_tabletnode_retry_period);
DECLARE_string(tera_leveldb_compact_strategy);
DECLARE_bool(tera_leveldb_verify_checksums);
DECLARE_bool(tera_leveldb_ignore_corruption_in_compaction);

DECLARE_int32(tera_tabletnode_scan_pack_max_size);
DECLARE_bool(tera_tabletnode_cache_enabled);
DECLARE_int32(tera_leveldb_env_local_seek_latency);
DECLARE_int32(tera_leveldb_env_dfs_seek_latency);
DECLARE_int32(tera_memenv_table_cache_size);
DECLARE_int32(tera_memenv_block_cache_size);

DECLARE_bool(tera_tablet_use_memtable_on_leveldb);
DECLARE_int64(tera_tablet_memtable_ldb_write_buffer_size);
DECLARE_int64(tera_tablet_memtable_ldb_block_size);

extern tera::Counter row_read_delay;

namespace tera {
namespace io {

TabletIO::TabletIO()
    : m_async_writer(NULL),
      m_compact_status(kTableNotCompact),
      m_status(kNotInit),
      m_ref_count(1), m_db_ref_count(0), m_db(NULL),
      m_mem_store_activated(false),
      m_kv_only(false),
      m_key_operator(NULL) {
}

TabletIO::~TabletIO() {
    if (m_status != kNotInit && !Unload()) {
        if (m_async_writer != NULL) {
            m_async_writer->Stop();
            delete m_async_writer;
            m_async_writer = NULL;
        }
        delete m_db;
    }
}

std::string TabletIO::GetTableName() const {
    return m_table_schema.name();
}

std::string TabletIO::GetTablePath() const {
    if (!m_tablet_path.empty()) {
        return m_tablet_path.substr(FLAGS_tera_tabletnode_path_prefix.size());
    } else {
        return m_tablet_path;
    }
}

std::string TabletIO::GetStartKey() const {
    return m_start_key;
}

std::string TabletIO::GetEndKey() const {
    return m_end_key;
}

CompactStatus TabletIO::GetCompactStatus() const {
    return m_compact_status;
}

const TableSchema& TabletIO::GetSchema() const {
    return m_table_schema;
}

TabletIO::StatCounter& TabletIO::GetCounter() {
    return m_counter;
}

bool TabletIO::Load(const TableSchema& schema,
                    const std::string& key_start,
                    const std::string& key_end,
                    const std::string& path,
                    const std::vector<uint64_t>& parent_tablets,
{'fraction_non_alphanumeric': 0.10830999066293184, 'fraction_numerical': 0.012004801920768308, 'mean_word_length': 5.688670829616414, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6051126', 'n_tokens_mistral': 2871, 'n_tokens_neox': 2748, 'n_words': 395}