void Put(IChunkCache cache, int i) { var content = new byte[1024]; PackUnpack.PackInt32BE(content, 0, i); cache.Put(CalcHash(content), ByteBuffer.NewAsync(content)); }
bool Get(IChunkCache cache, int i) { var content = new byte[1024]; PackUnpack.PackInt32BE(content, 0, i); return(cache.Get(CalcHash(content)).Result.Length == 1024); }
public void BigCompaction() { using var fileCollection = new InMemoryFileCollection(); var logger = new LoggerMock(); using var db = NewKeyValueDB(new KeyValueDBOptions { FileCollection = fileCollection, Compression = new NoCompressionStrategy(), CompactorScheduler = null, FileSplitSize = 10000, Logger = logger }); using (var tr = db.StartTransaction()) { var key = new byte[100]; var value = new byte[2000]; for (var i = 0; i < 2000; i++) { PackUnpack.PackInt32BE(key, 0, i); tr.CreateOrUpdateKeyValue(key, value); } tr.Commit(); } using (var tr = db.StartTransaction()) { var key = new byte[100]; for (var i = 0; i < 2000; i += 2) { PackUnpack.PackInt32BE(key, 0, i); tr.FindExactKey(key); tr.EraseCurrent(); } for (var i = 0; i < 2000; i += 3) { PackUnpack.PackInt32BE(key, 0, i); if (tr.FindExactKey(key)) { tr.EraseCurrent(); } } Assert.Equal(667, tr.GetKeyValueCount()); tr.Commit(); } db.Compact(CancellationToken.None); Assert.Equal(513u, logger.MarkedForDeleteCount); }
public void WriteInt32(int value) { if (Pos + 4 > End) { FlushBuffer(); if (Pos + 4 > End) { var b = new byte[4]; PackUnpack.PackInt32BE(b, 0, value); WriteBlock(b); return; } } PackUnpack.PackInt32BE(Buf, Pos, value); Pos += 4; }
public void WriteInt32(int value) { if (Pos + 4 > End) { FlushBuffer(); if (Pos + 4 > End) { Span <byte> buf = stackalloc byte[4]; BinaryPrimitives.WriteInt32BigEndian(buf, value); WriteBlock(buf); return; } } PackUnpack.PackInt32BE(Buf, Pos, value); Pos += 4; }