Navigation Menu

Skip to content

Commit

Permalink
Restart the server manually when the metadata is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 22, 2015
1 parent 5eac50e commit 69938dd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
2 changes: 2 additions & 0 deletions bin/droonga-engine-absorb-data
Expand Up @@ -27,6 +27,7 @@ require "droonga/data_absorber"
require "droonga/serf"
require "droonga/client"
require "droonga/node_metadata"
require "droonga/restarter"

class AbsorbDataCommand
def run
Expand Down Expand Up @@ -216,6 +217,7 @@ class AbsorbDataCommand
if timestamp and not timestamp.empty?
metadata = NodeMetadata.new
metadata.set(:effective_message_timestamp, timestamp)
Droonga::Restarter.restart
end
end

Expand Down
14 changes: 12 additions & 2 deletions lib/droonga/command/remote.rb
Expand Up @@ -14,6 +14,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "json"
require "fileutils"

require "droonga/path"
require "droonga/serf"
Expand All @@ -24,6 +25,7 @@
require "droonga/data_absorber"
require "droonga/safe_file_writer"
require "droonga/service_installation"
require "droonga/restarter"

module Droonga
module Command
Expand Down Expand Up @@ -105,11 +107,12 @@ class SetMetadata < Base
def process
metadata = NodeMetadata.new
metadata.set(@params["key"], @params["value"])
Restarter.restart
end
end

class Join < Base
def process
def processt
log("type = #{type}")
case type
when "replica"
Expand Down Expand Up @@ -233,14 +236,17 @@ def absorb_data

metadata = NodeMetadata.new
metadata.set(:absorbing, true)
Restarter.restart(5)

DataAbsorber.absorb(:dataset => dataset_name,
:source_host => source_host,
:destination_host => joining_host,
:port => port,
:tag => tag,
:messages_per_second => messages_per_second)

metadata.delete(:absorbing)
sleep(1)
Restarter.restart(5)
end
end

Expand Down Expand Up @@ -271,14 +277,18 @@ def process

metadata = NodeMetadata.new
metadata.set(:absorbing, true)
Restarter.restart(5)

DataAbsorber.absorb(:dataset => dataset_name,
:source_host => source,
:destination_host => host,
:port => port,
:tag => tag,
:messages_per_second => messages_per_second,
:client => "droonga-send")

metadata.delete(:absorbing)
Restarter.restart(5)
end

private
Expand Down
11 changes: 1 addition & 10 deletions lib/droonga/engine.rb
Expand Up @@ -25,6 +25,7 @@
require "droonga/dispatcher"
require "droonga/file_observer"
require "droonga/node_metadata"
require "droonga/restarter"

module Droonga
class Engine
Expand All @@ -44,13 +45,6 @@ def initialize(loop, name, internal_name)

@dispatcher = create_dispatcher

@node_metadata_observer = FileObserver.new(loop, Path.node_metadata)
@node_metadata_observer.on_change = lambda do
logger.trace("reloading node_metadata: start")
@node_metadata.reload
logger.trace("reloading node_metadata: done")
end

@on_ready = nil
end

Expand All @@ -61,15 +55,13 @@ def start
end
@state.start
@cluster.start
@node_metadata_observer.start
@dispatcher.start
logger.trace("start: done")
end

def stop_gracefully
logger.trace("stop_gracefully: start")
@cluster.stop_observe
@node_metadata_observer.stop
on_finish = lambda do
logger.trace("stop_gracefully/on_finish: start")
save_last_processed_message_timestamp
Expand All @@ -95,7 +87,6 @@ def stop_immediately
logger.trace("stop_immediately: start")
save_last_processed_message_timestamp
@cluster.stop_observe
@node_metadata_observer.stop
@dispatcher.stop_immediately
@cluster.shutdown
@state.shutdown
Expand Down
32 changes: 32 additions & 0 deletions lib/droonga/restarter.rb
@@ -0,0 +1,32 @@
# Copyright (C) 2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "fileutils"
require "droonga/path"

module Droonga
class Restarter
class << self
def restart(wait_for_next=nil)
new.restart(wait_for_next)
end
end

def restart(wait_for_next=nil)
FileUtils.touch(Path.restart.to_s)
sleep(wait_for_next) if wait_for_next
end
end
end
3 changes: 3 additions & 0 deletions lib/droonga/serf.rb
Expand Up @@ -14,6 +14,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "json"
require "fileutils"

require "droonga/path"
require "droonga/loggable"
Expand All @@ -25,6 +26,7 @@
require "droonga/line_buffer"
require "droonga/safe_file_writer"
require "droonga/service_installation"
require "droonga/restarter"

module Droonga
class Serf
Expand Down Expand Up @@ -150,6 +152,7 @@ def role=(new_role)
new_role ||= NodeMetadata::Role::SERVICE_PROVIDER
set_tag("role", new_role)
@node_metadata.role = new_role
Restarter.restart
end

def cluster_id
Expand Down

0 comments on commit 69938dd

Please sign in to comment.