public override void AfterDelete(string key) { var metadata = new RavenJObject { { Constants.RavenDeleteMarker, true }, { Constants.RavenReplicationHistory, deletedHistory.Value }, { Constants.RavenReplicationSource, Database.TransactionalStorage.Id.ToString() }, { Constants.RavenReplicationVersion, ReplicationHiLo.NextId(Database) } }; deletedHistory.Value = null; Database.TransactionalStorage.Batch(accessor => accessor.Lists.Set(Constants.RavenReplicationAttachmentsTombstones, key, metadata, UuidType.Attachments)); }
public override void AfterDelete(string key, TransactionInformation transactionInformation) { var now = DateTime.UtcNow; var metadata = new RavenJObject { { Constants.RavenDeleteMarker, true }, { Constants.RavenReplicationHistory, deletedHistory.Value }, { Constants.RavenReplicationSource, Database.TransactionalStorage.Id.ToString() }, { Constants.RavenReplicationVersion, ReplicationHiLo.NextId(Database) }, { Constants.LastModified, now }, { Constants.RavenLastModified, now } }; deletedHistory.Value = null; Database.TransactionalStorage.Batch(accessor => accessor.Lists.Set(Constants.RavenReplicationDocsTombstones, key, metadata, UuidType.Documents)); }
public override void OnPut(string key, Stream data, RavenJObject metadata) { if (key.StartsWith("Raven/")) // we don't deal with system attachment { return; } using (Database.DisableAllTriggersForCurrentThread()) { var attachmentMetadata = GetAttachmentMetadata(key); if (attachmentMetadata != null) { RavenJArray history = new RavenJArray(ReplicationData.GetHistory(metadata)); metadata[Constants.RavenReplicationHistory] = history; if (attachmentMetadata.ContainsKey(Constants.RavenReplicationVersion) && attachmentMetadata.ContainsKey(Constants.RavenReplicationSource)) { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, attachmentMetadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, attachmentMetadata[Constants.RavenReplicationSource] } }); } else { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, 0 }, { Constants.RavenReplicationSource, RavenJToken.FromObject(Database.TransactionalStorage.Id) } }); } while (history.Length > Constants.ChangeHistoryLength) { history.RemoveAt(0); } } metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(ReplicationHiLo.NextId(Database)); metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id); } }
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) && // we don't deal with system documents key.StartsWith("Raven/Hilo/", StringComparison.OrdinalIgnoreCase) == false) // except for hilos { return; } using (Database.DisableAllTriggersForCurrentThread()) { var documentMetadata = GetDocumentMetadata(key); if (documentMetadata != null) { var history = new RavenJArray(ReplicationData.GetHistory(documentMetadata)); metadata[Constants.RavenReplicationHistory] = history; if (documentMetadata.ContainsKey(Constants.RavenReplicationVersion) && documentMetadata.ContainsKey(Constants.RavenReplicationSource)) { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, documentMetadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, documentMetadata[Constants.RavenReplicationSource] } }); } else { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, 0 }, { Constants.RavenReplicationSource, RavenJToken.FromObject(Database.TransactionalStorage.Id) } }); } while (history.Length > Constants.ChangeHistoryLength) { history.RemoveAt(0); } } metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(ReplicationHiLo.NextId(Database)); metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id); } }
public override void AfterDelete(string key, TransactionInformation transactionInformation, RavenJObject metaJObject) { var now = DateTime.UtcNow; var metadata = new RavenJObject { { Constants.RavenDeleteMarker, true }, { Constants.RavenReplicationHistory, deletedHistory.Value }, { Constants.RavenReplicationSource, Database.TransactionalStorage.Id.ToString() }, { Constants.RavenReplicationVersion, ReplicationHiLo.NextId(Database) }, { Constants.LastModified, now }, { Constants.RavenLastModified, now } }; //Adding Raven-Entity-Name to tombstones so we can filter them when using ETL. if (metaJObject.ContainsKey(Constants.RavenEntityName)) { metadata[Constants.RavenEntityName] = metaJObject[Constants.RavenEntityName]; } deletedHistory.Value = null; Database.TransactionalStorage.Batch(accessor => accessor.Lists.Set(Constants.RavenReplicationDocsTombstones, key, metadata, UuidType.Documents)); }
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { if (key.StartsWith("Raven/")) // we don't deal with system documents { return; } var doc = Database.Get(key, null); if (doc != null) { var history = doc.Metadata.Value <RavenJArray>(ReplicationConstants.RavenReplicationHistory) ?? new RavenJArray(); metadata[ReplicationConstants.RavenReplicationHistory] = history; history.Add(new RavenJObject { { ReplicationConstants.RavenReplicationVersion, doc.Metadata[ReplicationConstants.RavenReplicationVersion] }, { ReplicationConstants.RavenReplicationSource, doc.Metadata[ReplicationConstants.RavenReplicationSource] } }); if (history.Length > ReplicationConstants.ChangeHistoryLength) { history.RemoveAt(0); } } metadata[ReplicationConstants.RavenReplicationVersion] = RavenJToken.FromObject(hiLo.NextId()); metadata[ReplicationConstants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id); }
public override void OnPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation) { if (key.StartsWith("Raven/")) // we don't deal with system documents { return; } if (ReplicationContext.IsInReplicationContext) { return; } var doc = Database.Get(key, null); if (doc != null) { metadata[ReplicationConstants.RavenReplicationParentVersion] = doc.Metadata[ReplicationConstants.RavenReplicationVersion]; metadata[ReplicationConstants.RavenReplicationParentSource] = doc.Metadata[ReplicationConstants.RavenReplicationSource]; } metadata[ReplicationConstants.RavenReplicationVersion] = JToken.FromObject(hiLo.NextId()); metadata[ReplicationConstants.RavenReplicationSource] = JToken.FromObject(Database.TransactionalStorage.Id); }
public override void OnPut(string key, Stream data, RavenJObject metadata) { if (key.StartsWith("Raven/")) // we don't deal with system attachment { return; } var attachment = Database.GetStatic(key); if (attachment != null) { var history = attachment.Metadata.Value <RavenJArray>(ReplicationConstants.RavenReplicationHistory) ?? new RavenJArray(); metadata[ReplicationConstants.RavenReplicationHistory] = history; history.Add(new RavenJObject { { ReplicationConstants.RavenReplicationVersion, attachment.Metadata[ReplicationConstants.RavenReplicationVersion] }, { ReplicationConstants.RavenReplicationSource, attachment.Metadata[ReplicationConstants.RavenReplicationSource] } }); if (history.Length > ReplicationConstants.ChangeHistoryLength) { history.RemoveAt(0); } } metadata[ReplicationConstants.RavenReplicationVersion] = RavenJToken.FromObject(hiLo.NextId()); metadata[ReplicationConstants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id); }
public override void OnPut(string key, Stream data, RavenJObject metadata) { if (key.StartsWith("Raven/")) // we don't deal with system attachment { return; } using (Database.DisableAllTriggersForCurrentThread()) { var attachmentMetadata = GetAttachmentMetadata(key); if (attachmentMetadata != null) { var history = new RavenJArray(ReplicationData.GetHistory(attachmentMetadata)); if (attachmentMetadata.ContainsKey(Constants.RavenReplicationMergedHistory) == false) { if (attachmentMetadata.ContainsKey(Constants.RavenReplicationVersion) && attachmentMetadata.ContainsKey(Constants.RavenReplicationSource)) { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, attachmentMetadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, attachmentMetadata[Constants.RavenReplicationSource] } }); } else { history.Add(new RavenJObject { { Constants.RavenReplicationVersion, 0 }, { Constants.RavenReplicationSource, RavenJToken.FromObject(Database.TransactionalStorage.Id) } }); } var sources = new HashSet <RavenJToken>(RavenJTokenEqualityComparer.Default); int pos = history.Length - 1; for (; pos >= 0; pos--) { var source = ((RavenJObject)history[pos])[Constants.RavenReplicationSource]; if (sources.Contains(source)) { history.RemoveAt(pos); continue; } sources.Add(source); } metadata[Constants.RavenReplicationMergedHistory] = true; metadata[Constants.RavenReplicationHistory] = history; } //If we have the flag we must have Constants.RavenReplicationVersion and Constants.RavenReplicationSource too //Here we assume that the replication history is in the form of a "sorted dictionary" so we just need to remove //the entry with the current source id and insert the new version at the end of the history. else { int i = history.Length - 1; for (; i >= 0; i--) { var currentEntry = history[i]; if (RavenJTokenEqualityComparer.Default.Equals(((RavenJObject)currentEntry) [Constants.RavenReplicationSource], attachmentMetadata[Constants.RavenReplicationSource])) { break; } } if (i != -1) { history.RemoveAt(i); } history.Add(new RavenJObject { { Constants.RavenReplicationVersion, attachmentMetadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, attachmentMetadata[Constants.RavenReplicationSource] } }); metadata[Constants.RavenReplicationHistory] = history; } } metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(ReplicationHiLo.NextId(Database)); metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id); } }