1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 /******************************************************************************
19  * $Id: blockresolutionmanager.h 1825 2013-01-24 18:41:00Z pleblanc $
20  *
21  *****************************************************************************/
22 
23 /** @file
24  * class BlockResolutionManager
25  */
26 
27 #ifndef BLOCKRESOLUTIONMANAGER_H_
28 #define BLOCKRESOLUTIONMANAGER_H_
29 
30 #include <sys/types.h>
31 #include <vector>
32 #include <set>
33 
34 #include "brmtypes.h"
35 #include "mastersegmenttable.h"
36 #include "extentmap.h"
37 #include "vbbm.h"
38 #include "vss.h"
39 #include "copylocks.h"
40 
41 #if defined(_MSC_VER) && defined(xxxBLOCKRESOLUTIONMANAGER_DLLEXPORT)
42 #define EXPORT __declspec(dllexport)
43 #else
44 #define EXPORT
45 #endif
46 
47 namespace BRM
48 {
49 
50 /** @brief The BlockResolutionManager manages the Logical Block ID space.
51  *
52  * The BlockResolutionManager manages the Logical Block ID space.  Its
53  * primary use is to translate <LBID, VerID, VBFlag> triples
54  * to <OID, FBO> pairs and vice-versa.
55  *
56  * @note This class will be used by C code, so it should not throw exceptions.
57  */
58 class BlockResolutionManager
59 {
60 public:
61     EXPORT explicit BlockResolutionManager(bool ronly = false) throw();
62     EXPORT ~BlockResolutionManager() throw();
63 
64     /** @brief Persistence API.  Loads the local Extent Map from a file.
65      *
66      * Persistence API.  Loads the <b>local</b> Extent Map from a file.
67      *
68      * @warning The load must be done on each slave node atomically wrt
69      * writing operations, otherwise nodes may be out of synch.
70      * @param filename Relative or absolute path to a file saved with saveExtentMap.
71      * @return 0, throws if EM throws
72      */
73     EXPORT int loadExtentMap(const std::string& filename, bool fixFL);
74 
75     /** @brief Persistence API.  Saves the local Extent Map to a file.
76      *
77      * Persistence API.  Saves the <b>local</b> Extent Map to a file.
78      *
79      * @param filename Relative or absolute path to save to.
80      * @return 0 on success, throws if EM throws
81      */
82     EXPORT int saveExtentMap(const std::string& filename);
83 
84     /** @brief Persistence API.  Loads all BRM snapshots.
85      *
86      * Loads all <b>local</b> BRM structures from files saved with saveState().
87      *
88      * @warning The load must be done on each slave node atomically wrt
89      * writing operations, otherwise nodes may be out of synch.
90      * @param filename The filename prefix to use.  Loads 4 files with that prefix.
91      * @return 0 on success, -1 on error
92      */
93     EXPORT int loadState(std::string filename, bool fixFL = false) throw();
94 
95     /** @brief Persistence API.  Loads the BRM deltas since the last snapshot.
96      *
97      * Loads all <b>local</b> BRM structures from files saved with saveState().
98      *
99      * @warning The load must be done on each slave node atomically wrt
100      * writing operations, otherwise nodes may be out of synch.
101      * @param filename The filename prefix to use.  Loads 4 files with that prefix.
102      * @return 0 on success, -1 on error
103      */
104     EXPORT int replayJournal(std::string filename) throw();
105 
106     /** @brief Persistence API.  Saves all BRM structures.
107      *
108      * Saves all <b>local</b> BRM structures to files.
109      *
110      * @param filename The filename prefix to use.  Saves 4 files with that prefix.
111      * @return 0 on success, -1 on error
112      */
113     EXPORT int saveState(std::string filename) throw();
114 
115 private:
116     explicit BlockResolutionManager(const BlockResolutionManager& brm);
117     BlockResolutionManager& operator=(const BlockResolutionManager& brm);
118     MasterSegmentTable mst;
119     ExtentMap em;
120     VBBM vbbm;
121     VSS vss;
122     CopyLocks copylocks;
123 
124 };
125 
126 }
127 
128 #undef EXPORT
129 
130 #endif
131