 			)
 			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
+				@serviceId,
+				@grainId,
+				@reminderName,
+				@startTime,
+				@period,
+				@grainIdConsistentHash
+			)
+		ON DUPLICATE KEY UPDATE 
+				StartTime             = @startTime,
+				Period                = @period,
+				GrainIdConsistentHash = @grainIdConsistentHash,
+				ETag                  = last_insert_id(ETag+1);
+	
+		SELECT CONVERT(last_insert_id(), BINARY) AS ETag;
+');
+
+INSERT INTO OrleansQuery(QueryKey, QueryText)
+VALUES
+(
+	'UpsertReportClientMetricsKey','
 			INSERT INTO OrleansClientMetricsTable
 			(
 				DeploymentId,

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertReminderRowKey', 'call UpsertReminderRowKey(@serviceId, @grainId, @reminderName, @startTime, @period, 
    @grainIdConsistentHash);'
);

DELIMITER $$
CREATE PROCEDURE UpsertReminderRowKey(
	in 	_serviceId NVARCHAR(150),
	in 	_grainId NVARCHAR(150),
	in 	_reminderName NVARCHAR(150),
	in 	_startTime DATETIME,
	in 	_period INT,
	in 	_grainIdConsistentHash INT
)
BEGIN
		DECLARE _newEtag BIGINT;
		START TRANSACTION;
        SET _newEtag = (SELECT ETag + 1 FROM OrleansRemindersTable WHERE
						ServiceId = _serviceId AND _serviceId IS NOT NULL
						AND GrainId = _grainId AND _grainId IS NOT NULL
						AND ReminderName = _reminderName AND _reminderName IS NOT NULL 
						FOR UPDATE);
                        
		IF _newEtag IS NULL
		THEN
			SET _newEtag = 0;
			INSERT INTO OrleansRemindersTable
			(
				ServiceId,

			)
			VALUES
			(
				@deploymentId,
				@clientId,
				@address,
				@hostName,
				@cpuUsage,
				@memoryUsage,
				@sendQueueLength,
				@receiveQueueLength,
				@sentMessagesCount,
				@receivedMessagesCount,
				@connectedGatewaysCount
			)
		ON DUPLICATE KEY UPDATE 
				Address 		= @address,
				HostName 		= @hostName,
				CPU 			= @cpuUsage,
				Memory 			= @memoryUsage,
				SendQueue 		= @sendQueueLength,
				ReceiveQueue 		= @receiveQueueLength,
				SentMessages 		= @sentMessagesCount,
				ReceivedMessages 	= @receivedMessagesCount,
				ConnectedGatewayCount 	= @connectedGatewaysCount;
');

INSERT INTO OrleansQuery(QueryKey, QueryText)
VALUES
(
	'UpsertSiloMetricsKey','
			INSERT INTO OrleansSiloMetricsTable
			(
				DeploymentId,
