~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/pbms/src/trans_cache_ms.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

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