~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/TransactionManager.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        rolledBackTransaction->state = RolledBack;
53
53
        rolledBackTransaction->inList = false;
54
54
        syncObject.setName("TransactionManager::syncObject");
55
 
        //syncInitialize.setName("TransactionManager::syncInitialize");
56
55
}
57
56
 
58
57
TransactionManager::~TransactionManager(void)
96
95
 
97
96
Transaction* TransactionManager::findOldest(void)
98
97
{
 
98
        Sync sync (&activeTransactions.syncObject, "TransactionManager::findOldest");
 
99
        sync.lock (Shared);
99
100
        Transaction *oldest = NULL;
100
101
        
101
102
        for (Transaction *transaction = activeTransactions.first; transaction; transaction = transaction->next)
107
108
 
108
109
Transaction* TransactionManager::startTransaction(Connection* connection)
109
110
{
110
 
        Sync sync (&activeTransactions.syncObject, "Database::startTransaction");
 
111
        Sync sync (&activeTransactions.syncObject, "TransactionManager::startTransaction");
111
112
        sync.lock (Shared);
112
 
        //Sync syncInit(&syncInitialize, "TransactionManager::startTransaction");
113
113
        Transaction *transaction;
114
114
 
115
115
        for (transaction = activeTransactions.first; transaction; transaction = transaction->next)
116
116
                if (transaction->state == Available && transaction->dependencies == 0)
117
117
                        if (COMPARE_EXCHANGE(&transaction->state, Available, Initializing))
118
118
                                {
119
 
                                //syncInit.lock(Exclusive);
120
119
                                transaction->initialize(connection, INTERLOCKED_INCREMENT(transactionSequence));
121
120
 
122
121
                                return transaction;
124
123
 
125
124
        sync.unlock();
126
125
        sync.lock(Exclusive);
127
 
        //syncInit.lock(Exclusive);
128
126
 
129
127
        transaction = new Transaction (connection, INTERLOCKED_INCREMENT(transactionSequence));
130
128
        activeTransactions.append(transaction);
131
 
        //syncInit.unlock();
132
129
 
133
130
        // And, just for yucks, add another 10 Available transactions
134
131
 
175
172
        return false;
176
173
}
177
174
 
178
 
/***
179
 
void TransactionManager::scavengeRecords(int threshold)
180
 
{
181
 
        Sync sync (&activeTransactions.syncObject, "TransactionManager::scavengeRecord");
182
 
        sync.lock (Shared);
183
 
        
184
 
        for (bool again = true; again;)
185
 
                {
186
 
                again = false;
187
 
                
188
 
                for (Transaction *transaction = activeTransactions.first; transaction; transaction = transaction->next)
189
 
                        if (transaction != database->systemConnection->transaction && transaction->isActive() && !transaction->scavenged)
190
 
                                {
191
 
                                transaction->addRef();
192
 
                                sync.unlock();
193
 
                                transaction->scavengeRecords(threshold);
194
 
                                transaction->release();
195
 
                                sync.lock(Shared);
196
 
                                again = true;
197
 
                                break;
198
 
                                }
199
 
                }
200
 
}
201
 
***/
202
 
 
203
175
void TransactionManager::commitByXid(int xidLength, const UCHAR* xid)
204
176
{
205
177
        Sync sync (&activeTransactions.syncObject, "TransactionManager::commitByXid");
333
305
        sync.unlock();
334
306
        
335
307
        int n = 0;
336
 
//      infoTable->putString(n++, database->name);
337
308
        infoTable->putInt(n++, numberCommitted);
338
309
        infoTable->putInt(n++, numberRolledBack);
339
310
        infoTable->putInt(n++, numberActive);
348
319
        sync.lock (Shared);
349
320
        Transaction *transaction;
350
321
        int active = 0;
 
322
        int available = 0;
 
323
        int dependencies = 0;
351
324
        time_t maxTime = 0;
352
325
        
353
326
        for (transaction = activeTransactions.first; transaction; transaction = transaction->next)
354
327
                if (transaction->state == Active)
355
328
                        {
356
329
                        ++active;
357
 
                        time_t age = database->deltaTime - transaction->startTime;
358
 
                        maxTime = MAX(age, maxTime);
 
330
                        time_t ageTime = database->deltaTime - transaction->startTime;
 
331
                        maxTime = MAX(ageTime, maxTime);
 
332
                        }
 
333
                else if (transaction->state == Available)
 
334
                        {
 
335
                        ++available;
 
336
                        
 
337
                        if (transaction->dependencies)
 
338
                                ++dependencies;
359
339
                        }
360
340
                        
361
341
        int pendingCleanup = committedTransactions.count;
365
345
        priorRolledBack = rolledBack;
366
346
        
367
347
        if ((active || numberCommitted || numberRolledBack) && Log::isActive(LogInfo))
368
 
                Log::log (LogInfo, "%d: Transactions: %d committed, %d rolled back, %d active, %d post-commit, oldest %d seconds\n",
369
 
                                  database->deltaTime, numberCommitted, numberRolledBack, active, pendingCleanup, maxTime);
 
348
                Log::log (LogInfo, "%d: Transactions: %d committed, %d rolled back, %d active, %d/%d available, %d post-commit, oldest %d seconds\n",
 
349
                                  database->deltaTime, numberCommitted, numberRolledBack, active, available, dependencies, pendingCleanup, maxTime);
370
350
}
371
351
 
372
352
void TransactionManager::removeCommittedTransaction(Transaction* transaction)