Database.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/db/Database.h#21 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_Database_Included
00025 #define Fennel_Database_Included
00026 
00027 #include "fennel/device/DeviceMode.h"
00028 #include "fennel/common/TraceSource.h"
00029 #include "fennel/common/StatsSource.h"
00030 #include "fennel/common/ConfigMap.h"
00031 #include "fennel/common/ClosableObject.h"
00032 #include "fennel/db/DatabaseHeader.h"
00033 #include "fennel/tuple/StandardTypeDescriptor.h"
00034 #include "fennel/segment/SegmentMap.h"
00035 #include "fennel/synch/SynchMonitoredObject.h"
00036 
00037 #include <boost/utility.hpp>
00038 
00039 FENNEL_BEGIN_NAMESPACE
00040 
00041 class LogicalTxnParticipantFactory;
00042 class VersionedSegment;
00043 class LinearDeviceSegmentParams;
00044 
00049 class FENNEL_DB_EXPORT Database
00050     : public boost::noncopyable,
00051         public ClosableObject,
00052         public TraceSource,
00053         public SegmentMap,
00054         public StatsSource,
00055         public SynchMonitoredObject
00056 {
00057     DeviceId dataDeviceId;
00058 
00059     SharedRandomAccessDevice pDataDevice;
00060 
00061     DeviceId tempDeviceId;
00062 
00063     DeviceId shadowDeviceId;
00064 
00065     DeviceId txnLogDeviceId;
00066 
00067     std::string dataDeviceName;
00068 
00069     std::string tempDeviceName;
00070 
00071     std::string shadowDeviceName;
00072 
00073     std::string txnLogDeviceName;
00074 
00075     SharedCache pCache;
00076 
00077     SharedSegmentFactory pSegmentFactory;
00078 
00079     SharedSegment pHeaderSegment;
00080 
00081     SharedSegment pDataSegment;
00082 
00083     SharedSegment pTempSegment;
00084 
00085     VersionedSegment *pVersionedSegment;
00086 
00087     SharedLogicalTxnLog pTxnLog;
00088 
00089     PageId headerPageId1;
00090 
00091     PageId headerPageId2;
00092 
00093     DatabaseHeader header;
00094 
00095     LogicalTxnParticipantFactory *pTxnParticipantFactory;
00096 
00097     bool forceTxns;
00098 
00099     bool disableSnapshots;
00100 
00101     bool recoveryRequired;
00102 
00103     DeviceMode openMode;
00104 
00105     ConfigMap configMap;
00106 
00107     StandardTypeDescriptorFactory typeFactory;
00108 
00109     SharedCheckpointThread pCheckpointThread;
00110 
00111     SharedPseudoUuidGenerator pUuidGenerator;
00112 
00116     uint nCheckpointsStat;
00117 
00121     uint nCheckpoints;
00122 
00126     bool disableDeallocateOld;
00127 
00131     SharedSegPageBackupRestoreDevice pBackupRestoreDevice;
00132 
00136     SegmentAccessor scratchAccessor;
00137 
00138     explicit Database(
00139         SharedCache pCache,
00140         ConfigMap const &configMap,
00141         DeviceMode openMode,
00142         SharedTraceTarget pTraceTarget,
00143         SharedPseudoUuidGenerator pUuidGenerator);
00144 
00145     // implement ClosableObject
00146     virtual void closeImpl();
00147 
00148 // ----------------------------------------------------------------------
00149 // internal helper methods
00150 // ----------------------------------------------------------------------
00151 
00152     void init();
00153 
00154     void createTxnLog(DeviceMode);
00155 
00156     SharedSegment createTxnLogSegment(DeviceMode,PageId);
00157 
00158     SharedSegment createShadowLog(DeviceMode);
00159 
00160     void createDataDevice(LinearDeviceSegmentParams &);
00161 
00162     void createDataSegment(SharedSegment, LinearDeviceSegmentParams &);
00163 
00164     void createTempSegment();
00165 
00166     void allocateHeader();
00167 
00168     void writeHeader();
00169 
00170     void loadHeader(bool);
00171 
00172     void closeDevices();
00173 
00174     void deleteLogs();
00175 
00176     void openSegments();
00177 
00178     void prepareForRecovery();
00179 
00180     void recoverPhysical(CheckpointType);
00181 
00182     void readDeviceParams(
00183         std::string paramNamePrefix,
00184         DeviceMode deviceMode,
00185         LinearDeviceSegmentParams &deviceParams);
00186 
00187     void cleanupBackupRestore(bool isBackup);
00188 
00189 public:
00190     static ParamName paramDatabaseDir;
00191     static ParamName paramResourceDir;
00192     static ParamName paramForceTxns;
00193     static ParamName paramDisableSnapshots;
00194     static ParamName paramDatabasePrefix;
00195     static ParamName paramTempPrefix;
00196     static ParamName paramShadowLogPrefix;
00197     static ParamName paramTxnLogPrefix;
00198     static ParamName paramInitSizeSuffix;
00199     static ParamName paramMaxSizeSuffix;
00200     static ParamName paramIncSizeSuffix;
00201 
00202     static ParamVal valLogAllocLinear;
00203     static ParamVal valLogAllocCircular;
00204 
00205     static const SegmentId DEFAULT_DATA_SEGMENT_ID;
00206     static const SegmentId TEMP_SEGMENT_ID;
00207 
00208     static SharedDatabase newDatabase(
00209         SharedCache pCache,
00210         ConfigMap const &configMap,
00211         DeviceMode openMode,
00212         SharedTraceTarget pTraceTarget,
00213         SharedPseudoUuidGenerator pUuidGenerator = SharedPseudoUuidGenerator());
00214 
00215     virtual ~Database();
00216 
00217     const ConfigMap& getConfigMap() const;
00218 
00219     SharedCache getCache() const;
00220 
00221     SharedSegmentFactory getSegmentFactory() const;
00222 
00223     SharedSegment getDataSegment() const;
00224 
00225     SharedSegment getTempSegment() const;
00226 
00227     SharedCheckpointThread getCheckpointThread() const;
00228 
00229     // implement SegmentMap
00230     virtual SharedSegment getSegmentById(
00231         SegmentId segmentId,
00232         SharedSegment pDataSegment);
00233 
00234     // implement StatsSource
00235     virtual void writeStats(StatsTarget &target);
00236 
00237     SharedLogicalTxnLog getTxnLog() const;
00238 
00239     StoredTypeDescriptorFactory const &getTypeFactory() const;
00240 
00241     bool isRecoveryRequired() const;
00242 
00243     bool shouldForceTxns() const;
00244 
00245     bool areSnapshotsEnabled() const;
00246 
00247     void recoverOnline();
00248 
00249     void recover(
00250         LogicalTxnParticipantFactory &txnParticipantFactory);
00251 
00252     void checkpointImpl(CheckpointType = CHECKPOINT_FLUSH_ALL);
00253 
00263     void requestCheckpoint(
00264         CheckpointType checkpointType,
00265         bool async);
00266 
00275     void deallocateOldPages(TxnId oldestLabelCsn);
00276 
00282     void setLastCommittedTxnId(TxnId txnId);
00283 
00287     TxnId getLastCommittedTxnId();
00288 
00311     TxnId initiateBackup(
00312         const std::string &backupFilePathname,
00313         bool checkSpaceRequirements,
00314         FileSize spacePadding,
00315         TxnId lowerBoundCsn,
00316         const std::string &compressionProgram,
00317         FileSize &dataDeviceSize,
00318         const volatile bool &aborted);
00319 
00332     void completeBackup(
00333         TxnId lowerBoundCsn,
00334         TxnId upperBoundCsn,
00335         const volatile bool &aborted);
00336 
00343     void abortBackup();
00344 
00363     void restoreFromBackup(
00364         const std::string &backupFilePathname,
00365         FileSize newSize,
00366         const std::string &compressionProgram,
00367         TxnId lowerBoundCsn,
00368         TxnId upperBoundCsn,
00369         const volatile bool &aborted);
00370 };
00371 
00372 FENNEL_END_NAMESPACE
00373 
00374 #endif
00375 
00376 // End Database.h

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1