private Task <PushFileResult> PushCheckpointFileAsync(OperationContext context, ContentHashWithSize hashWithSize) { return(context.PerformOperationAsync(Tracer, async() => { var destinationMachineResult = _locationStore.GetRandomMachineLocation(); if (!destinationMachineResult.Succeeded) { return new PushFileResult(destinationMachineResult, "Failed to get a location to proactively copy the checkpoint file."); } var destionationMachine = destinationMachineResult.Value; var streamResult = await PrivateCas.OpenStreamAsync(context, hashWithSize.Hash, pinRequest: null); if (!streamResult.Succeeded) { return new PushFileResult(streamResult, "Should have been able to open the stream from the local CAS"); } using var stream = streamResult.Stream !; return await _copier.PushFileAsync( context, hashWithSize, destionationMachine, stream, isInsideRing: false, CopyReason.ProactiveCheckpointCopy, ProactiveCopyLocationSource.Random, attempt: 0); },
private async Task <ContentHashWithSize> TryGetFromFallbackAndPutAsync(OperationContext context, AbsolutePath targetFilePath, string fallbackStorageId, bool isImmutable) { // In the success case the content will be put at targetFilePath await _fallbackStorage.TryGetFileAsync(context, fallbackStorageId, targetFilePath, isImmutable).ThrowIfFailure(); var placementFileRealizationMode = isImmutable ? FileRealizationMode.Any : FileRealizationMode.Copy; var putResult = await PrivateCas.PutFileAsync(context, targetFilePath, placementFileRealizationMode, HashType, pinRequest : null).ThrowIfFailure(); return(new ContentHashWithSize(putResult.ContentHash, putResult.ContentSize)); }
protected async override Task <BoolResult> PruneInternalCacheCoreAsync(OperationContext context, string storageId) { var(hash, fallbackStorageId) = ParseCompositeStorageId(storageId); if (hash is null) { return(new BoolResult(errorMessage: $"Could not parse content hash from storage id `{storageId}`")); } return(await PrivateCas.DeleteAsync(context, hash.Value, new Interfaces.Stores.DeleteContentOptions() { DeleteLocalOnly = true, })); }
public bool TryGetContentInfo(string storageId, out ContentHash hash, out long size) { var parsed = ParseCompositeStorageId(storageId); if (parsed.hash != null) { hash = parsed.hash.Value; return(PrivateCas.Contains(hash, out size)); } hash = default; size = default; return(false); }
protected virtual async Task <PutResult> PutFileAsync(OperationContext context, AbsolutePath file, ContentHash?hash, bool isImmutable = false, bool isUpload = false) { var putFileRealizationMode = isImmutable ? FileRealizationMode.Any : FileRealizationMode.Copy; PutResult putResult; if (hash != null) { putResult = await PrivateCas.PutFileAsync(context, file, putFileRealizationMode, hash.Value, pinRequest : null).ThrowIfFailure(); } else { putResult = await PrivateCas.PutFileAsync(context, file, putFileRealizationMode, HashType, pinRequest : null).ThrowIfFailure(); } return(putResult); }
protected virtual async Task <Result <ContentHashWithSize> > TryGetAndPutFileAsync(OperationContext context, string storageId, AbsolutePath targetFilePath, bool isImmutable) { var(hash, fallbackStorageId) = ParseCompositeStorageId(storageId); if (hash != null) { var fileAccessMode = isImmutable ? FileAccessMode.ReadOnly : FileAccessMode.Write; var fileRealizationMode = isImmutable ? FileRealizationMode.Any : FileRealizationMode.Copy; if (PrivateCas.Contains(hash.Value) || await TryRetrieveFromExternalCacheAsync(context, hash.Value)) { // First attempt to place file from content store var placeResult = await PrivateCas.PlaceFileAsync(context, hash.Value, targetFilePath, fileAccessMode, FileReplacementMode.ReplaceExisting, fileRealizationMode, pinRequest : null); if (placeResult.IsPlaced()) { return(Result.Success(new ContentHashWithSize(hash.Value, placeResult.FileSize))); } } } Counters[CentralStorageCounters.TryGetFileFromFallback].Increment(); return(await TryGetFromFallbackAndPutAsync(context, targetFilePath, fallbackStorageId, isImmutable)); }
protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context) { await PrivateCas.ShutdownAsync(context).ThrowIfFailure(); return(await base.ShutdownCoreAsync(context)); }
public virtual bool HasContent(ContentHash contentHash) { return(PrivateCas.Contains(contentHash)); }
public virtual Task <OpenStreamResult> StreamContentAsync(Context context, ContentHash contentHash) { return(PrivateCas.OpenStreamAsync(context, contentHash, pinRequest: null)); }