public static async Task <string> Execute(ConnectionManager connectionManager, string partitionId)
        {
            string masterId = connectionManager.GetPartitionMasterId(partitionId);
            IImmutableSet <Server> replicaSet = connectionManager.GetPartitionAliveReplicas(partitionId);

            foreach (Server replica in replicaSet)
            {
                try
                {
                    while (true)
                    {
                        GStoreGetMasterResponse gStoreGetMasterResponse = await replica.Stub.GetMasterAsync(new GStoreGetMasterRequest
                        {
                            PartitionId = partitionId
                        });

                        string newMasterId = gStoreGetMasterResponse.MasterId;
                        if (newMasterId != masterId)
                        {
                            masterId = newMasterId;
                            break;
                        }
                        await Task.Delay(RETRY_DELAY);
                    }
                    break;
                }
                catch (Grpc.Core.RpcException exception) when(exception.StatusCode == Grpc.Core.StatusCode.Internal)
                {
                    // should handle this error
                    Console.WriteLine(exception.Message);
                }
            }
            return(masterId);
        }
Example #2
0
        public GStoreGetMasterResponse ExecuteGetMaster(GStoreGetMasterRequest request)
        {
            Console.WriteLine($"GetMaster request -> PartitionId: {request.PartitionId}");
            string masterId;

            try
            {
                masterId = gStore.GetMaster(request.PartitionId);
            }
            catch (Exception)
            {
                masterId = "-1"; //fixme
            }

            GStoreGetMasterResponse gStoreGetMasterResponse = new GStoreGetMasterResponse
            {
                MasterId = masterId
            };

            return(gStoreGetMasterResponse);
        }