Skip to content

Commit 1427634

Browse files
committed
Fix oplog file size counting
1 parent 099b392 commit 1427634

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Oplog.zig

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ files: std.ArrayList(FileInfo),
2626

2727
current_file: ?std.fs.File = null,
2828
current_file_size: usize = 0,
29-
max_file_size: usize = 1_000_000,
29+
max_file_size: usize = 16 * 1024 * 1024,
3030

3131
next_commit_id: u64 = 1,
3232

@@ -208,7 +208,8 @@ pub fn write(self: *Self, changes: []const Change) !u64 {
208208
const commit_id = self.next_commit_id;
209209

210210
const file = try self.getFile(commit_id);
211-
var bufferred_writer = std.io.bufferedWriter(file.writer());
211+
var counting_writer = std.io.countingWriter(file.writer());
212+
var bufferred_writer = std.io.bufferedWriter(counting_writer.writer());
212213
const writer = bufferred_writer.writer();
213214

214215
try msgpack.encode(Transaction{
@@ -218,7 +219,7 @@ pub fn write(self: *Self, changes: []const Change) !u64 {
218219

219220
try bufferred_writer.flush();
220221

221-
self.current_file_size += changes.len;
222+
self.current_file_size += counting_writer.bytes_written;
222223
self.next_commit_id += 1;
223224

224225
file.sync() catch |err| {

0 commit comments

Comments
 (0)