public bool MoveNext() { Current = null; while (_counters.MoveNext()) { var current = _counters.Current; if (CanMoveNextAndNotExceedLastDocumentInBatch(current.Etag, _lastProcessedDocEtagInBatch) == false) { return(false); } var doc = _docsStorage.Get(_context, current.DocumentId); if (doc != null && current.Etag > doc.Etag) { Current = current; return(true); } // counter has lower etag than its document - we skip it to avoid // sending a counter of document that can not exist on the destination side _stats.RecordChangeVector(current.ChangeVector); _stats.RecordLastFilteredOutEtag(current.Etag, EtlItemType.Counter); } return(false); }
public unsafe dynamic LoadDocument(LazyStringValue keyLazy, string keyString, string collectionName) { using (_loadDocumentStats?.Start() ?? (_loadDocumentStats = _stats?.For(IndexingOperation.LoadDocument))) { if (keyLazy == null && keyString == null) { return(DynamicNullObject.Null); } var source = Source; var id = GetSourceId(source); if (source is DynamicBlittableJson) { if (keyLazy != null && id.Equals(keyLazy)) { return(source); } if (keyString != null && id.Equals(keyString)) { return(source); } } if (TryGetKeySlice(keyLazy, keyString, out var keySlice) == false) { return(DynamicNullObject.Null); } // we intentionally don't dispose of the scope here, this is being tracked by the references // and will be disposed there. Slice.From(QueryContext.Documents.Allocator, id, out var idSlice); var references = GetReferencesForItem(idSlice); references.Add(keySlice); // when there is conflict, we need to apply same behavior as if the document would not exist var document = _documentsStorage.Get(QueryContext.Documents, keySlice, throwOnConflict: false); if (document == null) { return(DynamicNullObject.Null); } if (document.TryGetMetadata(out var metadata) && metadata.TryGet(Constants.Documents.Metadata.Collection, out string collection)) { if (string.Equals(collection, collectionName, StringComparison.OrdinalIgnoreCase) == false) { return(DynamicNullObject.Null); } } // we can't share one DynamicBlittableJson instance among all documents because we can have multiple LoadDocuments in a single scope return(new DynamicBlittableJson(document)); } }
protected override Document LoadDocument(string id) { if (DocumentsStorage != null && _context is DocumentsOperationContext ctx) { return(DocumentsStorage.Get(ctx, id)); } // can happen during some debug endpoints that should never load a document return(null); }
protected override Document DirectGet(Lucene.Net.Documents.Document input, string id) { var doc = _documentsStorage.Get(_context, id); if (doc == null) { return(null); } return(doc); }
public void Recreate <T>(DocumentsOperationContext context, string docId) where T : IRecreationType { var doc = _documentsStorage.Get(context, docId); if (doc?.Data == null) { return; } var type = _recreationTypes.Single(t => t.GetType() == typeof(T)); using (doc.Data) { PutDocument(context, docId, expectedChangeVector: null, document: doc.Data, nonPersistentFlags: type.ResolveConflictFlag); } }
public bool MoveNext() { Current = null; while (_counters.MoveNext()) { var current = _counters.Current; var doc = _docsStorage.Get(_context, current.DocumentId); if (doc != null && current.Etag > doc.Etag) { Current = current; return(true); } _stats.RecordChangeVector(current.ChangeVector); _stats.RecordLastFilteredOutEtag(current.Etag, EtlItemType.Counter); } return(false); }
public void Fill(List <Document> result) { if (_includedIds == null || _includedIds.Count == 0) { return; } foreach (var includedDocId in _includedIds) { if (includedDocId == null) //precaution, should not happen { continue; } var includedDoc = _storage.Get(_context, includedDocId); if (includedDoc == null) { continue; } result.Add(includedDoc); } }
protected override Document LoadDocument(string id) { return(DocumentsStorage.Get(_context, id)); }
public override Document DirectGet(Lucene.Net.Documents.Document input, string id, DocumentFields fields, IState state) { return(DocumentsStorage.Get(_context, id, fields)); }
protected override Document LoadDocument(string id) => DocumentsStorage.Get(_context, id);
protected override Document DirectGet(Lucene.Net.Documents.Document input, string id, DocumentFields fields, IState state) => DocumentsStorage.Get(_context, id);
protected override Document DirectGet(Lucene.Net.Documents.Document input, string id, IState state) { return(DocumentsStorage.Get(_context, id)); }
public unsafe dynamic LoadDocument(LazyStringValue keyLazy, string keyString, string collectionName) { using (_loadDocumentStats?.Start() ?? (_loadDocumentStats = _stats?.For(IndexingOperation.LoadDocument))) { if (keyLazy == null && keyString == null) { return(DynamicNullObject.Null); } var source = Source; if (source == null) { throw new ArgumentException("Cannot execute LoadDocument. Source is not set."); } var id = source.GetId() as LazyStringValue; if (id == null) { throw new ArgumentException("Cannot execute LoadDocument. Source does not have a key."); } if (keyLazy != null && id.Equals(keyLazy)) { return(source); } if (keyString != null && id.Equals(keyString)) { return(source); } Slice keySlice; if (keyLazy != null) { if (keyLazy.Length == 0) { return(DynamicNullObject.Null); } // we intentionally don't dispose of the scope here, this is being tracked by the references // and will be disposed there. Slice.External(_documentsContext.Allocator, keyLazy.Buffer, keyLazy.Size, out keySlice); } else { if (keyString.Length == 0) { return(DynamicNullObject.Null); } // we intentionally don't dispose of the scope here, this is being tracked by the references // and will be disposed there. Slice.From(_documentsContext.Allocator, keyString, out keySlice); } // making sure that we normalize the case of the key so we'll be able to find // it in case insensitive manner _documentsContext.Allocator.ToLowerCase(ref keySlice.Content); var references = GetReferencesForDocument(id); var referenceEtags = GetReferenceEtags(); references.Add(keySlice); // when there is conflict, we need to apply same behavior as if the document would not exist var document = _documentsStorage.Get(_documentsContext, keySlice, throwOnConflict: false); if (document == null) { MaybeUpdateReferenceEtags(referenceEtags, collectionName, 0); return(DynamicNullObject.Null); } MaybeUpdateReferenceEtags(referenceEtags, collectionName, document.Etag); // we can't share one DynamicBlittableJson instance among all documents because we can have multiple LoadDocuments in a single scope return(new DynamicBlittableJson(document)); } }
public unsafe dynamic LoadDocument(LazyStringValue keyLazy, string keyString) { if (keyLazy == null && keyString == null) { return(DynamicNullObject.Null); } var source = Source; if (source == null) { throw new ArgumentException("Cannot execute LoadDocument. Source is not set."); } var id = source.__document_id as LazyStringValue; if (id != null) { if (keyLazy != null && id.Equals(keyLazy)) { return(source); } if (keyString != null && id.Equals(keyString)) { return(source); } } ByteStringContext.Scope scope; Slice keySlice; if (keyLazy != null) { if (keyLazy.Length == 0) { return(DynamicNullObject.Null); } scope = Slice.External(_documentsContext.Allocator, keyLazy.Buffer, keyLazy.Size, out keySlice); } else { if (keyString.Length == 0) { return(DynamicNullObject.Null); } scope = Slice.From(_documentsContext.Allocator, keyString, out keySlice); } // making sure that we normalize the case of the key so we'll be able to find // it in case insensitive manner _documentsContext.Allocator.ToLowerCase(ref keySlice.Content); var document = _documentsStorage.Get(_documentsContext, keySlice); scope.Dispose(); if (document == null) { return(DynamicNullObject.Null); } if (LoadedDocumentEtags == null) { LoadedDocumentEtags = new List <long>(); } LoadedDocumentEtags.Add(document.Etag); document.EnsureMetadata(); // we can't share one DynamicBlittableJson instance among all documents because we can have multiple LoadDocuments in a single scope return(new DynamicBlittableJson(document)); }