public override void Initialize()
		{
			base.Initialize();
			hiLo = new ReplicationHiLo
			{
				Database = Database
			};
		}
예제 #2
0
 public override void Initialize()
 {
     base.Initialize();
     hiLo = new ReplicationHiLo
     {
         Database = Database
     };
 }
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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, 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);
            }
        }