/// <summary>Clear the entire content of a subspace</summary> public static void ClearRange(this IFdbTransaction trans, [NotNull] IFdbSubspace subspace) { Contract.Requires(trans != null && subspace != null); //BUGBUG: should we call subspace.ToRange() ? trans.ClearRange(FdbKeyRange.StartsWith(subspace.ToFoundationDbKey())); }
public static MemoryDatabase CreateNew(string name, IFdbSubspace globalSpace, bool readOnly) { globalSpace = globalSpace ?? FdbSubspace.Empty; var uid = Guid.NewGuid(); MemoryClusterHandler cluster = null; MemoryDatabaseHandler db = null; try { cluster = new MemoryClusterHandler(); db = cluster.OpenDatabase(uid); // initialize the system keys for this new db db.PopulateSystemKeys(); return(new MemoryDatabase(new FdbCluster(cluster, ":memory:"), db, name, globalSpace, null, readOnly, true)); } catch { if (db != null) { db.Dispose(); } if (cluster != null) { cluster.Dispose(); } throw; } }
/// <summary>Clear the entire content of a subspace</summary> public static Task ClearRangeAsync(this IFdbRetryable db, [NotNull] IFdbSubspace subspace, CancellationToken cancellationToken) { Contract.NotNull(db, nameof(db)); Contract.NotNull(subspace, nameof(subspace)); return(db.WriteAsync((tr) => ClearRange(tr, subspace), cancellationToken)); }
public async Task <IFdbDatabase> OpenDatabaseAsync(string databaseName, IFdbSubspace subspace, bool readOnly, CancellationToken cancellationToken) { if (subspace == null) { throw new ArgumentNullException("subspace"); } return(await OpenDatabaseInternalAsync(databaseName, subspace, readOnly : readOnly, ownsCluster : false, cancellationToken : cancellationToken).ConfigureAwait(false)); }
protected async Task DeleteSubspace(IFdbDatabase db, IFdbSubspace subspace) { using (var tr = db.BeginTransaction(this.Cancellation)) { tr.ClearRange(subspace); await tr.CommitAsync(); } }
public static Slice[] ConcatRange(this IFdbSubspace subspace, [NotNull] IEnumerable <Slice> keys) { if (keys == null) { throw new ArgumentNullException("keys"); } return(subspace.ToFoundationDbKey().ConcatRange(keys)); }
public PrefixRewriterTransaction(IFdbSubspace prefix, IFdbTransaction trans, bool ownsTransaction) : base(trans, false, ownsTransaction) { if (prefix == null) { throw new ArgumentNullException("prefix"); } m_prefix = prefix; }
/// <summary> /// Create a new object representing a binary large object (blob). /// Only keys within the subspace will be used by the object. /// Other clients of the database should refrain from modifying the subspace.</summary> /// <param name="subspace">Subspace to be used for storing the blob data and metadata</param> public FdbBlob([NotNull] IFdbSubspace subspace) { if (subspace == null) { throw new ArgumentNullException("subspace"); } this.Subspace = subspace.Using(TypeSystem.Tuples); }
public static Slice[] ConcatRange <TKey>(this IFdbSubspace subspace, [NotNull] IEnumerable <TKey> keys) where TKey : IFdbKey { if (keys == null) { throw new ArgumentNullException("keys"); } return(subspace.ToFoundationDbKey().ConcatRange(keys.Select((key) => key.ToFoundationDbKey()))); }
public FdbHashSetCollection(IFdbSubspace subspace) { if (subspace == null) { throw new ArgumentNullException(nameof(subspace)); } this.Subspace = subspace.Using(TypeSystem.Tuples); }
/// <summary>Append a key to the subspace key</summary> /// <typeparam name="TKey">type of the key, must implements IFdbKey</typeparam> /// <param name="key"></param> /// <returns>Return Slice : 'subspace.Key + key'</returns> public static Slice Concat <TKey>(this IFdbSubspace subspace, [NotNull] TKey key) where TKey : IFdbKey { if (key == null) { throw new ArgumentNullException("key"); } return(Slice.Concat(subspace.ToFoundationDbKey(), key.ToFoundationDbKey())); }
/// <summary>Change the current global namespace.</summary> /// <remarks>Do NOT call this, unless you know exactly what you are doing !</remarks> internal void ChangeRoot(IFdbSubspace subspace, IFdbDirectory directory, bool readOnly) { //REVIEW: rename to "ChangeRootSubspace" ? subspace = subspace ?? FdbSubspace.Empty; lock (this) //TODO: don't use this for locking { m_readOnly = readOnly; m_globalSpace = FdbSubspace.CopyDynamic(subspace, TypeSystem.Tuples); m_globalSpaceCopy = FdbSubspace.CopyDynamic(subspace, TypeSystem.Tuples); // keep another copy m_directory = directory == null ? null : new FdbDatabasePartition(this, directory); } }
/// <summary>Return a version of this subspace, which uses a different type system to produces the keys and values</summary> /// <param name="subspace">Instance of a generic subspace</param> /// <param name="encoding">Custom key encoder</param> /// <returns>Subspace equivalent to <paramref name="subspace"/>, but augmented with a specific TypeSystem</returns> public static IFdbEncoderSubspace <T1, T2, T3> UsingEncoder <T1, T2, T3>([NotNull] this IFdbSubspace subspace, [NotNull] IFdbKeyEncoding encoding) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } return(FdbSubspace.CopyEncoder <T1, T2, T3>(subspace, encoding)); }
/// <summary>Return a version of this subspace, which uses a different type system to produces the keys and values</summary> /// <param name="subspace">Instance of a generic subspace</param> /// <param name="encoder">Custom key encoder</param> /// <returns>Subspace equivalent to <paramref name="subspace"/>, but augmented with a specific TypeSystem</returns> public static IFdbEncoderSubspace <T> UsingEncoder <T>([NotNull] this IFdbSubspace subspace, [NotNull] IKeyEncoder <T> encoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } return(FdbSubspace.CopyEncoder <T>(subspace, encoder)); }
/// <summary>Return a version of this subspace, which uses a different type system to produces the keys and values</summary> /// <param name="subspace">Instance of a generic subspace</param> /// <param name="encoder">Custom key encoder</param> /// <returns>Subspace equivalent to <paramref name="subspace"/>, but augmented with a specific TypeSystem</returns> public static IFdbDynamicSubspace UsingEncoder([NotNull] this IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } return(FdbSubspace.CopyDynamic(subspace, encoder)); }
/// <summary>Return a version of this subspace, which uses a different type system to produces the keys and values</summary> /// <param name="subspace">Instance of a generic subspace</param> /// <param name="encoding">If non-null, uses this specific instance of the TypeSystem. If null, uses the default instance for this particular TypeSystem</param> /// <returns>Subspace equivalent to <paramref name="subspace"/>, but augmented with a specific TypeSystem</returns> public static IFdbDynamicSubspace Using([NotNull] this IFdbSubspace subspace, [NotNull] IFdbKeyEncoding encoding) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } return(FdbSubspace.CopyDynamic(subspace, encoding)); }
public static async Task DumpSubspace([NotNull] IFdbDatabase db, [NotNull] IFdbSubspace subspace, CancellationToken ct) { Assert.That(db, Is.Not.Null); Assert.That(db.GlobalSpace.Contains(subspace.Key), Is.True, "Using a location outside of the test database partition!!! This is probably a bug in the test..."); // do not log db = db.WithoutLogging(); using (var tr = db.BeginTransaction(ct)) { await DumpSubspace(tr, subspace).ConfigureAwait(false); } }
/// <summary>Clear the entire content of a subspace</summary> public static Task ClearRangeAsync(this IFdbRetryable db, [NotNull] IFdbSubspace subspace, CancellationToken cancellationToken) { if (db == null) { throw new ArgumentNullException("db"); } if (subspace == null) { throw new ArgumentNullException("subspace"); } return(db.WriteAsync((tr) => ClearRange(tr, subspace), cancellationToken)); }
/// <summary>Tests whether the specified <paramref name="key"/> starts with this Subspace's prefix, indicating that the Subspace logically contains <paramref name="key"/>.</summary> /// <param name="subspace"/> /// <param name="key">The key to be tested</param> /// <exception cref="System.ArgumentNullException">If <paramref name="key"/> is null</exception> public static bool Contains <TKey>([NotNull] this IFdbSubspace subspace, [NotNull] TKey key) where TKey : IFdbKey { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (key == null) { throw new ArgumentNullException("key"); } return(subspace.Contains(key.ToFoundationDbKey())); }
public static IFdbTuple Append(this IFdbSubspace subspace, [NotNull] ITupleFormattable formattable) { if (formattable == null) { throw new ArgumentNullException("formattable"); } var tuple = formattable.ToTuple(); if (tuple == null) { throw new InvalidOperationException("Formattable item cannot return an empty tuple"); } return(new FdbPrefixedTuple(subspace.ToFoundationDbKey(), tuple)); }
/// <summary>Create a new key by appending a formattable object to the current subspace</summary> /// <param name="item">Instance of a type that can be transformed into a Tuple</param> /// <returns>Key the correspond to the concatenation of the current subspace's prefix and the packed representation of the tuple returned by <paramref name="item"/>.ToTuple()</returns> /// <exception cref="System.ArgumentNullException">If <paramref name="item"/> is null</exception> /// <exception cref="System.InvalidOperationException">If calling <paramref name="item"/>.ToTuple() returns null.</exception> public static Slice Pack(this IFdbSubspace subspace, [NotNull] ITupleFormattable item) { if (item == null) { throw new ArgumentNullException("item"); } var tuple = item.ToTuple(); if (tuple == null) { throw new InvalidOperationException("The specified item returned a null tuple"); } return(Pack(subspace, tuple)); }
public static FdbSubspace Partition(this IFdbSubspace subspace, [NotNull] ITupleFormattable formattable) { if (formattable == null) { throw new ArgumentNullException("formattable"); } var tuple = formattable.ToTuple(); if (tuple == null) { throw new InvalidOperationException("Formattable item returned an empty tuple"); } return(Partition(subspace, tuple)); }
/// <summary>Create a new multimap, using a specific key and value encoder</summary> /// <param name="subspace">Location where the map will be stored in the database</param> /// <param name="allowNegativeValues">If true, allow negative or zero values to stay in the map.</param> /// <param name="encoder">Encoder for the key/value pairs</param> public FdbMultiMap(IFdbSubspace subspace, bool allowNegativeValues, ICompositeKeyEncoder <TKey, TValue> encoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } this.Subspace = subspace; this.AllowNegativeValues = allowNegativeValues; this.Location = subspace.UsingEncoder(encoder); }
/// <summary>Create a new counter map, using a specific key encoder.</summary> public FdbCounterMap([NotNull] IFdbSubspace subspace, [NotNull] IKeyEncoder <TKey> keyEncoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (keyEncoder == null) { throw new ArgumentNullException("keyEncoder"); } this.Subspace = subspace; this.KeyEncoder = keyEncoder; this.Location = subspace.UsingEncoder(keyEncoder); }
public static FdbSubspace Partition(this IFdbSubspace subspace, [NotNull] IFdbTuple tuple) { if (tuple == null) { throw new ArgumentNullException("tuple"); } if (tuple.Count == 0) { return(new FdbSubspace(subspace.ToFoundationDbKey())); } else { return(new FdbSubspace(FdbTuple.PackWithPrefix(subspace.ToFoundationDbKey(), tuple))); } }
public FdbVector([NotNull] IFdbSubspace subspace, T defaultValue, [NotNull] IValueEncoder <T> encoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } this.Subspace = subspace.Using(TypeSystem.Tuples); this.DefaultValue = defaultValue; this.Encoder = encoder; }
public FdbWorkerPool(IFdbSubspace subspace) { if (subspace == null) { throw new ArgumentNullException(nameof(subspace)); } this.Subspace = subspace.Using(TypeSystem.Tuples); this.TaskStore = this.Subspace.Partition.ByKey(Slice.FromChar('T')); this.IdleRing = this.Subspace.Partition.ByKey(Slice.FromChar('I')); this.BusyRing = this.Subspace.Partition.ByKey(Slice.FromChar('B')); this.UnassignedTaskRing = this.Subspace.Partition.ByKey(Slice.FromChar('U')); this.Counters = new FdbCounterMap <int>(this.Subspace.Partition.ByKey(Slice.FromChar('C'))); }
/// <summary>Create a new High Contention counter, using a specific value encoder.</summary> /// <param name="db">Database used by this layer</param> /// <param name="subspace">Subspace to be used for storing the counter</param> /// <param name="encoder">Encoder for the counter values</param> public FdbHighContentionCounter([NotNull] IFdbDatabase db, [NotNull] IFdbSubspace subspace, [NotNull] IValueEncoder <long> encoder) { if (db == null) { throw new ArgumentNullException("db"); } if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } this.Database = db; this.Subspace = subspace.Using(TypeSystem.Tuples); this.Encoder = encoder; }
/// <summary>Create a new queue using either High Contention mode or Simple mode</summary> /// <param name="subspace">Subspace where the queue will be stored</param> /// <param name="highContention">If true, uses High Contention Mode (lots of popping clients). If true, uses the Simple Mode (a few popping clients).</param> public FdbQueue([NotNull] IFdbSubspace subspace, bool highContention, [NotNull] IValueEncoder <T> encoder) { if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } this.Subspace = subspace.Using(TypeSystem.Tuples); this.HighContention = highContention; this.Encoder = encoder; //TODO: rewrite this, using FdbEncoderSubpsace<..> ! this.ConflictedPop = this.Subspace.Partition.ByKey(Slice.FromAscii("pop")); this.ConflictedItem = this.Subspace.Partition.ByKey(Slice.FromAscii("conflict")); this.QueueItem = this.Subspace.Partition.ByKey(Slice.FromAscii("item")); }
public FdbIndex([NotNull] string name, [NotNull] IFdbSubspace subspace, IEqualityComparer <TValue> valueComparer, bool indexNullValues, [NotNull] ICompositeKeyEncoder <TValue, TId> encoder) { if (name == null) { throw new ArgumentNullException("name"); } if (subspace == null) { throw new ArgumentNullException("subspace"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } this.Name = name; this.Subspace = subspace; this.ValueComparer = valueComparer ?? EqualityComparer <TValue> .Default; this.IndexNullValues = indexNullValues; this.Location = subspace.UsingEncoder(encoder); }
public static MemoryDatabase CreateNew(string name, IFdbSubspace globalSpace, bool readOnly) { globalSpace = globalSpace ?? FdbSubspace.Empty; var uid = Guid.NewGuid(); MemoryClusterHandler cluster = null; MemoryDatabaseHandler db = null; try { cluster = new MemoryClusterHandler(); db = cluster.OpenDatabase(uid); // initialize the system keys for this new db db.PopulateSystemKeys(); return new MemoryDatabase(new FdbCluster(cluster, ":memory:"), db, name, globalSpace, null, readOnly, true); } catch { if (db != null) db.Dispose(); if (cluster != null) cluster.Dispose(); throw; } }
protected Task DumpSubspace(IFdbDatabase db, IFdbSubspace subspace) { return TestHelpers.DumpSubspace(db, subspace, this.Cancellation); }
public async Task<IFdbDatabase> OpenDatabaseAsync(string databaseName, IFdbSubspace subspace, bool readOnly, CancellationToken cancellationToken) { if (subspace == null) throw new ArgumentNullException("subspace"); return await OpenDatabaseInternalAsync(databaseName, subspace, readOnly: readOnly, ownsCluster: false, cancellationToken: cancellationToken).ConfigureAwait(false); }
public PrefixRewriterTransaction(IFdbSubspace prefix, IFdbTransaction trans, bool ownsTransaction) : base(trans, false, ownsTransaction) { if (prefix == null) throw new ArgumentNullException("prefix"); m_prefix = prefix; }
public static Task<IFdbDatabase> OpenAsync(IFdbSubspace globalSpace, CancellationToken cancellationToken = default(CancellationToken)) { return OpenAsync(clusterFile: null, dbName: null, globalSpace: globalSpace, cancellationToken: cancellationToken); }
public static async Task<IFdbDatabase> OpenAsync(string clusterFile, string dbName, IFdbSubspace globalSpace, bool readOnly = false, CancellationToken cancellationToken = default(CancellationToken)) { return await OpenInternalAsync(clusterFile, dbName, globalSpace, readOnly, cancellationToken); }
internal static async Task<FdbDatabase> OpenInternalAsync(string clusterFile, string dbName, IFdbSubspace globalSpace, bool readOnly, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); dbName = dbName ?? "DB"; globalSpace = globalSpace ?? FdbSubspace.Empty; if (Logging.On) Logging.Info(typeof(Fdb), "OpenAsync", String.Format("Connecting to database '{0}' using cluster file '{1}' and subspace '{2}' ...", dbName, clusterFile, globalSpace)); FdbCluster cluster = null; FdbDatabase db = null; bool success = false; try { cluster = await CreateClusterInternalAsync(clusterFile, cancellationToken).ConfigureAwait(false); //note: since the cluster is not provided by the caller, link it with the database's Dispose() db = await cluster.OpenDatabaseInternalAsync(dbName, globalSpace, readOnly: readOnly, ownsCluster: true, cancellationToken: cancellationToken).ConfigureAwait(false); success = true; return db; } finally { if (!success) { // cleanup the cluter if something went wrong if (db != null) db.Dispose(); if (cluster != null) cluster.Dispose(); } } }
private MemoryDatabase(IFdbCluster cluster, MemoryDatabaseHandler handler, string name, IFdbSubspace globalSpace, IFdbDirectory directory, bool readOnly, bool ownsCluster) : base(cluster, handler, name, globalSpace, directory, readOnly, ownsCluster) { m_handler = handler; }
public static FdbDirectoryLayer Create(IFdbSubspace subspace, IEnumerable<string> path = null) { if (subspace == null) throw new ArgumentNullException("subspace"); var location = path != null ? ParsePath(path) : FdbTuple.Empty; var space = subspace.Using(TypeSystem.Tuples); return new FdbDirectoryLayer(space.Partition[FdbKey.Directory], space, location); }
public FdbWorkerPool(IFdbSubspace subspace) { if (subspace == null) throw new ArgumentNullException("subspace"); this.Subspace = subspace.Using(TypeSystem.Tuples); this.TaskStore = this.Subspace.Partition.ByKey(Slice.FromChar('T')); this.IdleRing = this.Subspace.Partition.ByKey(Slice.FromChar('I')); this.BusyRing = this.Subspace.Partition.ByKey(Slice.FromChar('B')); this.UnassignedTaskRing = this.Subspace.Partition.ByKey(Slice.FromChar('U')); this.Counters = new FdbCounterMap<int>(this.Subspace.Partition.ByKey(Slice.FromChar('C'))); }
public FdbHashSetCollection(IFdbSubspace subspace) { if (subspace == null) throw new ArgumentNullException("subspace"); this.Subspace = subspace.Using(TypeSystem.Tuples); }
internal async Task<FdbDatabase> OpenDatabaseInternalAsync(string databaseName, IFdbSubspace subspace, bool readOnly, bool ownsCluster, CancellationToken cancellationToken) { ThrowIfDisposed(); if (string.IsNullOrEmpty(databaseName)) throw new ArgumentNullException("databaseName"); if (subspace == null) throw new ArgumentNullException("subspace"); if (Logging.On) Logging.Info(typeof(FdbCluster), "OpenDatabaseAsync", String.Format("Connecting to database '{0}' ...", databaseName)); if (cancellationToken.IsCancellationRequested) cancellationToken.ThrowIfCancellationRequested(); var handler = await m_handler.OpenDatabaseAsync(databaseName, cancellationToken).ConfigureAwait(false); if (Logging.On && Logging.IsVerbose) Logging.Verbose(typeof(FdbCluster), "OpenDatabaseAsync", String.Format("Connected to database '{0}'", databaseName)); return FdbDatabase.Create(this, handler, databaseName, subspace, null, readOnly, ownsCluster); }