 			)
 			VALUES
 			(
-				_deploymentId,
-				_siloId,
-				_address,
-				_port,
-				_generation,
-				_hostName,
-				_gatewayAddress,
-				_gatewayPort,
-				_cpuUsage,
-				_memoryUsage,
-				_activationsCount,
-				_recentlyUsedActivationsCount,
-				_sendQueueLength,
-				_receiveQueueLength,
-				_requestQueueLength,
-				_sentMessagesCount,
-				_receivedMessagesCount,
-				_isOverloaded,
-				_clientCount
-			);
-		END IF;
-		COMMIT;
-END$$    
-
-DELIMITER ;
+				@deploymentId,
+				@siloId,
+				@address,
+				@port,
+				@generation,
+				@hostName,
+				@gatewayAddress,
+				@gatewayPort,
+				@cpuUsage,
+				@memoryUsage,
+				@activationsCount,
+				@recentlyUsedActivationsCount,
+				@sendQueueLength,
+				@receiveQueueLength,
+				@requestQueueLength,
+				@sentMessagesCount,
+				@receivedMessagesCount,
+				@isOverloaded,
+				@clientCount
+			)
+		ON DUPLICATE KEY UPDATE 
+				Address 		= @address,
+				Port 			= @port,
+				Generation 		= @generation,
+				HostName 		= @hostName,
+				GatewayAddress	 	= @gatewayAddress,
+				GatewayPort		= @gatewayPort,
+				CPU 			= @cpuUsage,
+				Memory 			= @memoryUsage,
+				Activations 		= @activationsCount,
+				RecentlyUsedActivations	= @recentlyUsedActivationsCount,
+				SendQueue 		= @sendQueueLength,
+				ReceiveQueue 		= @receiveQueueLength,
+				RequestQueue 		= @requestQueueLength,
+				SentMessages 		= @sentMessagesCount,
+				ReceivedMessages 	= @receivedMessagesCount,
+				LoadShedding 		= @isOverloaded,
+				ClientCount 		= @clientCount;
+');
 
 INSERT INTO OrleansQuery(QueryKey, QueryText)
 VALUES

			)
			VALUES
			(
				_serviceId,
				_grainId,
				_reminderName,
				_startTime,
				_period,
				_grainIdConsistentHash
			);
		ELSE
			UPDATE OrleansRemindersTable
			SET				
				StartTime             = _startTime,
				Period                = _period,
				GrainIdConsistentHash = _grainIdConsistentHash,
				ETag                  = _newEtag
			WHERE
				ServiceId = _serviceId AND _serviceId IS NOT NULL
				AND GrainId = _grainId AND _grainId IS NOT NULL
				AND ReminderName = _reminderName AND _reminderName IS NOT NULL;
		END IF;
		COMMIT;
		SELECT CONVERT(_newEtag, BINARY) AS ETag;
END$$

DELIMITER ;

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertReportClientMetricsKey','call UpsertReportClientMetricsKey(@deploymentId, @clientId, @timestamp, 
    @address, @hostName, @cpuUsage, @memoryUsage, @sendQueueLength, @receiveQueueLength, @sentMessagesCount,
    @receivedMessagesCount, @connectedGatewaysCount);'
);

DELIMITER $$

CREATE PROCEDURE UpsertReportClientMetricsKey(
	in	_deploymentId NVARCHAR(150),
	in	_clientId NVARCHAR(150),
	in	_timestamp DATETIME,
	in	_address VARCHAR(45),
	in	_hostName NVARCHAR(150),
	in	_cpuUsage FLOAT,
	in	_memoryUsage BIGINT,
	in	_sendQueueLength INT,
	in	_receiveQueueLength INT,
	in	_sentMessagesCount BIGINT,
	in	_receivedMessagesCount BIGINT,
	in	_connectedGatewaysCount BIGINT
)
BEGIN
		START TRANSACTION;     
		IF EXISTS(SELECT 1 FROM OrleansClientMetricsTable WHERE
			DeploymentId = _deploymentId AND _deploymentId IS NOT NULL
			AND ClientId = _clientId AND _clientId IS NOT NULL
			FOR UPDATE) 
		THEN
			UPDATE OrleansClientMetricsTable
			SET			
				Address = _address,
				HostName = _hostName,
				CPU = _cpuUsage,
				Memory = _memoryUsage,
				SendQueue = _sendQueueLength,
				ReceiveQueue = _receiveQueueLength,
				SentMessages = _sentMessagesCount,
				ReceivedMessages = _receivedMessagesCount,
				ConnectedGatewayCount = _connectedGatewaysCount
			WHERE
				(DeploymentId = _deploymentId AND _deploymentId IS NOT NULL)
				AND (ClientId = _clientId AND _clientId IS NOT NULL);
		ELSE
			INSERT INTO OrleansClientMetricsTable
			(
				DeploymentId,

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertReminderRowKey', '
			INSERT INTO OrleansRemindersTable
			(
				ServiceId,
