Skip to content

Commit

Permalink
Rename Action#bytesize to #lag_size
Browse files Browse the repository at this point in the history
It may not always represent the entire Action size sent over the socket.
  • Loading branch information
spuun committed Apr 9, 2024
1 parent 04d7cda commit e5aee74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions spec/replication/actions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ describe LavinMQ::Replication::Action do
end
end

describe "#bytesize" do
describe "#lag_size" do
it "should count filename and filesize" do
with_datadir_tempfile("data") do |_relative, absolute|
File.write absolute, "foo"
action = LavinMQ::Replication::AddAction.new absolute
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".bytesize)
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".bytesize)
end
end
end
Expand All @@ -82,12 +82,12 @@ describe LavinMQ::Replication::Action do
end
end
end
describe "#bytesize" do
describe "#lag_size" do
it "should count filename and filesize" do
with_datadir_tempfile("data") do |_relative, absolute|
File.write absolute, "foo"
action = LavinMQ::Replication::AddAction.new absolute
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".bytesize)
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".bytesize)
end
end
end
Expand All @@ -109,11 +109,11 @@ describe LavinMQ::Replication::Action do
end
end
end
describe "#bytesize" do
describe "#lag_size" do
it "should count filename and size of Int32" do
with_datadir_tempfile("data") do |_relative, absolute|
action = LavinMQ::Replication::AppendAction.new absolute, 123i32
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + sizeof(Int32))
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + sizeof(Int32))
end
end
end
Expand All @@ -133,11 +133,11 @@ describe LavinMQ::Replication::Action do
end
end
end
describe "#bytesize" do
describe "#lag_size" do
it "should count filename and size of UInt32" do
with_datadir_tempfile("data") do |_relative, absolute|
action = LavinMQ::Replication::AppendAction.new absolute, 123u32
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + sizeof(UInt32))
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + sizeof(UInt32))
end
end
end
Expand All @@ -157,11 +157,11 @@ describe LavinMQ::Replication::Action do
end
end
end
describe "#bytesize" do
describe "#lag_size" do
it "should count filename and size of Bytes" do
with_datadir_tempfile("data") do |_relative, absolute|
action = LavinMQ::Replication::AppendAction.new absolute, "foo".to_slice
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".to_slice.bytesize)
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + "foo".to_slice.bytesize)
end
end
end
Expand All @@ -184,13 +184,13 @@ describe LavinMQ::Replication::Action do
end
end
end
describe "#bytesize" do
describe "#lag_size" do
it "should count filename and size of FileRange" do
with_datadir_tempfile("data") do |_relative, absolute|
File.write absolute, "foo bar baz"
range = LavinMQ::Replication::FileRange.new(MFile.new(absolute), 4, 3)
action = LavinMQ::Replication::AppendAction.new absolute, range
action.bytesize.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + range.len)
action.lag_size.should eq(sizeof(Int32) + "data".bytesize + sizeof(Int64) + range.len)
end
end
end
Expand Down
8 changes: 4 additions & 4 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 : Int64
abstract def lag_size : Int64
abstract def send(socket : IO) : Int64

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

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

def bytesize : Int64
def lag_size : Int64
datasize = case obj = @obj
in Bytes
obj.bytesize.to_i64
Expand Down Expand Up @@ -102,7 +102,7 @@ module LavinMQ
end

struct DeleteAction < Action
def bytesize : Int64
def lag_size : 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?
Expand Down
6 changes: 3 additions & 3 deletions src/lavinmq/replication/follower.cr
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ module LavinMQ
end

private def send_action(action : Action) : Int64
action_size = action.bytesize
@sent_bytes += action_size
lag_size = action.lag_size
@sent_bytes += lag_size
@actions.send action
action_size
lag_size
end

def close
Expand Down

0 comments on commit e5aee74

Please sign in to comment.