Пример #1
0
    KyotoCabinetServer(const std::string& directoryName, bool sync, int64_t mmapSizeMb) :
        directoryName_(directoryName),
        sync_(sync),
        mmapSizeMb_(mmapSizeMb) {

        // open all the existing databases
        boost::unique_lock< boost::shared_mutex > writeLock(mutex_);;
        directory_iterator end_itr;
        for (directory_iterator itr(directoryName); itr != end_itr; itr++) {
            if (is_regular_file(itr->status())) {
                std::string mapName = itr->path().leaf().string();
                std::string fileName = itr->path().string();

                // skip hidden files
                if (mapName[0] == '.') {
                    continue;
                }

                TreeDB* db = new TreeDB();
                db->tune_map(mmapSizeMb_ << 20);
                uint32_t flags = BasicDB::OWRITER | BasicDB::OAUTOTRAN;
                if (sync_) {
                    flags |= BasicDB::OAUTOSYNC;
                }
                if (!db->open(fileName, flags)) {
                    printf("ERROR: failed to open '%s'\n", fileName.c_str());
                    exit(1);
                }
                maps_.insert(mapName, db);
                printf("INFO: opened '%s'\n", fileName.c_str());
            }
        }
    }
Пример #2
0
    ResponseCode::type addMap(const std::string& mapName) {
        boost::unique_lock< boost::shared_mutex> writeLock(mutex_);;
        boost::ptr_map<std::string, TreeDB>::iterator itr = maps_.find(mapName);
        if (itr != maps_.end()) {
            return ResponseCode::MapExists;
        }
        TreeDB* db = new TreeDB();
        db->tune_map(mmapSizeMb_ << 20);

        uint32_t flags = BasicDB::OWRITER | BasicDB::OCREATE | BasicDB::OAUTOTRAN;
        if (sync_) {
            flags |= BasicDB::OAUTOSYNC;
        }
        if (!db->open(directoryName_ + "/" + mapName,  flags)) {
            return ResponseCode::Error;
        }
        std::string mapName_ = mapName;
        maps_.insert(mapName_, db);
        return ResponseCode::Success;
    }