public int[] AssignAllEmptySegments(NodeEndpoint replicationEndpoint, ReplicationType type, int[] segments) { var reservedSegments = new List <int>(); hashTable.Batch(actions => { foreach (var segment in segments) { if (actions.HasTag(segment)) { continue; } if (type == ReplicationType.Ownership && MarkSegmentAsAssignedToEndpoint(actions, replicationEndpoint, segment) == false) { continue; } reservedSegments.Add(segment); } actions.Commit(); }); return(reservedSegments.ToArray()); }
/// <summary> /// Notify the master that the endpoint has caught up on all the specified segments /// </summary> public void CaughtUp(NodeEndpoint endpoint, ReplicationType type, params int[] caughtUpSegments) { var matchingSegments = GetMatchingSegments(caughtUpSegments, endpoint); var modifiedSegments = from segment in Segments join caughtUpSegment in matchingSegments on segment.Index equals caughtUpSegment.Index into maybeMatchingSegment select new MatchSegment { Segment = segment, Matching = maybeMatchingSegment }; switch (type) { case ReplicationType.Ownership: CaughtUpOnOwnership(modifiedSegments, endpoint); break; case ReplicationType.Backup: CaughtUpOnBackups(modifiedSegments, endpoint); break; default: throw new InvalidOperationException("Unknown replication type: " + type); } LogCurrentSegmentAssignment(); TopologyChanged(); }
public OnlineSegmentReplicationCommand( NodeEndpoint endpoint, Segment[] segments, ReplicationType type, IDistributedHashTableNode node, IDistributedHashTableNodeReplicationFactory factory) { this.endpoint = endpoint; this.segments = segments; this.type = type; this.node = node; this.factory = factory; }
public void GaveUp(NodeEndpoint endpoint, ReplicationType type, params int[] segmentsGivingUpOn) { var matchingSegments = GetMatchingSegments(segmentsGivingUpOn, endpoint); foreach (var segment in matchingSegments) { if (type == ReplicationType.Ownership) { segment.InProcessOfMovingToEndpoint = null; } else { segment.PendingBackups.Remove(endpoint); } } }
public static string Replication(ReplicationType type) { switch (type) { case ReplicationType.Nine: return("9"); case ReplicationType.Eight: return("8"); case ReplicationType.Seven: return("7"); case ReplicationType.Six: return("6"); case ReplicationType.Five: return("5"); case ReplicationType.Four: return("4"); case ReplicationType.Three: return("3"); case ReplicationType.Two: return("2"); case ReplicationType.One: return("1"); case ReplicationType.Zero: return("0"); case ReplicationType.None: case ReplicationType.All: default: return("0-all"); } }
public ReplicationItem(IClient client = null, ReplicationType type = ReplicationType.UserData, X509Certificate2 certificate = null) { if ((type & ReplicationType.UserData) != 0) { if (client == null) { throw new ArgumentNullException(nameof(client)); } } else if ((type & ReplicationType.CertificateData) != 0) { if (certificate == null) { throw new ArgumentNullException(nameof(certificate)); } } Client = client; Type = type; Certificate = certificate; }
public int[] AssignAllEmptySegments(NodeEndpoint replicationEndpoint, ReplicationType type, int[] segments) { var reservedSegments = new List<int>(); hashTable.Batch(actions => { foreach (var segment in segments) { if (actions.HasTag(segment)) continue; if (type == ReplicationType.Ownership && MarkSegmentAsAssignedToEndpoint(actions, replicationEndpoint, segment) == false) continue; reservedSegments.Add(segment); } actions.Commit(); }); return reservedSegments.ToArray(); }
public void GivingUpOn(ReplicationType type, params int[] segmentsGivingUpOn) { master.GaveUp(endpoint, type, segmentsGivingUpOn); }
public void DoneReplicatingSegments(ReplicationType type, int[] replicatedSegments) { master.CaughtUp(endpoint, type, replicatedSegments); State = NodeState.Started; }
public ReplicationResult ReplicateNextPage(NodeEndpoint replicationEndpoint, ReplicationType type, int segment) { var putRequests = new List <ExtendedPutRequest>(); var removalRequests = new List <ExtendedRemoveRequest>(); var done = false; hashTable.Batch(actions => { foreach (var getRequest in actions.GetKeysForTag(segment)) { var alreadyReplicated = actions.HasReplicationInfo(getRequest.Key, getRequest.SpecifiedVersion, replicationEndpoint.GetHash()); if (alreadyReplicated) { continue; } var values = actions.Get(getRequest); if (values.Length != 1) { continue; } var value = values[0]; putRequests.Add(new ExtendedPutRequest { Bytes = value.Data, ExpiresAt = value.ExpiresAt, IsReadOnly = value.ReadOnly, IsReplicationRequest = true, Key = value.Key, ParentVersions = value.ParentVersions, ReplicationTimeStamp = value.Timestamp, ReplicationVersion = value.Version, Tag = value.Tag, Segment = value.Tag.Value, }); actions.AddReplicationInfo(getRequest.Key, getRequest.SpecifiedVersion, replicationEndpoint.GetHash()); if (putRequests.Count >= 100) { break; } } foreach (var request in actions.ConsumeRemovalReplicationInfo(replicationEndpoint.GetHash())) { removalRequests.Add(new ExtendedRemoveRequest { Key = request.Key, SpecificVersion = request.SpecificVersion }); if (removalRequests.Count >= 100) { break; } } done = putRequests.Count == 0 && removalRequests.Count == 0; if (done && type == ReplicationType.Ownership) { MarkSegmentAsAssignedToEndpoint(actions, replicationEndpoint, segment); } actions.Commit(); }); return(new ReplicationResult { PutRequests = putRequests.ToArray(), RemoveRequests = removalRequests.ToArray(), Done = done }); }
public static bool replicate(NamedReplicationConfiguration config, ReplicationType type, bool createTarget) { var endpoint = new CouchDbEndpoint(); switch (type) { case ReplicationType.PUSH: endpoint = new CouchDbEndpoint { host = config.source.host, port = config.source.port, db = config.source.db, useSsl = config.source.useSsl, username = config.source.username, password = config.source.password }; break; case ReplicationType.PULL: endpoint = new CouchDbEndpoint { host = config.target.host, port = config.target.port, db = config.target.db, useSsl = config.target.useSsl, username = config.target.username, password = config.target.password }; break; } var content = new JObject { { "source", config.source.getUrl() + "/" + config.source.db.ToLower() }, { "target", config.target.getUrl() + "/" + config.target.db.ToLower() } }; if (createTarget) { content.Add("create_target", true); } if (!string.IsNullOrEmpty(config.proxyAddress)) { content.Add("proxy", config.proxyAddress + ":" + config.proxyPort); } content.Add("continuous", config.continuous); if (!string.IsNullOrEmpty(config.filter)) { content.Add("filter", config.filter); } if (config.docs != null) { var array = new JArray(); foreach (var doc in config.docs) { array.Add(doc); } content.Add("doc_ids", array); } var req = endpoint.getRequest("/_replicate", "POST", JsonConvert.SerializeObject(content)); var result = endpoint.getResponse(req, false); /** * {"ok":true,"_local_id":"0a81b645497e6270611ec3419767a584+continuous+create_target"} */ var ro = (JObject)JsonConvert.DeserializeObject(result.contentString); return(ro["ok"] != null && (bool)ro["ok"]); }
public ReplicationResult ReplicateNextPage(NodeEndpoint replicationEndpoint, ReplicationType type, int segment) { var putRequests = new List<ExtendedPutRequest>(); var removalRequests = new List<ExtendedRemoveRequest>(); var done = false; hashTable.Batch(actions => { foreach (var getRequest in actions.GetKeysForTag(segment)) { var alreadyReplicated = actions.HasReplicationInfo(getRequest.Key, getRequest.SpecifiedVersion, replicationEndpoint.GetHash()); if (alreadyReplicated) continue; var values = actions.Get(getRequest); if (values.Length != 1) continue; var value = values[0]; putRequests.Add(new ExtendedPutRequest { Bytes = value.Data, ExpiresAt = value.ExpiresAt, IsReadOnly = value.ReadOnly, IsReplicationRequest = true, Key = value.Key, ParentVersions = value.ParentVersions, ReplicationTimeStamp = value.Timestamp, ReplicationVersion = value.Version, Tag = value.Tag, Segment = value.Tag.Value, }); actions.AddReplicationInfo(getRequest.Key, getRequest.SpecifiedVersion, replicationEndpoint.GetHash()); if (putRequests.Count >= 100) break; } foreach (var request in actions.ConsumeRemovalReplicationInfo(replicationEndpoint.GetHash())) { removalRequests.Add(new ExtendedRemoveRequest { Key = request.Key, SpecificVersion = request.SpecificVersion }); if (removalRequests.Count >= 100) break; } done = putRequests.Count == 0 && removalRequests.Count == 0; if (done && type == ReplicationType.Ownership) { MarkSegmentAsAssignedToEndpoint(actions, replicationEndpoint, segment); } actions.Commit(); }); return new ReplicationResult { PutRequests = putRequests.ToArray(), RemoveRequests = removalRequests.ToArray(), Done = done }; }