Skip to content

Commit

Permalink
Make Action#bytesize Int64
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Apr 4, 2024
1 parent 3fed4d4 commit aeb94aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/lavinmq/replication/actions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module LavinMQ
def initialize(@path : String)
end

abstract def bytesize : Int32
abstract def bytesize : Int64
abstract def send(socket : IO) : Int64

protected def filename_bytesize : Int32
Expand All @@ -33,12 +33,12 @@ module LavinMQ
def initialize(@path : String, @mfile : MFile? = nil)
end

def bytesize : Int32
def bytesize : Int64
if mfile = @mfile
sizeof(Int32) + filename.bytesize +
0i64 + sizeof(Int32) + filename.bytesize +
sizeof(Int64) + mfile.size.to_i64
else
sizeof(Int32) + filename.bytesize +
0i64 + sizeof(Int32) + filename.bytesize +
sizeof(Int64) + File.size(@path).to_i64
end
end
Expand Down Expand Up @@ -66,7 +66,7 @@ module LavinMQ
def initialize(@path : String, @obj : Bytes | FileRange | UInt32 | Int32)
end

def bytesize : Int32
def bytesize : Int64
datasize = case obj = @obj
in Bytes
obj.bytesize.to_i64
Expand All @@ -75,7 +75,7 @@ module LavinMQ
in UInt32, Int32
4i64
end
sizeof(Int32) + filename.bytesize +
0i64 + sizeof(Int32) + filename.bytesize +
sizeof(Int64) + datasize
end

Expand All @@ -102,11 +102,11 @@ module LavinMQ
end

struct DeleteAction < Action
def bytesize : Int32
def bytesize : Int64
# Maybe it would be ok to not include delete action in lag, because
# the follower should have all info necessary to GC the file during
# startup?
sizeof(Int32) + filename.bytesize + sizeof(Int64)
(sizeof(Int32) + filename.bytesize + sizeof(Int64)).to_i64
end

def send(socket) : Int64
Expand Down
8 changes: 4 additions & 4 deletions src/lavinmq/replication/follower.cr
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ module LavinMQ
end
end

def add(path, mfile : MFile? = nil) : Int32
def add(path, mfile : MFile? = nil) : Int64
send_action AddAction.new(path, mfile)
end

def append(path, obj) : Int32
def append(path, obj) : Int64
send_action AppendAction.new(path, obj)
end

def delete(path) : Int32
def delete(path) : Int64
send_action DeleteAction.new(path)
end

private def send_action(action : Action) : Int32
private def send_action(action : Action) : Int64
action_size = action.bytesize
@sent_bytes += action_size
@actions.send action
Expand Down

0 comments on commit aeb94aa

Please sign in to comment.