public void AbstractScriptedIndexCreationTaskWillNotResetIndexIfNothingHasChanged() { using (var store = NewDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new Person { Name = "Name1" }); session.SaveChanges(); } var index = new People_By_Name_With_Scripts(); index.Execute(store); WaitForIndexing(store); var stats = store.DatabaseCommands.GetStatistics(); var indexStats = stats.Indexes.First(x => x.Name == index.IndexName); var lastIndexedEtag = indexStats.LastIndexedEtag; Assert.True(EtagUtil.IsGreaterThan(lastIndexedEtag, Etag.Empty)); store.DatabaseCommands.Admin.StopIndexing(); index.Execute(store); stats = store.DatabaseCommands.GetStatistics(); indexStats = stats.Indexes.First(x => x.Name == index.IndexName); Assert.True(indexStats.LastIndexedEtag.Equals(lastIndexedEtag) || EtagUtil.IsGreaterThan(indexStats.LastIndexedEtag, lastIndexedEtag)); } }
public Etag GetBestNextDocumentEtag(Etag etag) { if (etag == null) { throw new ArgumentNullException("etag"); } using (var iter = tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag) .Iterate(Snapshot, writeBatch.Value)) { if (!iter.Seek((Slice)etag.ToString()) && !iter.Seek(Slice.BeforeAllKeys)) //if parameter etag not found, scan from beginning. if empty --> return original etag { return(etag); } do { var docEtag = Etag.Parse(iter.CurrentKey.ToString()); if (EtagUtil.IsGreaterThan(docEtag, etag)) { return(docEtag); } } while (iter.MoveNext()); } return(etag); //if not found, return the original etag }
public void GetDocumentsBatchFromShouldReturnUniqueResults2() { var prefetcher = CreatePrefetcher(); AddDocumentsToTransactionalStorage(prefetcher.TransactionalStorage, 100); var documents = prefetcher.PrefetchingBehavior.GetDocumentsBatchFrom(Etag.Empty, 1); var document = documents.Single(); AddDocumentResult result = null; prefetcher.TransactionalStorage.Batch(accessor => result = accessor.Documents.AddDocument("keys/2", null, document.DataAsJson, document.Metadata)); documents = prefetcher.PrefetchingBehavior.GetDocumentsBatchFrom(document.Etag, 200); Assert.Equal(99, documents.Count); var prevEtag = Etag.Empty; var keys = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var doc in documents) { Assert.True(EtagUtil.IsGreaterThan(document.Etag, prevEtag)); Assert.True(keys.Add(doc.Key)); } }
public void CanProperlyHandleNonConsecutiveUpdates() { Etag last = Etag.Empty; for (int i = 0; i < 5; i++) { last = EtagUtil.Increment(last, 1); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[] { new JsonDocument { Etag = last, Key = i.ToString(CultureInfo.InvariantCulture) }, }); } last = EtagUtil.Increment(last, 10); for (int i = 0; i < 5; i++) { last = EtagUtil.Increment(last, 1); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[] { new JsonDocument { Etag = last, Key = i.ToString(CultureInfo.InvariantCulture) }, }); } Assert.Equal(5, prefetchingBehavior.GetDocumentsBatchFrom(Etag.Empty).Count); Assert.Equal(5, prefetchingBehavior.GetDocumentsBatchFrom(EtagUtil.Increment(Etag.Empty, 15)).Count); }
public IEnumerable <JsonDocument> GetDocumentsAfter(Etag etag, int take, long?maxSize = null, Etag untilEtag = null) { Api.JetSetCurrentIndex(session, Documents, "by_etag"); Api.MakeKey(session, Documents, etag.TransformToValueForEsentSorting(), MakeKeyGrbit.NewKey); if (Api.TrySeek(session, Documents, SeekGrbit.SeekGT) == false) { yield break; } long totalSize = 0; int count = 0; do { if (untilEtag != null && count > 0) { var docEtag = Etag.Parse(Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["etag"])); if (EtagUtil.IsGreaterThanOrEqual(docEtag, untilEtag)) { yield break; } } var readCurrentDocument = ReadCurrentDocument(); totalSize += readCurrentDocument.SerializedSizeOnDisk; if (maxSize != null && totalSize > maxSize.Value) { yield return(readCurrentDocument); yield break; } yield return(readCurrentDocument); count++; } while (Api.TryMoveNext(session, Documents) && count < take); }
public void ShouldCleanUpDocsThatResideInQueueTooLong() { Etag last = Etag.Empty; SystemTime.UtcDateTime = () => DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)); for (int i = 0; i < 5; i++) { last = EtagUtil.Increment(last, 1); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[] { new JsonDocument { Etag = last, Key = i.ToString(CultureInfo.InvariantCulture) }, }); } SystemTime.UtcDateTime = null; prefetchingBehavior.GetDocumentsBatchFrom(Etag.Empty); prefetchingBehavior.CleanupDocuments(Etag.Empty); Assert.Equal(0, prefetchingBehavior.InMemoryIndexingQueueSize); }
public void DocumentStorage_GetBestNextDocumentEtag_NonExistingDocumentEtag_LargerThan_MaxDocumentEtag(string requestedStorage) { using (var storage = NewTransactionalStorage(requestedStorage)) { Etag etag2 = null; Etag etag3 = null; storage.Batch(mutator => mutator.Documents.AddDocument("Foo", Etag.Empty, RavenJObject.FromObject(new { Name = "Bar" }), new RavenJObject())); storage.Batch(mutator => etag2 = mutator.Documents.AddDocument("Foo2", Etag.Empty, RavenJObject.FromObject(new { Name = "Bar" }), new RavenJObject()).Etag); storage.Batch(mutator => etag3 = mutator.Documents.AddDocument("Foo3", Etag.Empty, RavenJObject.FromObject(new { Name = "Bar" }), new RavenJObject()).Etag); Etag resultEtag = null; var nonExistingDocumentEtag = new Etag(UuidType.Documents, 0, 0); storage.Batch(viewer => resultEtag = viewer.Documents.GetBestNextDocumentEtag(nonExistingDocumentEtag)); var e = EtagUtil.Increment(nonExistingDocumentEtag, 1); Assert.Equal(e, resultEtag); } }
private bool IsIndexStateValid(LuceneDirectory luceneDirectory) { // 1. If commitData is null it means that there were no commits, so just in case we are resetting to Etag.Empty // 2. If no 'LastEtag' in commitData then we consider it an invalid index // 3. If 'LastEtag' is present (and valid), then resetting to it (if it is lower than lastStoredEtag) var commitData = IndexReader.GetCommitUserData(luceneDirectory); string value; Etag lastEtag = null; if (commitData != null && commitData.TryGetValue("LastEtag", out value)) { Etag.TryParse(value, out lastEtag); // etag will be null if parsing will fail } var lastStoredEtag = GetLastEtagForIndex() ?? Etag.Empty; lastEtag = lastEtag ?? Etag.Empty; if (EtagUtil.IsGreaterThan(lastEtag, lastStoredEtag)) { return(false); } var checkIndex = new CheckIndex(luceneDirectory); var status = checkIndex.CheckIndex_Renamed_Method(); return(status.clean); }
private bool ShouldReplace(IndexReplaceInformation indexReplaceInformation, int indexId) { bool shouldReplace = false; Database.TransactionalStorage.Batch(accessor => { if (indexReplaceInformation.Forced || Database.IndexStorage.IsIndexStale(indexId, Database.LastCollectionEtags) == false) { shouldReplace = true; // always replace non-stale or forced indexes } else { var replaceIndex = Database.IndexStorage.GetIndexInstance(indexId); var statistics = accessor.Indexing.GetIndexStats(indexId); if (replaceIndex.IsMapReduce == false) { if (statistics.LastIndexedEtag != null && EtagUtil.IsGreaterThanOrEqual(statistics.LastIndexedEtag, indexReplaceInformation.MinimumEtagBeforeReplace)) { shouldReplace = true; } } if (shouldReplace == false && indexReplaceInformation.ReplaceTimeUtc.HasValue && (indexReplaceInformation.ReplaceTimeUtc.Value - SystemTime.UtcNow).TotalSeconds < 0) { shouldReplace = true; } } }); return(shouldReplace); }
public void AbstractScriptedIndexCreationTaskWillResetIndexIfDocumentHasChanged() { using (var store = NewDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new Person { Name = "Name1" }); session.SaveChanges(); } new People_By_Name().Execute(store); var index = new People_By_Name_With_Scripts(); store.DatabaseCommands.Put(ScriptedIndexResults.IdPrefix + index.IndexName, null, new RavenJObject(), new RavenJObject()); WaitForIndexing(store); var stats = store.DatabaseCommands.GetStatistics(); var indexStats = stats.Indexes.First(x => x.Name == index.IndexName); Assert.True(EtagUtil.IsGreaterThan(indexStats.LastIndexedEtag, Etag.Empty)); store.DatabaseCommands.Admin.StopIndexing(); index.Execute(store); stats = store.DatabaseCommands.GetStatistics(); indexStats = stats.Indexes.First(x => x.Name == index.IndexName); Assert.True(indexStats.LastIndexedEtag.Equals(Etag.Empty)); } }
private void SaveSynchronizationSourceInformation(FileSystemInfo sourceFileSystem, Etag lastSourceEtag) { var lastSynchronizationInformation = GetLastSynchronization(sourceFileSystem.Id); if (EtagUtil.IsGreaterThan(lastSynchronizationInformation.LastSourceFileEtag, lastSourceEtag)) { return; } var synchronizationSourceInfo = new SourceSynchronizationInformation { LastSourceFileEtag = lastSourceEtag, SourceServerUrl = sourceFileSystem.Url, DestinationServerId = Storage.Id }; var key = SynchronizationConstants.RavenSynchronizationSourcesBasePath + "/" + sourceFileSystem.Id; Storage.Batch(accessor => accessor.SetConfig(key, JsonExtensions.ToJObject(synchronizationSourceInfo))); if (Log.IsDebugEnabled) { Log.Debug("Saved last synchronized file ETag {0} from {1} ({2})", lastSourceEtag, sourceFileSystem.Url, sourceFileSystem.Id); } }
public Etag CalculateSynchronizationEtag(Etag etag, Etag lastProcessedEtag) { if (etag == null) { if (lastProcessedEtag != null) { lock (locker) { if (currentEtag == null && lastProcessedEtag.CompareTo(synchronizationEtag) != 0) { synchronizationEtag = lastProcessedEtag; PersistSynchronizationState(); } } return(lastProcessedEtag); } return(Etag.Empty); } if (lastProcessedEtag == null) { return(Etag.Empty); } if (etag.CompareTo(lastProcessedEtag) < 0) { return(EtagUtil.Increment(etag, -1)); } return(lastProcessedEtag); }
private bool TryGetDocumentsFromQueue(Etag nextDocEtag, ref List <JsonDocument> items) { JsonDocument result; nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); bool hasDocs = false; while (items.Count < autoTuner.NumberOfItemsToIndexInSingleBatch && prefetchingQueue.TryPeek(out result) && nextDocEtag.CompareTo(result.Etag) >= 0) { // safe to do peek then dequeue because we are the only one doing the dequeues // and here we are single threaded prefetchingQueue.TryDequeue(out result); if (result.Etag != nextDocEtag) { continue; } items.Add(result); hasDocs = true; nextDocEtag = EtagUtil.Increment(nextDocEtag, 1); nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag); } return(hasDocs); }
public void GetLastEtag(string requestedStorage) { using (var storage = NewTransactionalStorage(requestedStorage)) { Etag etag = null; storage.Batch(accessor => etag = accessor.GetLastEtag()); Assert.Equal(Etag.Empty, etag); storage.Batch(accessor => accessor.PutFile("/file1", null, new RavenJObject())); storage.Batch(accessor => etag = accessor.GetLastEtag()); Assert.Equal(EtagUtil.Increment(Etag.Empty, 1), etag); storage.Batch(accessor => accessor.PutFile("/file3", null, new RavenJObject())); storage.Batch(accessor => etag = accessor.GetLastEtag()); Assert.Equal(EtagUtil.Increment(Etag.Empty, 2), etag); storage.Batch(accessor => accessor.PutFile("/file2", 10, new RavenJObject())); storage.Batch(accessor => etag = accessor.GetLastEtag()); Assert.Equal(EtagUtil.Increment(Etag.Empty, 3), etag); storage.Batch(accessor => accessor.PutFile("/file9", 10, new RavenJObject())); storage.Batch(accessor => etag = accessor.GetLastEtag()); Assert.Equal(EtagUtil.Increment(Etag.Empty, 4), etag); } }
public IEnumerable <JsonDocument> GetDocumentsAfter(Etag etag, int take, long?maxSize = null, Etag untilEtag = null) { var docs = storage.Documents["ByEtag"].SkipAfter(new RavenJObject { { "etag", etag.ToByteArray() } }) .Select(result => DocumentByKey(result.Value <string>("key"), null)) .Take(take); long totalSize = 0; int count = 0; foreach (var doc in docs) { totalSize += doc.SerializedSizeOnDisk; if (maxSize != null && totalSize > maxSize.Value) { yield return(doc); yield break; } if (untilEtag != null && count > 0) { if (EtagUtil.IsGreaterThanOrEqual(doc.Etag, untilEtag)) { yield break; } } count++; yield return(doc); } }
protected override async Task <Etag> ExportAttachments(JsonTextWriter jsonWriter, Etag lastEtag) { var totalCount = 0; while (true) { var array = GetAttachments(totalCount, lastEtag); if (array.Length == 0) { var databaseStatistics = await GetStats(); if (lastEtag == null) { lastEtag = Etag.Empty; } if (lastEtag.CompareTo(databaseStatistics.LastAttachmentEtag) < 0) { lastEtag = EtagUtil.Increment(lastEtag, SmugglerOptions.BatchSize); ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}", lastEtag); continue; } ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += array.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", array.Length, totalCount); foreach (var item in array) { item.WriteTo(jsonWriter); } lastEtag = Etag.Parse(array.Last().Value <string>("Etag")); } }
public void ReplaceIndexes(ICollection <int> indexIds) { if (indexIds.Count == 0 || indexesToReplace.Count == 0) { return; } var indexes = new Dictionary <int, IndexReplaceInformation>(); foreach (var indexId in indexIds) { IndexReplaceInformation indexReplaceInformation; if (indexesToReplace.TryGetValue(indexId, out indexReplaceInformation) == false) { continue; } var shouldReplace = false; Database.TransactionalStorage.Batch(accessor => { if (indexReplaceInformation.Forced || Database.IndexStorage.IsIndexStale(indexId, Database.LastCollectionEtags) == false) { shouldReplace = true; // always replace non-stale or forced indexes } else { var replaceIndex = Database.IndexStorage.GetIndexInstance(indexId); var statistics = accessor.Indexing.GetIndexStats(indexId); if (replaceIndex.IsMapReduce) { if (statistics.LastReducedEtag != null && EtagUtil.IsGreaterThanOrEqual(statistics.LastReducedEtag, indexReplaceInformation.MinimumEtagBeforeReplace)) { shouldReplace = true; } } else { if (statistics.LastIndexedEtag != null && EtagUtil.IsGreaterThanOrEqual(statistics.LastIndexedEtag, indexReplaceInformation.MinimumEtagBeforeReplace)) { shouldReplace = true; } } if (shouldReplace == false && indexReplaceInformation.ReplaceTimeUtc.HasValue && (indexReplaceInformation.ReplaceTimeUtc.Value - SystemTime.UtcNow).TotalSeconds < 0) { shouldReplace = true; } } }); if (shouldReplace) { indexes.Add(indexId, indexReplaceInformation); } } ReplaceIndexes(indexes); }
protected override async Task <Etag> ExportAttachments(RavenConnectionStringOptions src, JsonTextWriter jsonWriter, Etag lastEtag, Etag maxEtag) { var totalCount = 0; var maxEtagReached = false; while (true) { try { if (SmugglerOptions.Limit - totalCount <= 0 || maxEtagReached) { ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } var maxRecords = Math.Min(SmugglerOptions.Limit - totalCount, SmugglerOptions.BatchSize); var array = GetAttachments(totalCount, lastEtag, maxRecords); if (array.Length == 0) { var databaseStatistics = await GetStats(); if (lastEtag == null) { lastEtag = Etag.Empty; } if (lastEtag.CompareTo(databaseStatistics.LastAttachmentEtag) < 0) { lastEtag = EtagUtil.Increment(lastEtag, maxRecords); ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}", lastEtag); continue; } ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += array.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", array.Length, totalCount); foreach (var item in array) { var tempLastEtag = item.Value <string>("Etag"); if (maxEtag != null && tempLastEtag.CompareTo(maxEtag) > 0) { maxEtagReached = true; break; } item.WriteTo(jsonWriter); lastEtag = tempLastEtag; } } catch (Exception e) { ShowProgress("Got Exception during smuggler export. Exception: {0}. ", e.Message); ShowProgress("Done with reading attachments, total: {0}", totalCount, lastEtag); throw new SmugglerExportException(e.Message, e) { LastEtag = lastEtag, }; } } }
public void Calculation3() { var synchronizer = new DatabaseEtagSynchronizer(storage); var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer); var someEtag = EtagUtil.Increment(Etag.Empty, 1); Assert.Equal(Etag.Empty, iSynchronizer.CalculateSynchronizationEtag(someEtag, null)); }
private Etag SkipDeletedEtags(Etag nextEtag) { while (documentsToRemove.Any(x => x.Value.Contains(nextEtag))) { nextEtag = EtagUtil.Increment(nextEtag, 1); } return(nextEtag); }
private Etag SkipUpdatedEtags(Etag nextEtag) { while (updatedDocuments.Any(x => x.Value.Contains(nextEtag))) { nextEtag = EtagUtil.Increment(nextEtag, 1); } return(nextEtag); }
protected override async Task <Etag> ExportAttachments(JsonTextWriter jsonWriter, Etag lastEtag, Etag maxEtag) { if (maxEtag != null) { throw new ArgumentException("We don't support maxEtag in SmugglerApi", "maxEtag"); } int totalCount = 0; while (true) { RavenJArray attachmentInfo = null; await commands.CreateRequest("/static/?pageSize=" + SmugglerOptions.BatchSize + "&etag=" + lastEtag, "GET") .ReadResponseJsonAsync() .ContinueWith(task => attachmentInfo = (RavenJArray)task.Result); if (attachmentInfo.Length == 0) { var databaseStatistics = await GetStats(); var lastEtagComparable = new ComparableByteArray(lastEtag); if (lastEtagComparable.CompareTo(databaseStatistics.LastAttachmentEtag) < 0) { lastEtag = EtagUtil.Increment(lastEtag, SmugglerOptions.BatchSize); ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}", lastEtag); continue; } ShowProgress("Done with reading attachments, total: {0}", totalCount); return(lastEtag); } totalCount += attachmentInfo.Length; ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachmentInfo.Length, totalCount); foreach (var item in attachmentInfo) { ShowProgress("Downloading attachment: {0}", item.Value <string>("Key")); byte[] attachmentData = null; await commands.CreateRequest("/static/" + item.Value <string>("Key"), "GET") .ReadResponseBytesAsync() .ContinueWith(task => attachmentData = task.Result); new RavenJObject { { "Data", attachmentData }, { "Metadata", item.Value <RavenJObject>("Metadata") }, { "Key", item.Value <string>("Key") } } .WriteTo(jsonWriter); } lastEtag = Etag.Parse(attachmentInfo.Last().Value <string>("Etag")); } }
public void Calculation5() { var synchronizer = new DatabaseEtagSynchronizer(storage); var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer); var lowerEtag = EtagUtil.Increment(Etag.Empty, 1); var higherEtag = EtagUtil.Increment(Etag.Empty, 2); Assert.Equal(lowerEtag, iSynchronizer.CalculateSynchronizationEtag(higherEtag, lowerEtag)); }
public void CalculationShouldPersist1() { var synchronizer = new DatabaseEtagSynchronizer(storage); var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer); var lowerEtag = EtagUtil.Increment(Etag.Empty, 1); Assert.Equal(lowerEtag, iSynchronizer.CalculateSynchronizationEtag(null, lowerEtag)); Assert.Equal(2, numberOfCalls); }
private Etag GetNextDocEtag(Etag etag) { var oneUpEtag = EtagUtil.Increment(etag, 1); // no need to go to disk to find the next etag if we already have it in memory if (prefetchingQueue.NextDocumentETag() == oneUpEtag) { return(oneUpEtag); } return(GetNextDocumentEtagFromDisk(etag)); }
public void ShouldDisableCollectingDocsAfterCommit() { Etag last = Etag.Empty; SystemTime.UtcDateTime = () => DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(Enumerable.Range(0, 5).Select(x => { last = EtagUtil.Increment(last, 1); return(new JsonDocument { Etag = last, Key = x.ToString(CultureInfo.InvariantCulture) }); }).ToArray()); last = EtagUtil.Increment(last, store.Configuration.MaxNumberOfItemsToProcessInSingleBatch); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(Enumerable.Range(0, 5).Select(x => { last = EtagUtil.Increment(last, 1); return(new JsonDocument { Etag = last, Key = x.ToString(CultureInfo.InvariantCulture) }); }).ToArray()); SystemTime.UtcDateTime = null; var documentsBatchFrom = prefetchingBehavior.GetDocumentsBatchFrom(Etag.Empty); prefetchingBehavior.CleanupDocuments(documentsBatchFrom.Last().Etag); Assert.True(prefetchingBehavior.DisableCollectingDocumentsAfterCommit); for (int i = 0; i < 5; i++) { last = EtagUtil.Increment(last, 1); prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[] { new JsonDocument { Etag = last, Key = i.ToString(CultureInfo.InvariantCulture) }, }); } Assert.Equal(0, prefetchingBehavior.InMemoryIndexingQueueSize); }
public void Can_increment_last_etag() { var client = NewAsyncClient(1); var id = Guid.NewGuid(); var etag = EtagUtil.Increment(Etag.Empty, 5); client.Synchronization.IncrementLastETagAsync(id, "http://localhost:12345", etag).Wait(); var lastSyncInfo = client.Synchronization.GetLastSynchronizationFromAsync(id).Result; Assert.Equal(etag, lastSyncInfo.LastSourceFileEtag); }
public void ConcurrentJsonDocumentSortedListShouldSortByEtag() { var list = new ConcurrentJsonDocumentSortedList(); var etag1 = EtagUtil.Increment(Etag.Empty, 1); var etag2 = EtagUtil.Increment(Etag.Empty, 2); var etag3 = EtagUtil.Increment(Etag.Empty, 3); var etag4 = EtagUtil.Increment(Etag.Empty, 4); var doc1 = new JsonDocument { Etag = etag1 }; var doc2 = new JsonDocument { Etag = etag2 }; var doc3 = new JsonDocument { Etag = etag3 }; var doc4 = new JsonDocument { Etag = etag4 }; using (list.EnterWriteLock()) { list.Add(doc4); list.Add(doc2); list.Add(doc1); list.Add(doc3); } JsonDocument result; Assert.True(list.TryDequeue(out result)); Assert.Equal(doc1.Etag, result.Etag); Assert.True(list.TryDequeue(out result)); Assert.Equal(doc2.Etag, result.Etag); Assert.True(list.TryDequeue(out result)); Assert.Equal(doc3.Etag, result.Etag); Assert.True(list.TryDequeue(out result)); Assert.Equal(doc4.Etag, result.Etag); }
public void SynchronizerShouldReturnNullIfNoNewEtagsArrivedFromLastGet() { var synchronizer = new DatabaseEtagSynchronizer(storage); var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer); var someEtag = EtagUtil.Increment(Etag.Empty, 1); iSynchronizer.UpdateSynchronizationState(someEtag); var etag = iSynchronizer.GetSynchronizationEtag(); Assert.Equal(someEtag, etag); Assert.Null(iSynchronizer.GetSynchronizationEtag()); }
private void PutSideBySideIndexDocument(SideBySideReplicationInfo sideBySideReplicationInfo) { using (Database.DocumentLock.Lock()) { var id = Constants.IndexReplacePrefix + sideBySideReplicationInfo.SideBySideIndex.Name; var indexReplaceDocument = sideBySideReplicationInfo.IndexReplaceDocument; if (indexReplaceDocument.MinimumEtagBeforeReplace != null) //TODO : verify that this is OK -> not sure { indexReplaceDocument.MinimumEtagBeforeReplace = EtagUtil.Increment(Database.Statistics.LastDocEtag, 1); } Database.TransactionalStorage.Batch(accessor => accessor.Documents.AddDocument(id, null, RavenJObject.FromObject(indexReplaceDocument), new RavenJObject())); } }