Drizzled Public API Documentation

temp_log_ms.h

00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-07-03
00023  *
00024  * H&G2JCtL
00025  *
00026  * Temporary BLOB log.
00027  *
00028  * Temporary BLOBs are BLOBs that are to be deleted after an certain
00029  * expiry time.
00030  *
00031  * The temporary log is also used to schedule asynchronous operations to be performed
00032  * on the BLOB such as uploading it to a cloud.
00033  *
00034  * Temporary BLOBs are referenced by the temporary log.
00035  */
00036 
00037 #pragma once
00038 #ifndef __TEMPLOG_MS_H__
00039 #define __TEMPLOG_MS_H__
00040 
00041 #include "cslib/CSDefs.h"
00042 #include "cslib/CSFile.h"
00043 #include "cslib/CSStream.h"
00044 
00045 #include "defs_ms.h"
00046 
00047 class MSOpenTable;
00048 class MSDatabase;
00049 class MSTempLog;
00050 
00051 // Change history:
00052 // April 6 2009:
00053 // Changed MS_TEMP_LOG_MAGIC and MS_TEMP_LOG_VERSION
00054 // when the disk size of ti_type_1 was changed from
00055 // CSDiskValue4 to CSDiskValue1.
00056 
00057 #define MS_TEMP_LOG_MAGIC     0xF9E6D7C9
00058 #define MS_TEMP_LOG_VERSION     3
00059 #define MS_TEMP_LOG_HEAD_SIZE   32
00060 
00061 #define MS_TL_BLOB_REF        1
00062 #define MS_TL_REPO_REF        2   
00063 #define MS_TL_TABLE_REF       3
00064 
00065 typedef struct MSTempLogHead {
00066   CSDiskValue4      th_magic_4;             /* Table magic number. */
00067   CSDiskValue2      th_version_2;           /* The header version. */
00068   CSDiskValue2      th_head_size_2;           /* The size of the header. */
00069   CSDiskValue2      th_rec_size_2;            /* The size of a temp log record. */
00070   CSDiskValue4      th_reserved_4;
00071 } MSTempLogHeadRec, *MSTempLogHeadPtr;
00072 
00073 typedef struct MSTempLogItem {
00074   CSDiskValue1      ti_type_1;              /* 1 = BLOB reference, 2 = Repository reference, 3 = Table reference */
00075   CSDiskValue4      ti_table_id_4;            /* Table ID (non-zero if valid). */
00076   CSDiskValue6      ti_blob_id_6;           /* Blob ID (non-zero if valid). */
00077   CSDiskValue4      ti_auth_code_4;           /* To make sure we do not delete the wrong thing. */
00078   CSDiskValue4      ti_time_4;              /* The time of deletion/creation */
00079 } MSTempLogItemRec, *MSTempLogItemPtr;
00080 
00081 class MSTempLogFile : public CSReadBufferedFile {
00082 public:
00083   uint32_t    myTempLogID;
00084   MSTempLog *myTempLog;
00085 
00086   MSTempLogFile();
00087   ~MSTempLogFile();
00088 
00089   friend class MSTempLog;
00090 
00091 private:
00092   static MSTempLogFile *newTempLogFile(uint32_t id, MSTempLog *temp_log, CSFile *path);
00093 };
00094 
00095 class MSTempLog : public CSRefObject {
00096 public:
00097   uint32_t    myLogID;
00098   off64_t   myTempLogSize;
00099   int     myTemplogRecSize;
00100   size_t    myTempLogHeadSize;
00101 
00102   MSTempLog(uint32_t id, MSDatabase *db, off64_t file_size);
00103   virtual ~MSTempLog();
00104 
00105   void deleteLog();
00106   CSPath *getLogPath();
00107   MSTempLogFile *openTempLog();
00108   
00109 #ifdef DEBUG
00110 //  virtual void retain() {
00111 //    CSRefObject::retain();
00112 //    printf("MSTempLog retained %d\n", iRefCount);
00113 //  }
00114 //
00115 //  virtual void release() {
00116 //    printf("MSTempLog released %d\n", iRefCount);
00117 //    CSRefObject::release();
00118 //  }
00119 #endif
00120 
00121   friend class MSTempLogThread;
00122 
00123 private:
00124   MSDatabase    *iLogDatabase;
00125   bool      iDeleteLog;
00126 
00127 public:
00128 
00129   static time_t adjustWaitTime(time_t then, time_t now);
00130 };
00131 
00132 class MSTempLogThread : public CSDaemon {
00133 public:
00134   MSTempLogThread(time_t wait_time, MSDatabase *db);
00135   virtual ~MSTempLogThread(){} // Do nothing here because 'self' will no longer be valid, use completeWork().
00136 
00137   void close();
00138 
00139   virtual bool doWork();
00140 
00141   virtual void *completeWork();
00142 
00143 private:
00144   bool try_ReleaseBLOBReference(CSThread *self, CSStringBuffer *buffer, uint32_t tab_id, int type, uint64_t blob_id, uint32_t auth_code);
00145 
00146   MSDatabase      *iTempLogDatabase;
00147   MSTempLogFile   *iTempLogFile;
00148   size_t        iLogRecSize;
00149   off64_t       iLogOffset;
00150   
00151 };
00152 
00153 #endif