コード例 #1
0
        protected T GetChecked <T>(LibFunc <T, DbRetCode> libFunc)
        {
            var handle = CheckDisposed();
            var ret    = libFunc(handle, out T result);

            ErrorUtil.CheckRetCode(ret);
            return(result);
        }
コード例 #2
0
        /// <summary>Constructor.</summary>
        /// <param name="config">Configuration to use.</param>
        public LmdbEnvironment(LmdbEnvironmentConfiguration config = null)
        {
            // so that we can refer back to the Environment instance
            instanceHandle = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection);

            DbRetCode ret;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* */ }
            finally {
                IntPtr envHandle;
                ret = DbLib.mdb_env_create(out envHandle);
                if (ret == DbRetCode.SUCCESS)
                {
                    var ret2 = DbLib.mdb_env_set_userctx(envHandle, (IntPtr)instanceHandle);
                    if (ret2 == DbRetCode.SUCCESS)
                    {
                        this.env = envHandle;
                    }
                    else
                    {
                        ret = ret2;
                        DbLib.mdb_env_close(envHandle);
                    }
                }
            }
            ErrorUtil.CheckRetCode(ret);

            if (config != null)
            {
                this.autoReduceMapSizeIn32BitProcess = config.AutoReduceMapSizeIn32BitProcess;
                if (config.MapSize.HasValue)
                {
                    this.SetMapSize(config.MapSize.Value);
                }
                if (config.MaxDatabases.HasValue)
                {
                    this.MaxDatabases = config.MaxDatabases.Value;
                }
                if (config.MaxReaders.HasValue)
                {
                    this.MaxReaders = config.MaxReaders.Value;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Commit all the operations of a transaction into the database.
        /// The transaction handle is freed. It and its cursors must not be used again after this call, except with mdb_cursor_renew().
        /// Note: Earlier documentation incorrectly said all cursors would be freed. Only write-transactions free cursors.
        /// </summary>
        public void Commit()
        {
            // we check here, as we dont want to throw an exception later, but won't use this handle.
            var currentHandle = CheckDisposed();

            // now we use atomic access to the handle
            var handle = Interlocked.Exchange(ref txn, IntPtr.Zero);

            // if the txn handle was valid before we cleared it, lets close the handle
            if (handle != IntPtr.Zero)
            {
                var txnId = DbLib.mdb_txn_id(handle);
                var ret   = DbLib.mdb_txn_commit(handle);
                // whether the call succeeded or not, the transaction cannot be re-used.
                ReleaseManagedResources(true);
                disposed?.Invoke(txnId);

                ErrorUtil.CheckRetCode(ret);
                Committed();
            }
        }