Beispiel #1
0
        public override async Task <BoolResult> StartupAsync(Context context)
        {
            if (_fileSystem.FileExists(_localContentDirectoryPath))
            {
                await _fileSystem.CopyFileAsync(_localContentDirectoryPath, Directory.FilePath, replaceExisting : true);
            }

            await Directory.StartupAsync(context).ThrowIfFailure();

            return(BoolResult.Success);
        }
Beispiel #2
0
        private async Task HardlinkWithFallBackAsync(OperationContext context, AbsolutePath source, AbsolutePath target)
        {
            _fileSystem.CreateDirectory(target.Parent);

            var createHardLinkResult = _fileSystem.CreateHardLink(source, target, replaceExisting: true);

            if (createHardLinkResult != CreateHardLinkResult.Success)
            {
                context.TraceDebug($"{_tracer.Name}: Hardlinking {source} to {target} failed: {createHardLinkResult}. Copying...");
                await _fileSystem.CopyFileAsync(source, target, replaceExisting : true);
            }
        }
Beispiel #3
0
        public async Task <Result <AbsolutePath> > BackupAsync(OperationContext context, AbsolutePath instancePath, string?name = null)
        {
            int          numCopiedFiles = 0;
            AbsolutePath?backupPath     = null;

            return(await context.PerformOperationAsync(_tracer, async() =>
            {
                var backupTime = _clock.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture);
                var backupName = backupTime;
                if (!string.IsNullOrEmpty(name))
                {
                    backupName += $"-{name}";
                }
                backupPath = _backupPath / backupName;

                // Unlikely, but it is possible for GC to start running and think that it should purge this directory,
                // this avoids the scenario.
                using var _ = await _locks.AcquireAsync(backupPath);

                if (_fileSystem.DirectoryExists(backupPath))
                {
                    _fileSystem.DeleteDirectory(backupPath, DeleteOptions.All);
                }
                _fileSystem.CreateDirectory(backupPath);

                // See: https://github.com/facebook/rocksdb/wiki/rocksdb-basics#database-debug-logs
                _fileSystem.EnumerateFiles(instancePath, "*LOG*", false,
                                           async fileInfo =>
                {
                    var fileName = fileInfo.FullPath.FileName;
                    var targetFilePath = backupPath / fileName;

                    await _fileSystem.CopyFileAsync(fileInfo.FullPath, targetFilePath, replaceExisting: true);

                    ++numCopiedFiles;
                });

                if (numCopiedFiles == 0)
                {
                    _fileSystem.DeleteDirectory(backupPath, DeleteOptions.All);
                }

                return new Result <AbsolutePath>(backupPath);
            }, extraEndMessage : _ => $"From=[{instancePath}] To=[{backupPath?.ToString() ?? "Unknown"}] NumCopiedFiles=[{numCopiedFiles}]"));