DBParameterSetterImpl(DB *db, const string &name, T value, db_getter_fun get, db_setter_fun set) : _db(db), _name(name), _value(value), _get(get), _set(set), _didSet(false), _shouldUnset(true) { int r = _get(_db, &_oldValue); if (r != 0) { problem() << "error getting parameter " << _name << endl; handle_ydb_error(r); } if (_oldValue == _value) { return; } r = _set(_db, _value); if (r != 0) { problem() << "error setting parameter " << _name << endl; handle_ydb_error(r); } _didSet = true; }
Dictionary::Dictionary(const string &dname, const BSONObj &info, const mongo::Descriptor &descriptor, const bool may_create, const bool hot_index) : _dname(dname), _db(NULL) { const int r = db_create(&_db, env, 0); if (r != 0) { handle_ydb_error(r); } try { open(info, descriptor, may_create, hot_index); } catch (...) { close(); throw; } }
Loader::Loader(DB **dbs, const int n) : _dbs(dbs), _n(n), _loader(NULL), _closed(false) { uint32_t db_flags = 0; uint32_t dbt_flags = 0; const int loader_flags = 0; int r = storage::env->create_loader(storage::env, cc().txn().db_txn(), &_loader, _dbs[0], _n, _dbs, &db_flags, &dbt_flags, loader_flags); if (r != 0) { handle_ydb_error(r); } r = _loader->set_poll_function(_loader, BuilderBase::poll_function, &_poll_extra); if (r != 0) { handle_ydb_error_fatal(r); } r = _loader->set_error_callback(_loader, BuilderBase::error_callback, &_error_extra); if (r != 0) { handle_ydb_error_fatal(r); } }
void Dictionary::open(const BSONObj &info, const mongo::Descriptor &descriptor, const bool may_create, const bool hot_index) { int readPageSize = 65536; int pageSize = 4 * 1024 * 1024; TOKU_COMPRESSION_METHOD compression = TOKU_ZLIB_WITHOUT_CHECKSUM_METHOD; BSONObj key_pattern = info["key"].Obj(); BSONElement e; e = info["readPageSize"]; if (e.ok() && !e.isNull()) { readPageSize = BytesQuantity<int>(e); uassert(16743, "readPageSize must be a number > 0.", readPageSize > 0); TOKULOG(1) << "db " << _dname << ", using read page size " << readPageSize << endl; } e = info["pageSize"]; if (e.ok() && !e.isNull()) { pageSize = BytesQuantity<int>(e); uassert(16445, "pageSize must be a number > 0.", pageSize > 0); TOKULOG(1) << "db " << _dname << ", using page size " << pageSize << endl; } e = info["compression"]; if (e.ok() && !e.isNull()) { std::string str = e.String(); if (str == "lzma") { compression = TOKU_LZMA_METHOD; } else if (str == "quicklz") { compression = TOKU_QUICKLZ_METHOD; } else if (str == "zlib") { compression = TOKU_ZLIB_WITHOUT_CHECKSUM_METHOD; } else if (str == "none") { compression = TOKU_NO_COMPRESSION; } else { uassert(16442, "compression must be one of: lzma, quicklz, zlib, none.", false); } TOKULOG(1) << "db " << _dname << ", using compression method \"" << str << "\"" << endl; } int r = _db->set_readpagesize(_db, readPageSize); if (r != 0) { handle_ydb_error(r); } r = _db->set_pagesize(_db, pageSize); if (r != 0) { handle_ydb_error(r); } r = _db->set_compression_method(_db, compression); if (r != 0) { handle_ydb_error(r); } // If this is a non-creating open for a read-only (or non-existent) // transaction, we can use an alternate stack since there's nothing // to roll back and no locktree locks to hold. const bool needAltTxn = !may_create && (!cc().hasTxn() || cc().txn().readOnly()); scoped_ptr<Client::AlternateTransactionStack> altStack(!needAltTxn ? NULL : new Client::AlternateTransactionStack()); scoped_ptr<Client::Transaction> altTxn(!needAltTxn ? NULL : new Client::Transaction(0)); const int db_flags = may_create ? DB_CREATE : 0; r = _db->open(_db, cc().txn().db_txn(), _dname.c_str(), NULL, DB_BTREE, db_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (r == ENOENT && !may_create) { throw NeedsCreate(); } if (r != 0) { handle_ydb_error(r); } if (may_create) { set_db_descriptor(_db, descriptor, hot_index); } verify_or_upgrade_db_descriptor(_db, descriptor, hot_index); if (altTxn.get() != NULL) { altTxn->commit(); } }