libfoedus-core
FOEDUS Core Library
storage_manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
19 
20 #include <string>
21 
31 
32 namespace foedus {
33 namespace storage {
34 StorageManager::StorageManager(Engine* engine) : pimpl_(nullptr) {
35  pimpl_ = new StorageManagerPimpl(engine);
36 }
38  delete pimpl_;
39  pimpl_ = nullptr;
40 }
41 
42 Engine* StorageManager::get_engine() const { return pimpl_->engine_; }
44 bool StorageManager::is_initialized() const { return pimpl_->is_initialized(); }
46 
48  return pimpl_->get_storage(id);
49 }
51  return pimpl_->get_storage(name);
52 }
53 
56  return pimpl_->control_block_->largest_storage_id_;
57 }
58 
61  StorageControlBlock* block = get_storage(id);
62  if (block->exists()) {
63  return block->meta_.name_;
64  } else {
65  return kEmptyString;
66  }
67 }
68 
70  return pimpl_->drop_storage(id, commit_epoch);
71 }
73  pimpl_->drop_storage_apply(id);
74 }
75 
77  return pimpl_->create_storage(metadata, commit_epoch);
78 }
80  pimpl_->create_storage_apply(metadata);
81 }
82 
84  array::ArrayMetadata* metadata,
85  array::ArrayStorage* storage,
86  Epoch* commit_epoch) {
87  CHECK_ERROR(create_storage(metadata, commit_epoch));
88  *storage = get_array(metadata->id_);
89  return kRetOk;
90 }
91 
93  hash::HashMetadata* metadata,
94  hash::HashStorage* storage,
95  Epoch* commit_epoch) {
96  CHECK_ERROR(create_storage(metadata, commit_epoch));
97  *storage = get_hash(metadata->id_);
98  return kRetOk;
99 }
100 
104  Epoch* commit_epoch) {
105  CHECK_ERROR(create_storage(metadata, commit_epoch));
106  *storage = get_sequential(metadata->id_);
107  return kRetOk;
108 }
109 
111  masstree::MasstreeMetadata* metadata,
112  masstree::MasstreeStorage* storage,
113  Epoch* commit_epoch) {
114  CHECK_ERROR(create_storage(metadata, commit_epoch));
115  *storage = get_masstree(metadata->id_);
116  return kRetOk;
117 }
118 
120  return pimpl_->clone_all_storage_metadata(metadata);
121 }
122 
123 } // namespace storage
124 } // namespace foedus
Represents the data in one snapshot metadata file.
Metadata meta_
common part of the metadata.
Definition: storage.hpp:84
ErrorStack drop_storage(StorageId id, Epoch *commit_epoch)
sequential::SequentialStorage get_sequential(StorageId id)
Returns the sequential storage of given ID.
ErrorStack drop_storage(StorageId id, Epoch *commit_epoch)
Removes the storage object.
ErrorStack create_hash(hash::HashMetadata *metadata, hash::HashStorage *storage, Epoch *commit_epoch)
Just a type-wrapper of create_storage() for hash storages.
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents a key-value store based on a dense and regular array.
ErrorStack initialize() override
Acquires resources in this object, usually called right after constructor.
ErrorStack create_sequential(sequential::SequentialMetadata *metadata, sequential::SequentialStorage *storage, Epoch *commit_epoch)
Just a type-wrapper of create_storage() for sequential storages.
array::ArrayStorage get_array(StorageId id)
Returns the array storage of given ID.
StorageManagerControlBlock * control_block_
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...
StorageId largest_storage_id_
The largest StorageId we so far observed.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents a time epoch.
Definition: epoch.hpp:61
ErrorStack clone_all_storage_metadata(snapshot::SnapshotMetadata *metadata)
This method is called during snapshotting to clone metadata of all existing storages to the given obj...
ErrorStack create_masstree(masstree::MasstreeMetadata *metadata, masstree::MasstreeStorage *storage, Epoch *commit_epoch)
Just a type-wrapper of create_storage() for masstree storages.
void create_storage_apply(const Metadata &metadata)
This is called while restart to apply CREATE STORAGE logs.
masstree::MasstreeStorage get_masstree(StorageId id)
Returns the masstree storage of given ID.
Metadata of one storage.
Definition: metadata.hpp:58
Represents an append/scan-only store.
StorageId issue_next_storage_id()
Issue a unique and atomically/monotonically increasing storage ID for a new storage.
StorageControlBlock * get_storage(StorageId id)
void create_storage_apply(const Metadata &metadata)
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
bool is_initialized() const override
Returns whether the object has been already initialized or not.
const StorageName kEmptyString
StorageName name_
the unique name of this storage.
Definition: metadata.hpp:107
Metadata of an array storage.
ErrorStack create_array(array::ArrayMetadata *metadata, array::ArrayStorage *storage, Epoch *commit_epoch)
Just a type-wrapper of create_storage() for array storages.
Pimpl object of StorageManager.
Represents a key-value store based on a dense and regular hash.
StorageId get_largest_storage_id()
Returns the largest StorageId that does or did exist.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
ErrorStack uninitialize() override
An idempotent method to release all resources of this object, if any.
const ErrorStack kRetOk
Normal return value for no-error case.
ErrorStack create_storage(Metadata *metadata, Epoch *commit_epoch)
Newly creates a storage with the specified metadata and registers it to this manager.
Metadata of an hash storage.
const StorageName & get_name(StorageId id)
Returns the name of the given storage ID.
hash::HashStorage get_hash(StorageId id)
Returns the hash storage of given ID.
void drop_storage_apply(StorageId id)
This is called while restart to apply DROP STORAGE logs.
StorageControlBlock * get_storage(StorageId id)
Returns the storage of given ID.
A base layout of shared data for all storage types.
Definition: storage.hpp:53
StorageId id_
the unique ID of this storage.
Definition: metadata.hpp:103
bool is_initialized() const override final
Returns whether the object has been already initialized or not.
ErrorStack clone_all_storage_metadata(snapshot::SnapshotMetadata *metadata)
ErrorStack create_storage(Metadata *metadata, Epoch *commit_epoch)