~drizzle-trunk/drizzle/development

1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1
/* Copyright (c) 2009 PrimeBase Technologies GmbH, Germany
2
 *
3
 * PrimeBase Media Stream for MySQL
4
 *
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.
9
 *
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.
14
 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 *
19
 * Barry Leslie
20
 *
21
 * 2009-06-10
22
 *
23
 * H&G2JCtL
24
 *
25
 * PBMS transaction cache.
26
 *
27
 */
28
 
29
#ifndef __TRANSCACHE_MS_H__
30
#define __TRANSCACHE_MS_H__
31
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
32
#include "cslib/CSDefs.h"
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
33
#include "trans_log_ms.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
34
35
#define TRANS_CACHE_NEW_REF	((TRef)-1)
36
#define TRANS_CACHE_UNKNOWN_REF	((TRef)-2)
37
38
class MSTransCache : public CSSharedRefObject 
39
{
40
public:
41
	MSTransCache();
42
	~MSTransCache();
43
	
44
	// Prepare to add another record to a tansaction
45
	// This will preallocate anything required so that the call
46
	// to tc_AddRec() cannot fail.
47
	//void tc_PrepAddRec(TRef tref, uint32_t tr_id);
48
49
	// Add a transaction record to an already existing transaction
50
	// or possible creating a new one. Depending on the record added this may
51
	// also commit or rollback the transaction.
52
	// Returns false if the list is full.
53
	//void tc_AddRec(uint64_t log_position, MSTransPtr rec);
54
	void tc_AddRec(uint64_t log_position, MSTransPtr rec, TRef tref = TRANS_CACHE_UNKNOWN_REF);
55
	void tc_LoadRec(uint64_t log_position, MSTransPtr rec) { tc_AddRec(log_position, rec);}
56
	
57
	// Get the transaction ref of the first transaction in the list.
58
	// Sets terminated to true or false depending on if the transaction is terminated.
59
	// If there is no trsansaction then false is returned.
60
	bool tc_GetTransaction(TRef *ref, bool *terminated);	
61
62
	uint32_t tc_GetTransactionID(TRef ref);	
63
	
64
	// Get the state of the terminated transaction.
65
	MS_TxnState tc_TransactionState(TRef ref);	
66
	
67
	// Remove the transaction and all record associated with it.
68
	void tc_FreeTransaction(TRef tref);
69
	
70
	// Get the log position of the first transaction in the list.
71
	// Returns false if there is no transaction.
72
	bool tc_GetTransactionStartPosition(uint64_t *log_position);
73
	
74
	// Get the nth record for the specified transaction. A pointer to the
75
	// storage location is passed in. If there is no nth record 'false' is returned
76
	// otherwise the passed in record buffer is filled out and the pointer to
77
	// it is returned.
78
	bool tc_GetRecAt(TRef tref, size_t index, MSTransPtr rec, MS_TxnState *state);
79
	
80
	uint32_t tc_GetCacheUsed() { return tc_Used;}
81
	uint32_t tc_GetPercentCacheUsed() { return (tc_Used * 100)/(tc_Size-1);}
82
	uint32_t tc_GetPercentCacheHit() { return (tc_TotalCacheCount * 100)/tc_TotalTransCount;}
83
84
	// Notify the cache that recovery is in progress.
85
	// In this case transaction records are not cached.
86
	void tc_SetRecovering(bool recovering) {tc_Recovering = recovering;}
87
	
88
	// Methods used to update the cache from disk.
89
	bool tc_ShoulReloadCache();		// Test to see if the cache needs to be reloaded.
90
	uint64_t tc_StartCacheReload(bool startup = false);	// Initialize the cache for reload.
91
	bool tc_ContinueCacheReload();	// Returns false when the cache is full.
92
	void tc_CompleteCacheReload();	// Signal the end of the cache reload operation.
93
94
	void tc_UpdateCacheVersion() {tc_CacheVersion++;}
95
	
96
	void tc_SetSize(uint32_t cache_size); // Chang the size of the cache.
97
	
98
	void tc_dropDatabase(uint32_t db_id); // clears records from ther cache for a dropped database.
99
100
	static MSTransCache *newMSTransCache(uint32_t cache_size);
101
	
102
private:
103
	void tc_Initialize(uint32_t size);
104
	TRef tc_NewTransaction(uint32_t tid);	
105
	void tc_FindTXNRef(uint32_t tid, TRef *tref);
106
107
	struct TransList	*tc_List;		// The transaction list, One entry per transaction.
108
	struct TransList	*tc_OverFlow;	// The first transaction to overflow.
109
	uint32_t				tc_Size;		// The current size of the list
110
	uint32_t				tc_EOL;			// The index of the first unused transaction list record
111
	uint32_t				tc_First;		// The index of the first used transaction list record
112
	uint32_t				tc_Used;		// The number of used transaction list records
113
114
	uint64_t				tc_TotalTransCount;	// The number of transaction to be cached
115
	uint64_t				tc_TotalCacheCount;	// The number of transaction cached
116
	
117
	CSThread			*tc_ReLoadingThread; // The thread performing a reload.
118
	uint32_t				tc_OverFlowTID; // The transaction id of the first transaction in th reload.
119
	bool				tc_Full;
120
	uint32_t				tc_CacheVersion;
121
	
122
	bool				tc_Recovering;
123
124
#ifdef DEBUG
125
	uint32_t tc_ReloadCnt;
126
#endif
127
	
128
};
129
130
131
#endif // __TRANSCACHE_MS_H__