<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.
//
// Author: <EMAIL>

#include "namespace.h"

#include <fcntl.h>
#include <gflags/gflags.h>
#include <leveldb/db.h>
#include <leveldb/cache.h>
#include <leveldb/write_batch.h>
#include <common/logging.h>
#include <common/timer.h>
#include <common/util.h>
#include <common/atomic.h>
#include <common/string_util.h>
#include <boost/bind.hpp>

#include "nameserver/sync.h"

DECLARE_string(namedb_path);
DECLARE_int64(namedb_cache_size);
DECLARE_int32(default_replica_num);
DECLARE_int32(block_id_allocation_size);

const int64_t kRootEntryid = 1;


namespace baidu {
namespace bfs {

NameSpace::NameSpace(bool standalone): version_(0), last_entry_id_(1),
    block_id_upbound_(1), next_block_id_(1) {
    leveldb::Options options;
    options.create_if_missing = true;
    options.block_cache = leveldb::NewLRUCache(FLAGS_namedb_cache_size*1024L*1024L);
    leveldb::Status s = leveldb::DB::Open(options, FLAGS_namedb_path, &db_);
    if (!s.ok()) {
        db_ = NULL;
        LOG(FATAL, "Open leveldb fail: %s\n", s.ToString().c_str());
        return;
    }
    if (standalone) {
        //only unit test can get here, so nameserver_impl doesn't exists, dont' use any callback
        //which could touch namserver_impl or blockmapping or anything else
        Activate(NULL, NULL);
    }
}

void NameSpace::Activate(boost::function<void (const FileInfo&)> callback, NameServerLog* log) {
    std::string version_key(8, 0);
    version_key.append("version");
    std::string version_str;<commit_msg>Fix comment<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.
//
// Author: <EMAIL>

#include "namespace.h"

#include <fcntl.h>
#include <gflags/gflags.h>
#include <leveldb/db.h>
#include <leveldb/cache.h>
#include <leveldb/write_batch.h>
#include <common/logging.h>
#include <common/timer.h>
#include <common/util.h>
#include <common/atomic.h>
#include <common/string_util.h>
#include <boost/bind.hpp>

#include "nameserver/sync.h"

DECLARE_string(namedb_path);
DECLARE_int64(namedb_cache_size);
DECLARE_int32(default_replica_num);
DECLARE_int32(block_id_allocation_size);

const int64_t kRootEntryid = 1;


namespace baidu {
namespace bfs {

NameSpace::NameSpace(bool standalone): version_(0), last_entry_id_(1),
    block_id_upbound_(1), next_block_id_(1) {
    leveldb::Options options;
    options.create_if_missing = true;
    options.block_cache = leveldb::NewLRUCache(FLAGS_namedb_cache_size*1024L*1024L);
    leveldb::Status s = leveldb::DB::Open(options, FLAGS_namedb_path, &db_);
    if (!s.ok()) {
        db_ = NULL;
        LOG(FATAL, "Open leveldb fail: %s\n", s.ToString().c_str());
        return;
    }
    if (standalone) {
        //only unit test can get here, so nameserver_impl doesn't exists,
        //don't use any callback which could touch namserver_impl or
        //blockmapping or anything else
        Activate(NULL, NULL);
    }
}

void NameSpace::Activate(boost::function<void (const FileInfo&)> callback, NameServerLog* log) {
    std::string version_key(8, 0);
    version_key.append("version");
    std::string version_str;
{'fraction_non_alphanumeric': 0.1325014854426619, 'fraction_numerical': 0.016042780748663103, 'mean_word_length': 4.361464968152866, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7192299', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1161, 'n_words': 272}