Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/lisk/LiskDAO.php
Show First 20 Lines • Show All 1,615 Lines • ▼ Show 20 Lines | /* -( Isolation )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* @task isolate | * @task isolate | ||||
*/ | */ | ||||
public static function shouldIsolateAllLiskEffectsToTransactions() { | public static function shouldIsolateAllLiskEffectsToTransactions() { | ||||
return (bool)self::$transactionIsolationLevel; | return (bool)self::$transactionIsolationLevel; | ||||
} | } | ||||
/** | |||||
* Close any connections with no recent activity. | |||||
* | |||||
* Long-running processes can use this method to clean up connections which | |||||
* have not been used recently. | |||||
* | |||||
* @param int Close connections with no activity for this many seconds. | |||||
* @return void | |||||
*/ | |||||
public static function closeInactiveConnections($idle_window) { | |||||
$connections = self::$connections; | |||||
$now = PhabricatorTime::getNow(); | |||||
foreach ($connections as $key => $connection) { | |||||
$last_active = $connection->getLastActiveEpoch(); | |||||
$idle_duration = ($now - $last_active); | |||||
if ($idle_duration <= $idle_window) { | |||||
continue; | |||||
} | |||||
self::closeConnection($key); | |||||
} | |||||
} | |||||
public static function closeAllConnections() { | public static function closeAllConnections() { | ||||
self::$connections = array(); | $connections = self::$connections; | ||||
foreach ($connections as $key => $connection) { | |||||
self::closeConnection($key); | |||||
} | |||||
} | |||||
private static function closeConnection($key) { | |||||
if (empty(self::$connections[$key])) { | |||||
throw new Exception( | |||||
pht( | |||||
'No database connection with connection key "%s" exists!', | |||||
$key)); | |||||
} | |||||
$connection = self::$connections[$key]; | |||||
unset(self::$connections[$key]); | |||||
$connection->close(); | |||||
} | } | ||||
/* -( Utilities )---------------------------------------------------------- */ | /* -( Utilities )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* Applies configured serialization to a dictionary of values. | * Applies configured serialization to a dictionary of values. | ||||
* | * | ||||
* @task util | * @task util | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines |