1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
*
* PrimeBase Media Stream for MySQL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original author: Paul McCullagh
* Continued development: Barry Leslie
*
* 2007-07-03
*
* H&G2JCtL
*
* Temporary BLOB log.
*
* Temporary BLOBs are BLOBs that are to be deleted after an certain
* expiry time.
*
* The temporary log is also used to schedule asynchronous operations to be performed
* on the BLOB such as uploading it to a cloud.
*
* Temporary BLOBs are referenced by the temporary log.
*/
#ifndef __TEMPLOG_MS_H__
#define __TEMPLOG_MS_H__
#include "CSDefs.h"
#include "CSFile.h"
#include "CSStream.h"
#include "Defs_ms.h"
class MSOpenTable;
class MSDatabase;
class MSTempLog;
// Change history:
// April 6 2009:
// Changed MS_TEMP_LOG_MAGIC and MS_TEMP_LOG_VERSION
// when the disk size of ti_type_1 was changed from
// CSDiskValue4 to CSDiskValue1.
#define MS_TEMP_LOG_MAGIC 0xF9E6D7C9
#define MS_TEMP_LOG_VERSION 3
#define MS_TEMP_LOG_HEAD_SIZE 32
#define MS_TL_BLOB_REF 1
#define MS_TL_REPO_REF 2
#define MS_TL_TABLE_REF 3
typedef struct MSTempLogHead {
CSDiskValue4 th_magic_4; /* Table magic number. */
CSDiskValue2 th_version_2; /* The header version. */
CSDiskValue2 th_head_size_2; /* The size of the header. */
CSDiskValue2 th_rec_size_2; /* The size of a temp log record. */
CSDiskValue4 th_reserved_4;
} MSTempLogHeadRec, *MSTempLogHeadPtr;
typedef struct MSTempLogItem {
CSDiskValue1 ti_type_1; /* 1 = BLOB reference, 2 = Repository reference, 3 = Table reference */
CSDiskValue4 ti_table_id_4; /* Table ID (non-zero if valid). */
CSDiskValue6 ti_blob_id_6; /* Blob ID (non-zero if valid). */
CSDiskValue4 ti_auth_code_4; /* To make sure we do not delete the wrong thing. */
CSDiskValue4 ti_time_4; /* The time of deletion/creation */
} MSTempLogItemRec, *MSTempLogItemPtr;
class MSTempLogFile : public CSReadBufferedFile {
public:
u_int myTempLogID;
MSTempLog *myTempLog;
MSTempLogFile();
~MSTempLogFile();
friend class MSTempLog;
private:
static MSTempLogFile *newTempLogFile(u_int id, MSTempLog *temp_log, CSFile *path);
};
class MSTempLog : public CSRefObject {
public:
u_int myLogID;
off_t myTempLogSize;
int myTemplogRecSize;
size_t myTempLogHeadSize;
MSTempLog(u_int id, MSDatabase *db, off_t file_size);
virtual ~MSTempLog();
void deleteLog();
CSPath *getLogPath();
MSTempLogFile *openTempLog();
#ifdef DEBUG
// virtual void retain() {
// CSRefObject::retain();
// printf("MSTempLog retained %d\n", iRefCount);
// }
//
// virtual void release() {
// printf("MSTempLog released %d\n", iRefCount);
// CSRefObject::release();
// }
#endif
friend class MSTempLogThread;
private:
MSDatabase *iLogDatabase;
bool iDeleteLog;
public:
static u_long gTempBlobTimeout;
static time_t adjustWaitTime(time_t then, time_t now);
};
class MSTempLogThread : public CSDaemon {
public:
MSTempLogThread(time_t wait_time, MSDatabase *db);
virtual ~MSTempLogThread();
void close();
virtual bool doWork();
virtual void *finalize();
private:
MSDatabase *iTempLogDatabase;
MSTempLogFile *iTempLogFile;
size_t iLogRecSize;
off_t iLogOffset;
};
#endif
|