| 53 | } |
| 54 | |
| 55 | RocksDBStorageFactory::RocksDBStorageFactory(const char *dbfile, int dbnum, const char *rgchConfig, size_t cchConfig) |
| 56 | : m_path(dbfile) |
| 57 | { |
| 58 | dbnum++; // create an extra db for metadata |
| 59 | // Get the count of column families in the actual database |
| 60 | std::vector<std::string> vecT; |
| 61 | auto status = rocksdb::DB::ListColumnFamilies(rocksdb::Options(), dbfile, &vecT); |
| 62 | // RocksDB requires we know the count of col families before opening, if the user only wants to see less |
| 63 | // we still have to make room for all column family handles regardless |
| 64 | if (status.ok() && (int)vecT.size()/2 > dbnum) |
| 65 | dbnum = (int)vecT.size()/2; |
| 66 | |
| 67 | std::vector<rocksdb::ColumnFamilyDescriptor> veccoldesc; |
| 68 | veccoldesc.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, rocksdb::ColumnFamilyOptions())); // ignore default col family |
| 69 | |
| 70 | m_pfilemanager = std::shared_ptr<rocksdb::SstFileManager>(rocksdb::NewSstFileManager(rocksdb::Env::Default())); |
| 71 | |
| 72 | rocksdb::DB *db = nullptr; |
| 73 | |
| 74 | auto options = RocksDbOptions(); |
| 75 | options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(HASHSLOT_PREFIX_BYTES)); |
| 76 | |
| 77 | for (int idb = 0; idb < dbnum; ++idb) |
| 78 | { |
| 79 | rocksdb::ColumnFamilyOptions cf_options(options); |
| 80 | cf_options.level_compaction_dynamic_level_bytes = true; |
| 81 | veccoldesc.push_back(rocksdb::ColumnFamilyDescriptor(std::to_string(idb), cf_options)); |
| 82 | veccoldesc.push_back(rocksdb::ColumnFamilyDescriptor(std::to_string(idb) + "_expires", cf_options)); |
| 83 | } |
| 84 | |
| 85 | if (rgchConfig != nullptr) |
| 86 | { |
| 87 | std::string options_string(rgchConfig, cchConfig); |
| 88 | rocksdb::Status status; |
| 89 | if (!(status = rocksdb::GetDBOptionsFromString(options, options_string, &options)).ok()) |
| 90 | { |
| 91 | fprintf(stderr, "Failed to parse FLASH options: %s\r\n", status.ToString().c_str()); |
| 92 | exit(EXIT_FAILURE); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | std::vector<rocksdb::ColumnFamilyHandle*> handles; |
| 97 | status = rocksdb::DB::Open(options, dbfile, veccoldesc, &handles, &db); |
| 98 | if (!status.ok()) |
| 99 | throw status.ToString(); |
| 100 | |
| 101 | m_spdb = std::shared_ptr<rocksdb::DB>(db); |
| 102 | for (auto handle : handles) |
| 103 | { |
| 104 | if (handle->GetName().size() > 7 && !strncmp(handle->GetName().substr(handle->GetName().size() - 7).c_str(), "expires", 7)) { |
| 105 | m_vecspexpirecols.emplace_back(handle); |
| 106 | } else { |
| 107 | std::string strVersion; |
| 108 | auto status = m_spdb->Get(rocksdb::ReadOptions(), handle, rocksdb::Slice(version_key, sizeof(version_key)), &strVersion); |
| 109 | if (!status.ok()) |
| 110 | { |
| 111 | setVersion(handle); |
| 112 | } |
nothing calls this directly
no test coverage detected