Пример #1
0
        public void Delete(WriteOptions options, Slice key)
        {
            IntPtr error;

            Native.leveldb_delete(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out error);
            NativeHelper.CheckError(error);
        }
Пример #2
0
        public void Put(WriteOptions options, Slice key, Slice value)
        {
            IntPtr error;

            Native.leveldb_put(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, value.buffer, (UIntPtr)value.buffer.Length, out error);
            NativeHelper.CheckError(error);
        }
Пример #3
0
        public static DB Open(string name, Options options)
        {
            IntPtr handle = Native.leveldb_open(options.handle, Path.GetFullPath(name), out IntPtr error);

            NativeHelper.CheckError(error);
            return(new DB(handle));
        }
Пример #4
0
        public void Write(WriteOptions options, WriteBatch write_batch)
        {
            // There's a bug in .Net Core.
            // When calling DB.Write(), it will throw LevelDBException sometimes.
            // But when you try to catch the exception, the bug disappears.
            // We shall remove the "try...catch" clause when Microsoft fix the bug.
            byte retry = 0;

            while (true)
            {
                try
                {
                    IntPtr error;
                    Native.leveldb_write(handle, options.handle, write_batch.handle, out error);
                    NativeHelper.CheckError(error);
                    break;
                }
                catch (LevelDBException ex)
                {
                    if (++retry >= 4)
                    {
                        throw;
                    }
                    System.IO.File.AppendAllText("leveldb.log", ex.Message + "\r\n");
                }
            }
        }
Пример #5
0
        private void CheckError()
        {
            IntPtr error;

            Native.leveldb_iter_get_error(handle, out error);
            NativeHelper.CheckError(error);
        }
Пример #6
0
        public Slice Get(ReadOptions options, Slice key)
        {
            TR.Enter();
            UIntPtr length;
            IntPtr  error;
            IntPtr  value = Native.leveldb_get(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out length, out error);

            try
            {
                NativeHelper.CheckError(error);
                if (value == IntPtr.Zero)
                {
                    TR.Exit();
                    throw new LevelDBException("not found");
                }
                return(TR.Exit(new Slice(value, length)));
            }
            finally
            {
                TR.Log(value);
                if (value != IntPtr.Zero)
                {
                    Native.leveldb_free(value);
                }
            }
        }
Пример #7
0
        public static DB Open(string name, Options options)
        {
            TR.Enter();
            IntPtr error;
            IntPtr handle = Native.leveldb_open(options.handle, name, out error);

            NativeHelper.CheckError(error);
            return(TR.Exit(new DB(handle)));
        }
Пример #8
0
        public bool Contains(ReadOptions options, byte[] key)
        {
            IntPtr value = Native.leveldb_get(handle, options.handle, key, (UIntPtr)key.Length, out _, out IntPtr error);

            NativeHelper.CheckError(error);

            if (value != IntPtr.Zero)
            {
                Native.leveldb_free(value);
                return(true);
            }

            return(false);
        }
Пример #9
0
        public byte[] Get(ReadOptions options, byte[] key)
        {
            IntPtr value = Native.leveldb_get(handle, options.handle, key, (UIntPtr)key.Length, out UIntPtr length, out IntPtr error);

            try
            {
                NativeHelper.CheckError(error);
                return(value.ToByteArray(length));
            }
            finally
            {
                if (value != IntPtr.Zero)
                {
                    Native.leveldb_free(value);
                }
            }
        }
Пример #10
0
 public static void Repair(string name, Options options)
 {
     Native.leveldb_repair_db(options.handle, Path.GetFullPath(name), out IntPtr error);
     NativeHelper.CheckError(error);
 }
Пример #11
0
 public void Put(WriteOptions options, byte[] key, byte[] value)
 {
     Native.leveldb_put(handle, options.handle, key, (UIntPtr)key.Length, value, (UIntPtr)value.Length, out IntPtr error);
     NativeHelper.CheckError(error);
 }
Пример #12
0
 public void Delete(WriteOptions options, byte[] key)
 {
     Native.leveldb_delete(handle, options.handle, key, (UIntPtr)key.Length, out IntPtr error);
     NativeHelper.CheckError(error);
 }
Пример #13
0
 public void Write(WriteOptions options, WriteBatch write_batch)
 {
     Native.leveldb_write(handle, options.handle, write_batch.handle, out IntPtr error);
     NativeHelper.CheckError(error);
 }