LineairDB  0.1.0
database.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Nippon Telegraph and Telephone Corporation.
3 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7 
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LINEAIRDB_DATABASE_H
18 #define LINEAIRDB_DATABASE_H
19 
20 #include <lineairdb/transaction.h>
21 
22 #include <functional>
23 #include <memory>
24 #include <optional>
25 
26 #include "config.h"
27 #include "tx_status.h"
28 
29 namespace LineairDB {
30 
31 class Database {
32  public:
37  Database() noexcept;
38 
43  Database(const Config& config) noexcept;
44 
45  ~Database() noexcept;
46  Database(const Database&) = delete;
47  Database& operator=(const Database&) = delete;
48  Database(Database&&) = delete;
49  Database& operator=(Database&&) = delete;
50 
57  const Config GetConfig() const noexcept;
58 
59  using ProcedureType = std::function<void(Transaction&)>;
60  using CallbackType = std::function<void(const TxStatus)>;
79  void ExecuteTransaction(
80  ProcedureType proc, CallbackType commit_clbk,
81  std::optional<CallbackType> precommit_clbk = std::nullopt);
82 
97 
117  bool EndTransaction(Transaction& tx, CallbackType clbk);
118 
129  void Fence() const noexcept;
130 
141  void WaitForCheckpoint() const noexcept;
142 
151  void RequestCallbacks();
152 
153  private:
154  class Impl;
155  const std::unique_ptr<Impl> db_pimpl_;
156  friend class Transaction;
157 };
158 
159 }; // namespace LineairDB
160 
161 #endif
LineairDB::TxStatus
TxStatus
Definition: tx_status.h:25
transaction.h
LineairDB::Database::CallbackType
std::function< void(const TxStatus)> CallbackType
Definition: database.h:60
LineairDB::Config
Configuration and options for LineairDB instances.
Definition: config.h:30
LineairDB::Database::RequestCallbacks
void RequestCallbacks()
Requests executions of callback functions of already completed (committed or (aborted) transactions....
LineairDB::Database::~Database
~Database() noexcept
LineairDB::Database::Fence
void Fence() const noexcept
Fence() waits termination of transactions which is currently in progress. You can execute transaction...
LineairDB::Database::ExecuteTransaction
void ExecuteTransaction(ProcedureType proc, CallbackType commit_clbk, std::optional< CallbackType > precommit_clbk=std::nullopt)
Processes a transaction given by a transaction procedure proc, and afterwards process callback functi...
LineairDB::Database
Definition: database.h:31
LineairDB::Database::ProcedureType
std::function< void(Transaction &)> ProcedureType
Definition: database.h:59
LineairDB::Database::GetConfig
const Config GetConfig() const noexcept
Return the Config object set by constructor.
LineairDB::Database::operator=
Database & operator=(const Database &)=delete
LineairDB::Transaction
We adopt "the page model" [Vossen95] as the model of transaction processing. For each transaction,...
Definition: transaction.h:51
LineairDB
Definition: config.h:24
LineairDB::Database::Database
Database() noexcept
Construct a new Database object. Thread-safe. Note that a default-constructed Config object will be p...
config.h
LineairDB::Database::EndTransaction
bool EndTransaction(Transaction &tx, CallbackType clbk)
Terminates the transaction. If Transaction::Abort has not been called, LineairDB tries to commit tx.
LineairDB::Database::WaitForCheckpoint
void WaitForCheckpoint() const noexcept
WaitForCheckpoint Waits for the completion of the next checkpoint. Note that this method may take lon...
LineairDB::Database::BeginTransaction
Transaction & BeginTransaction()
Creates a new transaction. Via this interface, the callee thread of this method can manipulate Lineai...
tx_status.h