mirror of
https://github.com/gnustep/libs-sqlclient.git
synced 2025-02-14 15:40:59 +00:00
Track committed transactions
This commit is contained in:
parent
4f622fb975
commit
36fe235dba
4 changed files with 56 additions and 10 deletions
|
@ -1,3 +1,11 @@
|
|||
2022-06-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* SQLClient.h: Declare new (-committed) method.
|
||||
* SQLClient.m:
|
||||
* SQLClientPool.m:
|
||||
Implement -committed to return the count of transactions committed by
|
||||
a client or pool. Update -description to report that too.
|
||||
|
||||
2022-06-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* SQLClient.h: Declare new (-setOptions:) method.
|
||||
|
|
10
SQLClient.h
10
SQLClient.h
|
@ -522,6 +522,7 @@ SQLCLIENT_PRIVATE
|
|||
NSTimeInterval _lastConnect; /** Last successful connect */
|
||||
NSTimeInterval _lastStart; /** Last op start or connect */
|
||||
NSTimeInterval _duration; /** Duration logging threshold */
|
||||
uint64_t _committed; /** Count of committed transactions */
|
||||
unsigned int _debugging; /** The current debugging level */
|
||||
GSCache *_cache; /** The cache for query results */
|
||||
NSThread *_cacheThread; /** Thread for cache queries */
|
||||
|
@ -623,6 +624,10 @@ SQLCLIENT_PRIVATE
|
|||
*/
|
||||
- (void) begin;
|
||||
|
||||
/** Returns the number of committed transactions.
|
||||
*/
|
||||
- (uint64_t) committed;
|
||||
|
||||
/** This grabs the receiver for use by the current thread.<br />
|
||||
* If limit is nil or in the past, makes a single immediate attempt.<br />
|
||||
* Returns NO if it fails to obtain a lock by the specified date.<br />
|
||||
|
@ -1159,6 +1164,7 @@ SQLCLIENT_PRIVATE
|
|||
recordType: (id)rtype
|
||||
listType: (id)ltype;
|
||||
|
||||
|
||||
/** If there is no database connection, attempts to establish one.<br />
|
||||
* This does not do automatic retries on connection failure.<br />
|
||||
* Returns the current connection status.
|
||||
|
@ -1767,6 +1773,10 @@ typedef struct _SQLClientPoolItem SQLClientPoolItem;
|
|||
*/
|
||||
- (GSCache*) cache;
|
||||
|
||||
/** Returns the number of committed transactions.
|
||||
*/
|
||||
- (uint64_t) committed;
|
||||
|
||||
/**
|
||||
* Creates a pool of clients using a single client configuration.<br />
|
||||
* Calls -initWithConfiguration:name:pool: (passing NO to say the client
|
||||
|
|
11
SQLClient.m
11
SQLClient.m
|
@ -1609,6 +1609,11 @@ static int poolConnections = 0;
|
|||
NS_ENDHANDLER
|
||||
}
|
||||
|
||||
- (uint64_t) committed
|
||||
{
|
||||
return _committed;
|
||||
}
|
||||
|
||||
- (BOOL) connect
|
||||
{
|
||||
if (NO == [self tryConnect] && abandonAfter > 0.0)
|
||||
|
@ -1699,6 +1704,7 @@ static int poolConnections = 0;
|
|||
[s appendFormat: @" Password - %@\n",
|
||||
[self password] == nil ? @"unknown" : @"known"];
|
||||
[s appendFormat: @" Connected - %@\n", connected ? @"yes" : @"no"];
|
||||
[s appendFormat: @" Committed - %"PRIu64"\n", _committed];
|
||||
[s appendFormat: @" Transaction - %@\n",
|
||||
_inTransaction ? @"yes" : @"no"];
|
||||
}
|
||||
|
@ -2896,6 +2902,7 @@ static int poolConnections = 0;
|
|||
if (_inTransaction == NO)
|
||||
{
|
||||
[_statements removeAllObjects];
|
||||
_committed++;
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
|
@ -2978,6 +2985,10 @@ static int poolConnections = 0;
|
|||
d, stmt, count, ((1 == count) ? "" : "s")];
|
||||
}
|
||||
}
|
||||
if (_inTransaction == NO)
|
||||
{
|
||||
_committed++;
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
|
|
|
@ -119,6 +119,22 @@ static Class cls = Nil;
|
|||
return [_items[0].c cache];
|
||||
}
|
||||
|
||||
- (uint64_t) committed
|
||||
{
|
||||
NSUInteger index;
|
||||
uint64_t total = 0;
|
||||
|
||||
[_lock lock];
|
||||
for (index = 0; index < _max; index++)
|
||||
{
|
||||
SQLClient *client = _items[index].c;
|
||||
|
||||
total += [client committed];
|
||||
}
|
||||
[_lock unlock];
|
||||
return total;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
SQLClientPoolItem *old;
|
||||
|
@ -648,13 +664,14 @@ static Class cls = Nil;
|
|||
NSString *s;
|
||||
|
||||
s = [NSString stringWithFormat:
|
||||
@" Immediate provisions: %llu\n"
|
||||
@" Delayed provisions: %llu\n"
|
||||
@" Timed out provisions: %llu\n"
|
||||
@" Slowest provision: %g\n"
|
||||
@" Average delay: %g\n"
|
||||
@" Average timeout: %g\n"
|
||||
@" Average over all: %g\n",
|
||||
@" Immediate provisions: %llu\n"
|
||||
@" Delayed provisions: %llu\n"
|
||||
@" Timed out provisions: %llu\n"
|
||||
@" Slowest provision: %g\n"
|
||||
@" Average delay: %g\n"
|
||||
@" Average timeout: %g\n"
|
||||
@" Average over all: %g\n"
|
||||
@" Committed transactions: %"PRIu64"\n",
|
||||
(unsigned long long)_immediate,
|
||||
(unsigned long long)_delayed,
|
||||
(unsigned long long)_failed,
|
||||
|
@ -663,7 +680,8 @@ static Class cls = Nil;
|
|||
(_failed > 0) ? _failWaits / _failed : 0.0,
|
||||
(_immediate + _delayed + _failed) > 0
|
||||
? (_failWaits + _delayWaits) / (_immediate + _delayed + _failed)
|
||||
: 0.0];
|
||||
: 0.0,
|
||||
[self committed]];
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -729,7 +747,6 @@ static Class cls = Nil;
|
|||
}
|
||||
[liveInfo addObject: [tmp stringByAppendingFormat:
|
||||
@") active in transaction since %@\n", d]];
|
||||
rc = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -799,7 +816,7 @@ static Class cls = Nil;
|
|||
}
|
||||
|
||||
s = [NSMutableString stringWithFormat: @" size min: %u, max: %u\n"
|
||||
@"live:%u, used:%u, idle:%u, free:%u, dead:%u\n",
|
||||
@" live:%u, used:%u, idle:%u, free:%u, dead:%u\n",
|
||||
_min, _max, live, used, idle, free, dead];
|
||||
|
||||
if (liveInfo)
|
||||
|
|
Loading…
Reference in a new issue