private string ReadAdvanced(string partitionId, string objectId, string serverId) { var request = new ReadAdvancedRequest { PartitionId = partitionId, ObjectId = objectId }; try { var readResponse = _client.readAdvanced(request); if (!readResponse.ObjectValue.Equals(ObjectNotPresent)) { return(_previousStorage.GetAndUpdate(partitionId, objectId, readResponse)); } //return readResponse.ObjectValue; if (serverId.Equals("-1")) { return(_previousStorage.GetAndUpdate(partitionId, objectId)); } var serverUrl = MapServerIdToUrl(serverId); _client = BuildClientFromServerUrl(serverUrl); var secondReadResponse = _client.readAdvanced(request); if (secondReadResponse.ObjectValue.Equals(ObjectNotPresent)) { return(_previousStorage.GetAndUpdate(partitionId, objectId)); } return(_previousStorage.GetAndUpdate(partitionId, objectId, readResponse)); } catch (RpcException e) { ConnectToNewServer(partitionId); Console.WriteLine("Error reading"); Console.WriteLine(e.Message); return(ReadAdvanced(partitionId, objectId, serverId)); } }
private ReadAdvancedResponse ReadAdvanced(ReadAdvancedRequest request) { Console.WriteLine("Received Read Request: " + request.ToString()); try { var partitionId = request.PartitionId; var objectId = request.ObjectId; var partition = _storage.GetPartitionOrThrowException(partitionId); var objectValue = _storage.ReadAdvanced(partitionId, objectId); var response = new ReadAdvancedResponse { ObjectValue = objectValue.value, Timestamp = objectValue.timestampCounter }; return(response); } catch (Exception) { /*Partition not founded */ return(new ReadAdvancedResponse { ObjectValue = "N/A" }); } }
readAdvanced(ReadAdvancedRequest request, ServerCallContext context) { _freezeUtilities.WaitForUnfreeze(); delayFunction(); return(Task.FromResult(ReadAdvanced(request))); }