[Groonga-commit] droonga/droonga-engine at 0495d90 [master] Create ChunkLoader

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 21 20:42:38 JST 2014


Kouhei Sutou	2014-07-21 20:42:38 +0900 (Mon, 21 Jul 2014)

  New Revision: 0495d9027c4e510bf1f4e69d117ed2c4cc932153
  https://github.com/droonga/droonga-engine/commit/0495d9027c4e510bf1f4e69d117ed2c4cc932153

  Message:
    Create ChunkLoader

  Modified files:
    lib/droonga/buffered_tcp_socket.rb
    lib/droonga/forwarder.rb

  Modified: lib/droonga/buffered_tcp_socket.rb (+25 -3)
===================================================================
--- lib/droonga/buffered_tcp_socket.rb    2014-07-21 20:29:41 +0900 (f2e049c)
+++ lib/droonga/buffered_tcp_socket.rb    2014-07-21 20:42:38 +0900 (3921d86)
@@ -77,16 +77,38 @@ module Droonga
     private
     def load_chunks
       FileUtils.mkdir_p(@data_directory.to_s)
-      Pathname.glob("#{@data_directory}/*.chunk").collect do |chunk_path|
-        Chunk.load(chunk_path)
-      end
+      chunk_loader = ChunkLoader.new(@data_directory)
+      chunk_loader.load
     end
 
     def log_tag
       "[#{Process.ppid}] buffered-tcp-socket"
     end
 
+    class ChunkLoader
+      def initialize(path)
+        @path = path
+      end
+
+      def have_any_chunk?
+        @path.opendir do |dir|
+          dir.each do |entry|
+            return true if entry.end_with?(Chunk::SUFFIX)
+          end
+        end
+        false
+      end
+
+      def load
+        Pathname.glob("#{@path}/*#{Chunk::SUFFIX}").collect do |chunk_path|
+          Chunk.load(chunk_path)
+        end
+      end
+    end
+
     class Chunk
+      SUFFIX = ".chunk"
+
       class << self
         def load(path)
           data_directory = path.dirname

  Modified: lib/droonga/forwarder.rb (+7 -4)
===================================================================
--- lib/droonga/forwarder.rb    2014-07-21 20:29:41 +0900 (1450fd2)
+++ lib/droonga/forwarder.rb    2014-07-21 20:42:38 +0900 (cff0f5a)
@@ -18,6 +18,7 @@
 require "droonga/loggable"
 require "droonga/path"
 require "droonga/event_loop"
+require "droonga/buffered_tcp_socket"
 require "droonga/fluent_message_sender"
 
 module Droonga
@@ -57,10 +58,6 @@ module Droonga
       return unless Path.buffer.exist?
       Pathname.glob("#{Path.buffer}/*") do |path|
         next unless path.directory?
-        if Pathname.glob("#{path.to_s}/*").empty?
-          FileUtils.rm_rf(path.to_s)
-          next
-        end
 
         destination = path.basename.to_s
         sender = @senders[destination]
@@ -69,6 +66,12 @@ module Droonga
           next
         end
 
+        chunk_loader = ChunkLoader.new(path)
+        unless chunk_loader.have_any_chunk?
+          FileUtils.rm_rf(path.to_s)
+          next
+        end
+
         components = destination.split(":")
         port = components.pop.to_i
         next if port.zero?
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index