1
0
Fork 0
arangodb/arangod/Wal/LogfileManager.h

314 lines
12 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// @brief Write-ahead log file manager
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_WAL_LOGFILE_MANAGER_H
#define TRIAGENS_WAL_LOGFILE_MANAGER_H 1
#include "Basics/Common.h"
#include "Basics/Mutex.h"
#include "Basics/ReadWriteLock.h"
#include "Wal/LogEntry.h"
#include "Wal/Logfile.h"
#include <regex.h>
namespace triagens {
namespace wal {
class AllocatorThread;
class CollectorThread;
class Configuration;
// -----------------------------------------------------------------------------
// --SECTION-- class LogfileManager
// -----------------------------------------------------------------------------
class LogfileManager {
friend class AllocatorThread;
friend class CollectorThread;
////////////////////////////////////////////////////////////////////////////////
/// @brief LogfileManager
////////////////////////////////////////////////////////////////////////////////
private:
LogfileManager (LogfileManager const&);
LogfileManager& operator= (LogfileManager const&);
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief create the logfile manager
////////////////////////////////////////////////////////////////////////////////
LogfileManager (Configuration*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the logfile manager
////////////////////////////////////////////////////////////////////////////////
~LogfileManager ();
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief startup the logfile manager
////////////////////////////////////////////////////////////////////////////////
int startup ();
////////////////////////////////////////////////////////////////////////////////
/// @brief shuts down and closes all open logfiles
////////////////////////////////////////////////////////////////////////////////
void shutdown ();
////////////////////////////////////////////////////////////////////////////////
/// @brief reserve space in a log file
////////////////////////////////////////////////////////////////////////////////
LogEntry reserve (size_t);
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief increases the tick value and returns it
////////////////////////////////////////////////////////////////////////////////
LogEntry::TickType nextTick ();
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the last assigned tick
////////////////////////////////////////////////////////////////////////////////
LogEntry::TickType currentTick ();
////////////////////////////////////////////////////////////////////////////////
/// @brief reads the shutdown information
////////////////////////////////////////////////////////////////////////////////
int readShutdownInfo ();
////////////////////////////////////////////////////////////////////////////////
/// @brief writes the shutdown information
////////////////////////////////////////////////////////////////////////////////
int writeShutdownInfo ();
////////////////////////////////////////////////////////////////////////////////
/// @brief start the allocator thread
////////////////////////////////////////////////////////////////////////////////
int startAllocatorThread ();
////////////////////////////////////////////////////////////////////////////////
/// @brief stop the allocator thread
////////////////////////////////////////////////////////////////////////////////
void stopAllocatorThread ();
////////////////////////////////////////////////////////////////////////////////
/// @brief start the collector thread
////////////////////////////////////////////////////////////////////////////////
int startCollectorThread ();
////////////////////////////////////////////////////////////////////////////////
/// @brief stop the collector thread
////////////////////////////////////////////////////////////////////////////////
void stopCollectorThread ();
////////////////////////////////////////////////////////////////////////////////
/// @brief check which logfiles are present in the log directory
////////////////////////////////////////////////////////////////////////////////
int inventory ();
////////////////////////////////////////////////////////////////////////////////
/// @brief open the logfiles in the log directory
////////////////////////////////////////////////////////////////////////////////
int openLogfiles ();
////////////////////////////////////////////////////////////////////////////////
/// @brief reserve space in the logfile directory
////////////////////////////////////////////////////////////////////////////////
int reserveSpace ();
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a new datafile must be allocated
////////////////////////////////////////////////////////////////////////////////
bool shouldAllocate ();
////////////////////////////////////////////////////////////////////////////////
/// @brief total number of bytes allocated in datafiles
////////////////////////////////////////////////////////////////////////////////
uint64_t allocatedSize ();
////////////////////////////////////////////////////////////////////////////////
/// @brief total number of free bytes in already allocated datafiles
////////////////////////////////////////////////////////////////////////////////
uint64_t freeSize ();
////////////////////////////////////////////////////////////////////////////////
/// @brief allocate a new datafile
////////////////////////////////////////////////////////////////////////////////
int allocateDatafile ();
////////////////////////////////////////////////////////////////////////////////
/// @brief run the recovery procedure
////////////////////////////////////////////////////////////////////////////////
int runRecovery ();
////////////////////////////////////////////////////////////////////////////////
/// @brief get an id for the next logfile
////////////////////////////////////////////////////////////////////////////////
Logfile::IdType nextId ();
////////////////////////////////////////////////////////////////////////////////
/// @brief ensure the wal logfiles directory is actually there
////////////////////////////////////////////////////////////////////////////////
int ensureDirectory ();
////////////////////////////////////////////////////////////////////////////////
/// @brief return an absolute filename for a logfile id
////////////////////////////////////////////////////////////////////////////////
std::string logfileName (Logfile::IdType) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief return the absolute name of the shutdown file
////////////////////////////////////////////////////////////////////////////////
std::string shutdownFilename () const;
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief the log file manager configuration
////////////////////////////////////////////////////////////////////////////////
Configuration* _configuration;
////////////////////////////////////////////////////////////////////////////////
/// @brief a lock protecting _tick
////////////////////////////////////////////////////////////////////////////////
basics::ReadWriteLock _tickLock;
////////////////////////////////////////////////////////////////////////////////
/// @brief the last assigned tick
////////////////////////////////////////////////////////////////////////////////
LogEntry::TickType _tick;
////////////////////////////////////////////////////////////////////////////////
/// @brief the allocator thread
////////////////////////////////////////////////////////////////////////////////
AllocatorThread* _allocatorThread;
////////////////////////////////////////////////////////////////////////////////
/// @brief the collector thread
////////////////////////////////////////////////////////////////////////////////
CollectorThread* _collectorThread;
////////////////////////////////////////////////////////////////////////////////
/// @brief a lock protecting the _logfileId value
////////////////////////////////////////////////////////////////////////////////
basics::Mutex _logfileIdLock;
////////////////////////////////////////////////////////////////////////////////
/// @brief last allocated logfile id
////////////////////////////////////////////////////////////////////////////////
Logfile::IdType _logfileId;
////////////////////////////////////////////////////////////////////////////////
/// @brief a lock protecting the _logfiles map
////////////////////////////////////////////////////////////////////////////////
basics::ReadWriteLock _logfilesLock;
////////////////////////////////////////////////////////////////////////////////
/// @brief the logfiles
////////////////////////////////////////////////////////////////////////////////
std::map<Logfile::IdType, Logfile*> _logfiles;
////////////////////////////////////////////////////////////////////////////////
/// @brief logfile directory
////////////////////////////////////////////////////////////////////////////////
std::string const _directory;
////////////////////////////////////////////////////////////////////////////////
/// @brief regex to match logfiles
////////////////////////////////////////////////////////////////////////////////
regex_t _regex;
};
}
}
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End: