Пример #1
0
        private bool ReadAndAttach(
            string partitionId,
            string objectId,
            string serverId,
            string serverUrl,
            out string value)
        {
            if (!timestamps.TryGetValue(partitionId, out MutableVectorClock timestamp))
            {
                timestamp = MutableVectorClock.Empty();
                timestamps.Add(partitionId, timestamp);
            }

            if (AdvancedGrpcMessageLayer.Instance.Read(
                    serverUrl,
                    partitionId,
                    objectId,
                    out value,
                    timestamp.ToImmutable(),
                    out ImmutableVectorClock replicaTimestamp) &&
                value != null)
            {
                timestamp.Merge(replicaTimestamp);
                attachedId = serverId;
                return(true);
            }

            return(false);
        }
        public void OnJoinPartitionRequest(JoinPartitionArguments arguments)
        {
            string partitionId = arguments.PartitionId;

            partitionsDB.JoinPartition(arguments);
            partitionsDB.TryGetPartition(partitionId, out ImmutableHashSet <string> serverIds);

            // Only register partitions that the server belongs to for broadcast
            if (serverIds.Contains(serverConfig.ServerId))
            {
                valueTimestamps.TryAdd(partitionId, MutableVectorClock.Empty());
                emitedWritesTimestamps.TryAdd(partitionId, MutableVectorClock.Empty());
                ReliableBroadcastLayer.Instance.RegisterPartition(partitionId, serverIds);
            }
        }
Пример #3
0
        public bool Write(
            string partitionId,
            string objectId,
            string value)
        {
            if (!namingService.ListPartition(partitionId, out ImmutableHashSet <string> serverIds))
            {
                return(false);
            }

            if (!timestamps.TryGetValue(partitionId, out MutableVectorClock timestamp))
            {
                timestamp = MutableVectorClock.Empty();
                timestamps.Add(partitionId, timestamp);
            }


            foreach (string serverId in serverIds)
            {
                ImmutableVectorClock replicaTimestamp = null;

                bool success = namingService.Lookup(serverId, out string serverUrl) &&
                               AdvancedGrpcMessageLayer.Instance.Write(
                    serverUrl,
                    partitionId,
                    objectId,
                    value,
                    timestamp.ToImmutable(),
                    out replicaTimestamp);

                if (success)
                {
                    timestamp.Merge(replicaTimestamp);
                    return(true);
                }
            }
            return(false);
        }