mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::db: Move database::options to db::options.
This commit is contained in:
parent
52344457ec
commit
a133235f82
4 changed files with 209 additions and 206 deletions
|
@ -1,56 +0,0 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_DB_DATABASE_OPTIONS_H
|
||||
|
||||
/// options <-> string
|
||||
struct ircd::db::database::options
|
||||
:std::string
|
||||
{
|
||||
struct map;
|
||||
|
||||
// Output of options structures from this string
|
||||
explicit operator rocksdb::Options() const;
|
||||
operator rocksdb::DBOptions() const;
|
||||
operator rocksdb::ColumnFamilyOptions() const;
|
||||
operator rocksdb::PlainTableOptions() const;
|
||||
operator rocksdb::BlockBasedTableOptions() const;
|
||||
|
||||
// Input of options structures output to this string
|
||||
explicit options(const rocksdb::ColumnFamilyOptions &);
|
||||
explicit options(const rocksdb::DBOptions &);
|
||||
explicit options(const database::column &);
|
||||
explicit options(const database &);
|
||||
|
||||
// Input of options string from user
|
||||
options(std::string string)
|
||||
:std::string{std::move(string)}
|
||||
{}
|
||||
};
|
||||
|
||||
/// options <-> map
|
||||
struct ircd::db::database::options::map
|
||||
:std::unordered_map<std::string, std::string>
|
||||
{
|
||||
// Output of options structures from map
|
||||
operator rocksdb::DBOptions() const;
|
||||
operator rocksdb::ColumnFamilyOptions() const;
|
||||
operator rocksdb::PlainTableOptions() const;
|
||||
operator rocksdb::BlockBasedTableOptions() const;
|
||||
|
||||
// Convert option string to map
|
||||
map(const options &);
|
||||
|
||||
// Input of options map from user
|
||||
map(std::unordered_map<std::string, std::string> m)
|
||||
:std::unordered_map<std::string, std::string>{std::move(m)}
|
||||
{}
|
||||
};
|
|
@ -67,7 +67,6 @@ namespace ircd::db
|
|||
#include "descriptor.h"
|
||||
#include "database/rocksdb.h"
|
||||
#include "database/database.h"
|
||||
#include "database/options.h"
|
||||
#include "database/snapshot.h"
|
||||
#include "database/sst.h"
|
||||
#include "database/wal.h"
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace ircd::db
|
|||
enum class set :uint64_t;
|
||||
enum class get :uint64_t;
|
||||
|
||||
struct options;
|
||||
template<class> struct opts;
|
||||
struct sopts;
|
||||
struct gopts;
|
||||
|
@ -64,12 +65,14 @@ struct ircd::db::opts
|
|||
{}
|
||||
};
|
||||
|
||||
/// options for writing (set)
|
||||
struct ircd::db::sopts
|
||||
:opts<set>
|
||||
{
|
||||
using opts<set>::opts;
|
||||
};
|
||||
|
||||
/// options for reading (get)
|
||||
struct ircd::db::gopts
|
||||
:opts<get>
|
||||
{
|
||||
|
@ -82,6 +85,50 @@ struct ircd::db::gopts
|
|||
using opts<get>::opts;
|
||||
};
|
||||
|
||||
/// options <-> string
|
||||
struct ircd::db::options
|
||||
:std::string
|
||||
{
|
||||
struct map;
|
||||
|
||||
// Output of options structures from this string
|
||||
explicit operator rocksdb::Options() const;
|
||||
operator rocksdb::DBOptions() const;
|
||||
operator rocksdb::ColumnFamilyOptions() const;
|
||||
operator rocksdb::PlainTableOptions() const;
|
||||
operator rocksdb::BlockBasedTableOptions() const;
|
||||
|
||||
// Input of options structures output to this string
|
||||
explicit options(const rocksdb::ColumnFamilyOptions &);
|
||||
explicit options(const rocksdb::DBOptions &);
|
||||
explicit options(const database::column &);
|
||||
explicit options(const database &);
|
||||
|
||||
// Input of options string from user
|
||||
options(std::string string)
|
||||
:std::string{std::move(string)}
|
||||
{}
|
||||
};
|
||||
|
||||
/// options <-> map
|
||||
struct ircd::db::options::map
|
||||
:std::unordered_map<std::string, std::string>
|
||||
{
|
||||
// Output of options structures from map
|
||||
operator rocksdb::DBOptions() const;
|
||||
operator rocksdb::ColumnFamilyOptions() const;
|
||||
operator rocksdb::PlainTableOptions() const;
|
||||
operator rocksdb::BlockBasedTableOptions() const;
|
||||
|
||||
// Convert option string to map
|
||||
map(const options &);
|
||||
|
||||
// Input of options map from user
|
||||
map(std::unordered_map<std::string, std::string> m)
|
||||
:std::unordered_map<std::string, std::string>{std::move(m)}
|
||||
{}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
ircd::db::opts<T> &
|
||||
ircd::db::operator&=(opts<T> &a,
|
||||
|
|
311
ircd/db.cc
311
ircd/db.cc
|
@ -1589,7 +1589,7 @@ ircd::db::database::column::column(database &d,
|
|||
db::descriptor &descriptor)
|
||||
:rocksdb::ColumnFamilyDescriptor
|
||||
(
|
||||
descriptor.name, database::options{descriptor.options}
|
||||
descriptor.name, db::options{descriptor.options}
|
||||
)
|
||||
,d{&d}
|
||||
,descriptor{&descriptor}
|
||||
|
@ -10208,6 +10208,165 @@ ircd::db::_seek_(rocksdb::Iterator &it,
|
|||
return it;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// opts.h
|
||||
//
|
||||
|
||||
//
|
||||
// options
|
||||
//
|
||||
|
||||
ircd::db::options::options(const database &d)
|
||||
:options{d.d->GetDBOptions()}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::options::options(const database::column &c)
|
||||
:options
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions
|
||||
{
|
||||
c.d->d->GetOptions(c.handle.get())
|
||||
}
|
||||
}{}
|
||||
|
||||
ircd::db::options::options(const rocksdb::DBOptions &opts)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetStringFromDBOptions(this, opts)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::options::options(const rocksdb::ColumnFamilyOptions &opts)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetStringFromColumnFamilyOptions(this, opts)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::options::operator rocksdb::PlainTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::PlainTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetPlainTableOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::operator rocksdb::BlockBasedTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::BlockBasedTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetBlockBasedTableOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::operator rocksdb::ColumnFamilyOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetColumnFamilyOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::operator rocksdb::DBOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::DBOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetDBOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::operator rocksdb::Options()
|
||||
const
|
||||
{
|
||||
rocksdb::Options ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// options::map
|
||||
//
|
||||
|
||||
ircd::db::options::map::map(const options &o)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::StringToMap(o, this)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::options::map::operator rocksdb::PlainTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::PlainTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetPlainTableOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::map::operator rocksdb::BlockBasedTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::BlockBasedTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetBlockBasedTableOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::map::operator rocksdb::ColumnFamilyOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetColumnFamilyOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::options::map::operator rocksdb::DBOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::DBOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetDBOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// cache.h
|
||||
|
@ -10453,7 +10612,7 @@ std::vector<std::string>
|
|||
ircd::db::column_names(const std::string &path,
|
||||
const std::string &options)
|
||||
{
|
||||
return column_names(path, database::options{options});
|
||||
return column_names(path, db::options{options});
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
|
@ -10479,152 +10638,6 @@ catch(const io_error &e)
|
|||
};
|
||||
}
|
||||
|
||||
ircd::db::database::options::options(const database &d)
|
||||
:options{d.d->GetDBOptions()}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::database::options::options(const database::column &c)
|
||||
:options
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions
|
||||
{
|
||||
c.d->d->GetOptions(c.handle.get())
|
||||
}
|
||||
}{}
|
||||
|
||||
ircd::db::database::options::options(const rocksdb::DBOptions &opts)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetStringFromDBOptions(this, opts)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::database::options::options(const rocksdb::ColumnFamilyOptions &opts)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetStringFromColumnFamilyOptions(this, opts)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::database::options::operator rocksdb::PlainTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::PlainTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetPlainTableOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::operator rocksdb::BlockBasedTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::BlockBasedTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetBlockBasedTableOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::operator rocksdb::ColumnFamilyOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetColumnFamilyOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::operator rocksdb::DBOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::DBOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetDBOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::operator rocksdb::Options()
|
||||
const
|
||||
{
|
||||
rocksdb::Options ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetOptionsFromString(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::map::map(const options &o)
|
||||
{
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::StringToMap(o, this)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::db::database::options::map::operator rocksdb::PlainTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::PlainTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetPlainTableOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::map::operator rocksdb::BlockBasedTableOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::BlockBasedTableOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetBlockBasedTableOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::map::operator rocksdb::ColumnFamilyOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::ColumnFamilyOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetColumnFamilyOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::db::database::options::map::operator rocksdb::DBOptions()
|
||||
const
|
||||
{
|
||||
rocksdb::DBOptions ret;
|
||||
throw_on_error
|
||||
{
|
||||
rocksdb::GetDBOptionsFromMap(ret, *this, &ret)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Misc
|
||||
|
@ -10679,7 +10692,7 @@ ircd::db::make_dbopts(std::string optstr,
|
|||
// Generate RocksDB options from string
|
||||
rocksdb::DBOptions opts
|
||||
{
|
||||
database::options(optstr)
|
||||
db::options(optstr)
|
||||
};
|
||||
|
||||
if(out)
|
||||
|
|
Loading…
Reference in a new issue