public static IIronLeveldb Build(this IIronLeveldbStorge storge, IronLeveldbOptions options)
        {
            var manifestContent = storge.GetCurrentDescriptorContent();

            // TODO base version
            var b = new Version.Builder(storge, options, null);

            using (var manifestStream = manifestContent.AsStream())
            {
                foreach (var stream in new RecoverLogRecordsStream(manifestStream))
                {
                    var versionEdit = VersionEdit.DecodeFrom(stream);

                    b.With(versionEdit);
                }
            }

            var current = b.Build();

            return(new IronLeveldbStub(options, current, () =>
            {
                var es = new List <Exception>();
                try
                {
                    storge.Dispose();
                }
                catch (Exception e)
                {
                    es.Add(e);
                }

                try
                {
                    current.Dispose();
                }
                catch (Exception e)
                {
                    es.Add(e);
                }

                if (es.Count > 1)
                {
                    throw new AggregateException(es);
                }

                if (es.Count == 1)
                {
                    throw es.First();
                }
            }));
        }
        public ActionResult Edit(int id)
        {
            var svc    = new VersionService();
            var detail = svc.GetVersionById(id);
            var model  =
                new VersionEdit
            {
                Id          = detail.Id,
                Name        = detail.Name,
                Description = detail.Description,
                ReleaseYear = detail.ReleaseYear
            };

            return(View(model));
        }
Exemple #3
0
        public bool UpdateVersion(VersionEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Versions
                    .Single(e => e.Id == model.Id);

                entity.Name        = model.Name;
                entity.Description = model.Description;
                entity.ReleaseYear = model.ReleaseYear;

                return(ctx.SaveChanges() == 1);
            }
        }
		public Compaction(StorageState storageContext, int level, Version inputVersion = null)
		{
			this.storageContext = storageContext;
			Level = level;
			MaxOutputFileSize = CalculateMaxOutputFileSize(level);
			this.inputVersion = inputVersion;
			Edit = new VersionEdit();
			Inputs = new[]
			    {
			        new List<FileMetadata>(), 
                    new List<FileMetadata>()
			    };
			Grandparents = new List<FileMetadata>();
			grandparentIndex = 0;
			seenKey = false;
			overlappedBytes = 0;

			levelPointers = new int[Config.NumberOfLevels];

			for (int lvl = 0; lvl < Config.NumberOfLevels; lvl++)
			{
				levelPointers[lvl] = 0;
			}
		}
        public ActionResult Edit(int id, VersionEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var svc = new VersionService();

            if (svc.UpdateVersion(model))
            {
                TempData["SaveResult"] = "Your version was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your version could not be updated.");
            return(View(model));
        }
		/// <summary>
		/// Add all inputs to this compaction as delete operations to *edit.
		/// </summary>
		/// <param name="edit"></param>
		public void AddInputDeletions(VersionEdit edit)
		{
			for (var which = 0; which < 2; which++)
			{
				for (var i = 0; i < Inputs[which].Count; i++)
				{
					edit.DeleteFile(Level + which, Inputs[which][i].FileNumber);
				}
			}
		}
		public void WriteLevel0Table(MemTable memTable, Version currentVersion, VersionEdit edit)
		{
			var stopwatch = Stopwatch.StartNew();
			var fileNumber = state.VersionSet.NewFileNumber();

			pendingOutputs.Add(fileNumber);

			var fileMetadata = state.BuildTable(memTable, fileNumber);

			pendingOutputs.Remove(fileNumber);

			// Note that if file_size is zero, the file has been deleted and
			// should not be added to the manifest.
			int level = 0;
			if (fileMetadata.FileSize > 0)
			{
				var minUserKey = fileMetadata.SmallestKey.UserKey;
				var maxUserKey = fileMetadata.LargestKey.UserKey;

				if (currentVersion != null)
				{
					level = currentVersion.PickLevelForMemTableOutput(minUserKey, maxUserKey);
				}

				edit.AddFile(level, fileMetadata);
			}

			state.CompactionStats[level].Add(new CompactionStats
			{
				Milliseconds = stopwatch.ElapsedMilliseconds,
				BytesRead = 0,
				BytesWritten = fileMetadata.FileSize
			});
		}
		/// <summary>
		/// Compact the in-memory write buffer to disk.  Switches to a new
		/// log-file/memtable and writes a new descriptor if successful.
		/// </summary>
		/// <param name="locker"></param>
		private async Task CompactMemTableAsync(AsyncLock.LockScope locker)
		{
			MemTable immutableMemTable;
			Version currentVersion;

			using (await locker.LockAsync())
			{
				if (state.ImmutableMemTable == null)
					throw new InvalidOperationException("ImmutableMemTable cannot be null.");

				immutableMemTable = state.ImmutableMemTable;
				currentVersion = state.VersionSet.Current;
			}

			state.CancellationToken.ThrowIfCancellationRequested();
			var edit = new VersionEdit();
			WriteLevel0Table(immutableMemTable, currentVersion, edit);

			// Replace immutable memtable with the generated Table

			edit.SetPrevLogNumber(0);
			edit.SetLogNumber(state.LogFileNumber);
			await state.LogAndApplyAsync(edit, locker).ConfigureAwait(false);

			state.ImmutableMemTable = null;

			DeleteObsoleteFiles();
		}