/// <summary> /// Initializes a new instance of the <see cref="Metadata"/> class. /// </summary> internal Metadata( Uri name, Type type, IStateProvider2 stateProvider, byte[] initializationParameters, long stateProviderId, long parentId, long createLsn, long deleteLsn, MetadataMode metadataMode, bool transientCreate) { Utility.Assert(name != null, "Name cannot be empty in metadata."); Utility.Assert(type != null, "type cannot be null."); Utility.Assert(stateProvider != null, "state provider cannot be null."); Utility.Assert( stateProviderId != DynamicStateManager.EmptyStateProviderId, "state provider id cannot be empty."); // Parent Id can be empty so do not assert on it. this.Initialize( name, type, stateProvider, initializationParameters, stateProviderId, parentId, createLsn, deleteLsn, metadataMode, transientCreate); }
/// <summary> /// Initializes metadata. /// </summary> private void Initialize( Uri name, Type type, IStateProvider2 stateProvider, byte[] initializationParameters, long stateProviderId, long parentId, long createLsn, long deleteLsn, MetadataMode metadataMode, bool transientCreate) { this.Name = name; this.Type = type; this.StateProvider = stateProvider; this.StateProviderId = stateProviderId; this.InitializationContext = initializationParameters; this.CreateLsn = createLsn; this.DeleteLsn = deleteLsn; this.TransientCreate = transientCreate; this.TransientDelete = false; this.checkpointFlag = 1; this.MetadataMode = metadataMode; this.TransactionId = 0; this.ParentStateProviderId = parentId; }
private CompressionLevelInferrer PickEncoder(MetadataMode metadataMode) { switch (metadataMode) { case MetadataMode.Preserve: return(metadataPreservedService); case MetadataMode.Discard: return(metadataDiscardedService); default: throw new NotSupportedException("The mode is supported"); } }
/// <summary> /// Initializes a new instance of the <see cref="SerializableMetadata"/> class. /// </summary> public SerializableMetadata( Uri name, string type, byte[] initializationParameters, long stateProviderId, long parentStateProviderId, MetadataMode metadataMode, long createLsn, long deleteLsn) : this(name, initializationParameters, stateProviderId, parentStateProviderId, metadataMode, createLsn, deleteLsn) { Utility.Assert(type != null, "type cannot be null."); this.TypeString = type; this.Type = null; }
/// <summary> /// Deletes state provider key from the dictionary. This is called as a part of a transaction only. Hence lock has already been acquired and no lock is needed. /// </summary> public void SoftDelete(Uri key, MetadataMode metadataMode) { var lockContext = this.keylocks[key]; Metadata metadata = null; this.inMemoryState.TryGetValue(key, out metadata); Utility.Assert( metadata != null, "{0}: SoftDelete: Metadata cannot be null for state provider: {1}", this.traceType, key.OriginalString); Utility.Assert( metadata.StateProvider != null, "{0}: SoftDelete: State provider cannot be null for {1}", this.traceType, key.OriginalString); // close the state provider. not closing for now, to avoid race conditions with copy. // await metadata.StateProvider.CloseAsync().ConfigureAwait(false); metadata.MetadataMode = metadataMode; var addMetadataToDeleteList = this.DeletedStateProviders.TryAdd(metadata.StateProviderId, metadata); Utility.Assert( addMetadataToDeleteList, "{0}: SoftDelete: failed to add state provider {1} to delete list", this.traceType, key.OriginalString); // only data is removed here, lock should not be removed here as unlock of this transaction needs the lock. Metadata metadataToBeRemoved = null; var isRemoved = this.inMemoryState.TryRemove(key, out metadataToBeRemoved); Utility.Assert( isRemoved, "{0}: SoftDelete: failed to remove data for key {1}", this.traceType, key.OriginalString); // Remove from id-stateprovider provider map. Metadata outMetadata = null; isRemoved = this.stateProviderIdMap.TryRemove(metadata.StateProviderId, out outMetadata); Utility.Assert( isRemoved, "{0}: SoftDelete: failed to remove data for key {1} from stateprovider id map", this.traceType, metadata.StateProviderId); }
/// <summary> /// Initializes a new instance of the <see cref="SerializableMetadata"/> class. /// </summary> internal SerializableMetadata( Uri name, byte[] initializationParameters, long stateProviderId, long parentStateProviderId, MetadataMode metadataMode, long createLsn, long deleteLsn) { Utility.Assert(name != null, "Name cannot be empty in replication metadata."); Utility.Assert(stateProviderId != DynamicStateManager.EmptyStateProviderId, "state provider id cannot be empty."); this.Name = name; this.CreateLsn = createLsn; this.DeleteLsn = deleteLsn; this.InitializationContext = initializationParameters; this.StateProviderId = stateProviderId; this.ParentStateProviderId = parentStateProviderId; this.MetadataMode = metadataMode; }
public Range <int> InferCompressionLevel(FileInfo sourceFile, int targetCompressionLevel, MetadataMode metadataMode) { CompressionLevelInferrer service = PickEncoder(metadataMode); return(service.InferCompressionLevel(sourceFile, targetCompressionLevel)); }
internal void Start(bool resume) { ClientEngine.MainLoop.QueueWait(delegate { CheckRegisteredAndDisposed(); this.Engine.Start(); // If the torrent was "paused", then just update the state to Downloading and forcefully // make sure the peers begin sending/receiving again if (this.State == TorrentState.Paused) { Mode = new DownloadMode(this); return; } if (!HasMetadata) { if (TrackerManager.CurrentTracker != null) { this.TrackerManager.Announce(TorrentEvent.Started); } Mode = new MetadataMode(this, _torrentSaveFolder); #if !DISABLE_DHT StartDht(); #endif return; } VerifyHashState(); // If the torrent has not been hashed, we start the hashing process then we wait for it to finish // before attempting to start again if (!HashChecked) { if (State != TorrentState.Hashing) { HashCheck(true); } return; } if (State == TorrentState.Seeding || State == TorrentState.Downloading) { return; } if (TrackerManager.CurrentTracker != null && !resume) { if (this.TrackerManager.CurrentTracker.CanScrape) { this.TrackerManager.Scrape(); } this.TrackerManager.Announce(TorrentEvent.Started); // Tell server we're starting } if (this.Complete && this.Settings.InitialSeedingEnabled && ClientEngine.SupportsInitialSeed) { Mode = new InitialSeedingMode(this); } else { Mode = new DownloadMode(this); } Engine.Broadcast(this); #if !DISABLE_DHT StartDht(); #endif this.StartTime = DateTime.Now; this.PieceManager.Reset(); ClientEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(2), delegate { if (State != TorrentState.Downloading && State != TorrentState.Seeding) { return(false); } PieceManager.Picker.CancelTimedOutRequests(); return(true); }); }); }