Kaynağa Gözat

support full-size PKBFI scans

Danilo Fragoso 1 hafta önce
ebeveyn
işleme
231e294463
2 değiştirilmiş dosya ile 3 ekleme ve 3 silme
  1. 2 2
      engine.zig
  2. 1 1
      pkbfi.zig

+ 2 - 2
engine.zig

@@ -883,7 +883,7 @@ pub const Engine = struct {
     }
     }
 
 
     pub fn scan(self: *Engine, allocator: std.mem.Allocator, prefix: []const u8, cursor: []const u8, limit: u32, include_values: bool, max_bytes: u32) !ScanBatch {
     pub fn scan(self: *Engine, allocator: std.mem.Allocator, prefix: []const u8, cursor: []const u8, limit: u32, include_values: bool, max_bytes: u32) !ScanBatch {
-        if (prefix.len > pkvdb.max_key_size or cursor.len > pkvdb.max_key_size or limit == 0 or limit > 4096 or max_bytes == 0 or max_bytes > 1024 * 1024) return error.InvalidLength;
+        if (prefix.len > pkvdb.max_key_size or cursor.len > pkvdb.max_key_size or limit == 0 or limit > 4096 or max_bytes == 0 or max_bytes > pkvdb.max_key_size + pkvdb.max_value_size + 1024) return error.InvalidLength;
         try self.ensureOrdered();
         try self.ensureOrdered();
         self.lock.lockShared();
         self.lock.lockShared();
         defer self.lock.unlockShared();
         defer self.lock.unlockShared();
@@ -901,7 +901,7 @@ pub const Engine = struct {
         while (node) |current| {
         while (node) |current| {
             if (entries.items.len >= limit or !std.mem.startsWith(u8, current.key, prefix)) break;
             if (entries.items.len >= limit or !std.mem.startsWith(u8, current.key, prefix)) break;
             const record = current.record;
             const record = current.record;
-            const next_size = current.key.len + if (include_values) record.value_len else 0;
+            const next_size = 16 + current.key.len + if (include_values) record.value_len else 0;
             if (next_size > max_bytes) return error.ScanEntryTooLarge;
             if (next_size > max_bytes) return error.ScanEntryTooLarge;
             if (bytes_used + next_size > max_bytes) break;
             if (bytes_used + next_size > max_bytes) break;
             const key = try allocator.dupe(u8, current.key);
             const key = try allocator.dupe(u8, current.key);

+ 1 - 1
pkbfi.zig

@@ -195,7 +195,7 @@ pub const Session = struct {
         const requested = readInt(u32, payload, 8);
         const requested = readInt(u32, payload, 8);
         const scan = &self.scans.items[index];
         const scan = &self.scans.items[index];
         const limit = if (requested == 0) scan.limit else @min(requested, scan.limit);
         const limit = if (requested == 0) scan.limit else @min(requested, scan.limit);
-        var batch = try engine.scan(self.allocator, scan.prefix, scan.cursor, limit, scan.include_values, 1024 * 1024);
+        var batch = try engine.scan(self.allocator, scan.prefix, scan.cursor, limit, scan.include_values, max_frame_size - 10);
         defer batch.deinit(self.allocator);
         defer batch.deinit(self.allocator);
         try body.append(self.allocator, @intFromBool(batch.done));
         try body.append(self.allocator, @intFromBool(batch.done));
         try body.appendNTimes(self.allocator, 0, 3);
         try body.appendNTimes(self.allocator, 0, 3);