Esempio n. 1
0
        internal ReadResult Read(RavenJToken key, Guid txId)
        {
            byte[] readData = null;

            Guid mofiedByTx;

            if (keysModifiedInTx.TryGetValue(key, out mofiedByTx) && mofiedByTx == txId)
            {
                Command command = operationsInTransactions.GetOrAdd(txId, new List <Command>()).LastOrDefault(
                    x => comparer.Equals(x.Key, key));

                if (command != null)
                {
                    switch (command.Type)
                    {
                    case CommandType.Put:
                        return(new ReadResult
                        {
                            Position = command.Position,
                            Size = command.Size,
                            Data = () => readData ?? (readData = ReadData(command)),
                            Key = command.Key
                        });

                    case CommandType.Delete:
                        return(null);

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            return(persistentSource.Read(log =>
            {
                PositionInFile pos;
                if (KeyToFilePos.TryGetValue(key, out pos) == false)
                {
                    return null;
                }

                return new ReadResult
                {
                    Position = pos.Position,
                    Size = pos.Size,
                    Data = () => readData ?? (readData = ReadData(pos.Position, pos.Size, pos.Key)),
                    Key = pos.Key
                };
            }));
        }
Esempio n. 2
0
        public void Execute(object ignored)
        {
            try
            {
                to  = to.ToFullPath();
                src = src.ToFullPath();
                logger.Info("Starting backup of '{0}' to '{1}'", src, to);
                var directoryBackups = new List <DirectoryBackup>
                {
                    new DirectoryBackup(src, to, Path.Combine("TempData" + Guid.NewGuid().ToString("N")), false),
                    new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"),
                                        Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), false)
                };
                directoryBackups.AddRange(from index in Directory.GetDirectories(database.Configuration.IndexStoragePath)
                                          let fromIndex = Path.Combine(database.Configuration.IndexStoragePath, Path.GetFileName(index))
                                                          let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index))
                                                                        let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories", Guid.NewGuid().ToString("N")))
                                                                                        select new DirectoryBackup(fromIndex, toIndex, tempIndex, false));


                persistentSource.Read(log =>
                {
                    persistentSource.FlushLog();

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Notify += UpdateBackupStatus;
                        directoryBackup.Prepare();
                    }

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Execute();
                    }

                    return(0);                   // ignored
                });
            }
            catch (Exception e)
            {
                logger.ErrorException("Failed to complete backup", e);
                UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error);
            }
            finally
            {
                CompleteBackup();
            }
        }
Esempio n. 3
0
        public void Execute()
        {
            try
            {
                to  = to.ToFullPath();
                src = src.ToFullPath();
                logger.Info("Starting backup of '{0}' to '{1}'", src, to);
                var directoryBackups = new List <DirectoryBackup>
                {
                    new DirectoryBackup(src, to, Path.Combine("TempData" + Guid.NewGuid().ToString("N")), false),
                    new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"),
                                        Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), false)
                };

                database.IndexStorage.Backup(to);

                persistentSource.Read(log =>
                {
                    persistentSource.FlushLog();

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Notify += UpdateBackupStatus;
                        directoryBackup.Prepare();
                    }

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Execute();
                    }

                    return(0);                   // ignored
                });
            }
            catch (Exception e)
            {
                logger.ErrorException("Failed to complete backup", e);
                UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error);
            }
            finally
            {
                CompleteBackup();
            }
        }
Esempio n. 4
0
 public IEnumerable <RavenJToken> SkipFromEnd(int start)
 {
     return(persistentSource.Read(() => Index.ValuesInReverseOrder.Skip(start).Select(item => item.Key)));
 }