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); }
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); }
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)); }
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"); } } }
private void CheckError() { IntPtr error; Native.leveldb_iter_get_error(handle, out error); NativeHelper.CheckError(error); }
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); } } }
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))); }
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); }
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); } } }
public static void Repair(string name, Options options) { Native.leveldb_repair_db(options.handle, Path.GetFullPath(name), out IntPtr error); NativeHelper.CheckError(error); }
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); }
public void Delete(WriteOptions options, byte[] key) { Native.leveldb_delete(handle, options.handle, key, (UIntPtr)key.Length, out IntPtr error); NativeHelper.CheckError(error); }
public void Write(WriteOptions options, WriteBatch write_batch) { Native.leveldb_write(handle, options.handle, write_batch.handle, out IntPtr error); NativeHelper.CheckError(error); }