2018-01-18 03:14:13 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2019-07-21 00:29:33 +02:00
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
2018-01-18 03:14:13 +01:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
2018-01-19 02:59:22 +01:00
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2018-01-18 03:14:13 +01:00
|
|
|
|
|
|
|
#pragma once
|
2018-01-19 02:59:22 +01:00
|
|
|
#define HAVE_IRCD_DB_DATABASE_SNAPSHOT_H
|
2018-01-18 03:14:13 +01:00
|
|
|
|
2018-01-18 03:34:20 +01:00
|
|
|
// Forward declarations for RocksDB because it is not included here.
|
|
|
|
namespace rocksdb
|
|
|
|
{
|
|
|
|
struct Snapshot;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:47:00 +01:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
2023-02-17 00:59:13 +01:00
|
|
|
uint64_t sequence(const database::snapshot &) noexcept; // Sequence of a snapshot
|
|
|
|
uint64_t sequence(const rocksdb::Snapshot *) noexcept;
|
2019-02-16 01:47:00 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 03:14:13 +01:00
|
|
|
/// Database snapshot object. Maintaining this object will maintain a
|
|
|
|
/// consistent state of access to the database at the sequence number
|
|
|
|
/// from when it's acquired.
|
|
|
|
struct ircd::db::database::snapshot
|
|
|
|
{
|
|
|
|
std::shared_ptr<const rocksdb::Snapshot> s;
|
|
|
|
|
|
|
|
public:
|
2023-02-17 00:59:13 +01:00
|
|
|
operator const rocksdb::Snapshot *() const;
|
2018-01-18 03:14:13 +01:00
|
|
|
|
2023-02-17 00:59:13 +01:00
|
|
|
explicit operator bool() const;
|
|
|
|
bool operator !() const;
|
2018-01-18 03:14:13 +01:00
|
|
|
|
|
|
|
snapshot() = default;
|
2023-02-18 01:45:13 +01:00
|
|
|
explicit snapshot(database &);
|
|
|
|
snapshot(const snapshot &) = default;
|
|
|
|
snapshot &operator=(const snapshot &) = default;
|
2018-01-18 03:14:13 +01:00
|
|
|
~snapshot() noexcept;
|
|
|
|
};
|
2023-02-17 00:59:13 +01:00
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::db::database::snapshot::operator!()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return !s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ircd::db::database::snapshot::operator
|
|
|
|
bool()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return bool(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ircd::db::database::snapshot::operator
|
|
|
|
const rocksdb::Snapshot *()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return s.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t
|
|
|
|
ircd::db::sequence(const database::snapshot &s)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const rocksdb::Snapshot *const rs(s);
|
|
|
|
return sequence(rs);
|
|
|
|
}
|