Пример #1
0
        public static Task <IFdbDatabase> OpenAsync([CanBeNull] string clusterFile, [CanBeNull] string dbName, [CanBeNull] IKeySubspace globalSpace, bool readOnly = false, CancellationToken ct = default)
        {
            var options = new FdbConnectionOptions
            {
                ClusterFile = clusterFile,
                DbName      = dbName,
                GlobalSpace = globalSpace,
                ReadOnly    = readOnly
            };

            return(OpenInternalAsync(options, ct));
        }
Пример #2
0
        internal static async Task <IFdbDatabase> OpenInternalAsync(FdbConnectionOptions options, CancellationToken ct)
        {
            Contract.Requires(options != null);
            ct.ThrowIfCancellationRequested();

            string       clusterFile = options.ClusterFile;
            string       dbName      = options.DbName ?? FdbConnectionOptions.DefaultDbName;  // new FdbConnectionOptions { GlobalSpace =
            bool         readOnly    = options.ReadOnly;
            IKeySubspace globalSpace = options.GlobalSpace ?? KeySubspace.Empty;

            string[] partitionPath = options.PartitionPath?.ToArray();
            bool     hasPartition  = partitionPath != null && partitionPath.Length > 0;

            if (Logging.On)
            {
                Logging.Info(typeof(Fdb), nameof(OpenInternalAsync), $"Connecting to database '{dbName}' using cluster file '{clusterFile}' and subspace '{globalSpace}' ...");
            }

            FdbCluster  cluster = null;
            FdbDatabase db      = null;
            bool        success = false;

            try
            {
                cluster = await CreateClusterInternalAsync(clusterFile, ct).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 : !hasPartition && readOnly, ownsCluster : true, ct : ct).ConfigureAwait(false);

                // set the default options
                if (options.DefaultTimeout != TimeSpan.Zero)
                {
                    db.DefaultTimeout = checked ((int)Math.Ceiling(options.DefaultTimeout.TotalMilliseconds));
                }
                if (options.DefaultRetryLimit != 0)
                {
                    db.DefaultRetryLimit = options.DefaultRetryLimit;
                }
                if (options.DefaultMaxRetryDelay != 0)
                {
                    db.DefaultMaxRetryDelay = options.DefaultMaxRetryDelay;
                }
                if (options.DataCenterId != null)
                {
                    db.SetDataCenterId(options.DataCenterId);
                }
                if (options.MachineId != null)
                {
                    db.SetMachineId(options.MachineId);
                }

                if (hasPartition)
                {                 // open the partition, and switch the root of the db
                    await Fdb.Directory.SwitchToNamedPartitionAsync(db, partitionPath, readOnly, ct);
                }

                success = true;
                return(db);
            }
            finally
            {
                if (!success)
                {
                    // cleanup the cluter if something went wrong
                    db?.Dispose();
                    cluster?.Dispose();
                }
            }
        }
Пример #3
0
 /// <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>
 /// <param name="encoder">Encoder for the values stored in this queue</param>
 /// <remarks>Uses the default Tuple serializer</remarks>
 public FdbQueue([NotNull] IKeySubspace subspace, bool highContention = true, IValueEncoder <T> encoder = null)
     : this(subspace.AsDynamic(), highContention, encoder)
 {
 }