public void DeleteMappedResultsForDocumentId(string documentId, string view, Dictionary<ReduceKeyAndBucket, int> removed)
		{
			foreach (var key in storage.MappedResults["ByViewAndDocumentId"].SkipTo(new RavenJObject
			{
				{"view", view},
				{"docId", documentId}
			}).TakeWhile(x => StringComparer.OrdinalIgnoreCase.Equals(x.Value<string>("view"), view) &&
							  StringComparer.OrdinalIgnoreCase.Equals(x.Value<string>("docId"), documentId)))
			{
				storage.MappedResults.Remove(key);

				var reduceKey = key.Value<string>("reduceKey");
				var bucket = new ReduceKeyAndBucket(key.Value<int>("bucket"), reduceKey);
				removed[bucket] = removed.GetOrDefault(bucket) + 1;
			}
		}
Esempio n. 2
0
		public void DeleteMappedResultsForDocumentId(string documentId, string view, Dictionary<ReduceKeyAndBucket, int> removed)
		{
			Api.JetSetCurrentIndex(session, MappedResults, "by_view_and_doc_key");
			Api.MakeKey(session, MappedResults, view, Encoding.Unicode, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, MappedResults, documentId, Encoding.Unicode, MakeKeyGrbit.None);
			if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekEQ) == false)
				return;

			Api.MakeKey(session, MappedResults, view, Encoding.Unicode, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, MappedResults, documentId, Encoding.Unicode, MakeKeyGrbit.None);
			Api.JetSetIndexRange(session, MappedResults, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive);
			do
			{
				// esent index ranges are approximate, and we need to check them ourselves as well
				var viewFromDb = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"]);
				if (StringComparer.OrdinalIgnoreCase.Equals(viewFromDb, view) == false)
					continue;
				var documentIdFromDb = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["document_key"]);
				if (StringComparer.OrdinalIgnoreCase.Equals(documentIdFromDb, documentId) == false)
					continue;
				var reduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"],
														   Encoding.Unicode);
				var bucket = Api.RetrieveColumnAsInt32(session, MappedResults, tableColumnsCache.MappedResultsColumns["bucket"]).Value;

				var key = new ReduceKeyAndBucket(bucket, reduceKey);
				removed[key] = removed.GetOrDefault(key) + 1;
				Api.JetDelete(session, MappedResults);
			} while (Api.TryMoveNext(session, MappedResults));
		}
Esempio n. 3
0
		public void ScheduleReductions(string view, int level, ReduceKeyAndBucket reduceKeysAndBucket)
		{
			var bucket = reduceKeysAndBucket.Bucket;

			using (var map = new Update(session, ScheduledReductions, JET_prep.Insert))
			{
				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["view"],
							  view, Encoding.Unicode);
				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["reduce_key"],
							  reduceKeysAndBucket.ReduceKey, Encoding.Unicode);
				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["hashed_reduce_key"],
							  HashReduceKey(reduceKeysAndBucket.ReduceKey));

					Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["etag"], uuidGenerator.CreateSequentialUuid(UuidType.ScheduledReductions).ToByteArray());

				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["timestamp"],
							  SystemTime.UtcNow.ToBinary());


				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["bucket"],
							  bucket);

				Api.SetColumn(session, ScheduledReductions, tableColumnsCache.ScheduledReductionColumns["level"], level);
				map.Save();
			}
		}
Esempio n. 4
0
 protected bool Equals(ReduceKeyAndBucket other)
 {
     return(Bucket == other.Bucket && string.Equals(ReduceKey, other.ReduceKey));
 }
		protected bool Equals(ReduceKeyAndBucket other)
		{
			return Bucket == other.Bucket && string.Equals(ReduceKey, other.ReduceKey);
		}
		public void ScheduleReductions(string view, int level, ReduceKeyAndBucket reduceKeysAndBucket)
		{
			var etag = generator.CreateSequentialUuid(UuidType.ScheduledReductions).ToByteArray();
			storage.ScheduleReductions.UpdateKey(new RavenJObject
			{
				{"view", view},
				{"reduceKey", reduceKeysAndBucket.ReduceKey},
				{"bucket", reduceKeysAndBucket.Bucket},
				{"level", level},
				{"etag", etag},
				{"timestamp", SystemTime.UtcNow}
			});
		}