1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh
20
* Continued development: Barry Leslie
28
* Temporary BLOBs are BLOBs that are to be deleted after an certain
31
* The temporary log is also used to schedule asynchronous operations to be performed
32
* on the BLOB such as uploading it to a cloud.
34
* Temporary BLOBs are referenced by the temporary log.
38
#ifndef __TEMPLOG_MS_H__
39
#define __TEMPLOG_MS_H__
41
#include "cslib/CSDefs.h"
42
#include "cslib/CSFile.h"
43
#include "cslib/CSStream.h"
53
// Changed MS_TEMP_LOG_MAGIC and MS_TEMP_LOG_VERSION
54
// when the disk size of ti_type_1 was changed from
55
// CSDiskValue4 to CSDiskValue1.
57
#define MS_TEMP_LOG_MAGIC 0xF9E6D7C9
58
#define MS_TEMP_LOG_VERSION 3
59
#define MS_TEMP_LOG_HEAD_SIZE 32
61
#define MS_TL_BLOB_REF 1
62
#define MS_TL_REPO_REF 2
63
#define MS_TL_TABLE_REF 3
65
typedef struct MSTempLogHead {
66
CSDiskValue4 th_magic_4; /* Table magic number. */
67
CSDiskValue2 th_version_2; /* The header version. */
68
CSDiskValue2 th_head_size_2; /* The size of the header. */
69
CSDiskValue2 th_rec_size_2; /* The size of a temp log record. */
70
CSDiskValue4 th_reserved_4;
71
} MSTempLogHeadRec, *MSTempLogHeadPtr;
73
typedef struct MSTempLogItem {
74
CSDiskValue1 ti_type_1; /* 1 = BLOB reference, 2 = Repository reference, 3 = Table reference */
75
CSDiskValue4 ti_table_id_4; /* Table ID (non-zero if valid). */
76
CSDiskValue6 ti_blob_id_6; /* Blob ID (non-zero if valid). */
77
CSDiskValue4 ti_auth_code_4; /* To make sure we do not delete the wrong thing. */
78
CSDiskValue4 ti_time_4; /* The time of deletion/creation */
79
} MSTempLogItemRec, *MSTempLogItemPtr;
81
class MSTempLogFile : public CSReadBufferedFile {
89
friend class MSTempLog;
92
static MSTempLogFile *newTempLogFile(uint32_t id, MSTempLog *temp_log, CSFile *path);
95
class MSTempLog : public CSRefObject {
98
off64_t myTempLogSize;
100
size_t myTempLogHeadSize;
102
MSTempLog(uint32_t id, MSDatabase *db, off64_t file_size);
103
virtual ~MSTempLog();
106
CSPath *getLogPath();
107
MSTempLogFile *openTempLog();
110
// virtual void retain() {
111
// CSRefObject::retain();
112
// printf("MSTempLog retained %d\n", iRefCount);
115
// virtual void release() {
116
// printf("MSTempLog released %d\n", iRefCount);
117
// CSRefObject::release();
121
friend class MSTempLogThread;
124
MSDatabase *iLogDatabase;
129
static time_t adjustWaitTime(time_t then, time_t now);
132
class MSTempLogThread : public CSDaemon {
134
MSTempLogThread(time_t wait_time, MSDatabase *db);
135
virtual ~MSTempLogThread(){} // Do nothing here because 'self' will no longer be valid, use completeWork().
139
virtual bool doWork();
141
virtual void *completeWork();
144
bool try_ReleaseBLOBReference(CSThread *self, CSStringBuffer *buffer, uint32_t tab_id, int type, uint64_t blob_id, uint32_t auth_code);
146
MSDatabase *iTempLogDatabase;
147
MSTempLogFile *iTempLogFile;