Navigation Menu

Skip to content

Commit

Permalink
Set "have-unprocessed-messages-for-*" tag while there is any write bu…
Browse files Browse the repository at this point in the history
…ffer for the node
  • Loading branch information
piroor committed Apr 1, 2015
1 parent 0a03080 commit 96cb1f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/droonga/command/droonga_engine.rb
Expand Up @@ -372,6 +372,7 @@ class MainLoop

def initialize(configuration)
@configuration = configuration
ENV["DROONGA_ENGINE_NAME"] = @configuration.name
@loop = Coolio::Loop.default
@log_file = nil
@pid_file_path = nil
Expand Down
6 changes: 6 additions & 0 deletions lib/droonga/forward_buffer.rb
Expand Up @@ -22,6 +22,7 @@
require "droonga/loggable"
require "droonga/path"
require "droonga/safe_file_writer"
require "droonga/serf"

module Droonga
class ForwardBuffer
Expand All @@ -37,13 +38,17 @@ def initialize(node_name)
@packer = MessagePack::Packer.new
@unpacker = MessagePack::Unpacker.new

@target = node_name
@serf = Serf.new(ENV["DROONGA_ENGINE_NAME"])

dirname = node_name.gsub("/", ":")
@data_directory = Path.intentional_buffer + dirname
FileUtils.mkdir_p(@data_directory.to_s)
end

def add(message, destination)
logger.trace("add: start")
@serf.set_have_unprocessed_messages_for(@target)
buffered_message = {
"message" => message,
"destination" => destination,
Expand All @@ -61,6 +66,7 @@ def start_forward
Pathname.glob("#{@data_directory}/*#{SUFFIX}").collect do |buffered_message_path|
forward(buffered_message_path)
end
@serf.reset_have_unprocessed_messages_for(@target)
logger.trace("start_forward: done")
end

Expand Down
8 changes: 8 additions & 0 deletions lib/droonga/serf.rb
Expand Up @@ -141,6 +141,14 @@ def update_cluster_id
set_tag("cluster_id", cluster_id)
end

def set_have_unprocessed_messages_for(node_name)
set_tag("have-unprocessed-messages-for-#{node-name}", true)
end

def reset_have_unprocessed_messages_for(node_name)
delete_tag("have-unprocessed-messages-for-#{node-name}")
end

def role
@node_metadata.reload
@node_metadata.role
Expand Down

0 comments on commit 96cb1f1

Please sign in to comment.