Kouhei Sutou
null+****@clear*****
Mon Feb 3 17:02:04 JST 2014
Kouhei Sutou 2014-02-03 17:02:04 +0900 (Mon, 03 Feb 2014) New Revision: ae17e4179fbf7e7d6dbb9700d2cd2d39f4ec2f2d https://github.com/droonga/fluent-plugin-droonga/commit/ae17e4179fbf7e7d6dbb9700d2cd2d39f4ec2f2d Message: catalog: extract continuum computation code It isn't used yet. Added files: lib/droonga/catalog/dataset.rb test/unit/catalog/test_dataset.rb Added: lib/droonga/catalog/dataset.rb (+54 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/catalog/dataset.rb 2014-02-03 17:02:04 +0900 (1fe4432) @@ -0,0 +1,54 @@ +# Copyright (C) 2013-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +require "digest/sha1" + +module Droonga + module Catalog + class Dataset + def initialize(data) + @data = data + end + + def continuum + @continuum ||= compute_continuum + end + + private + def compute_continuum + number_of_partitions = @data["number_of_partitions"] + return [] if number_of_partitions < 2 + total_weight = compute_total_weight + continuum = [] + @data["ring"].each do |key, value| + points = number_of_partitions * 160 * value["weight"] / total_weight + points.times do |point| + hash = Digest::SHA1.hexdigest("#{key}:#{point}") + continuum << [hash[0..7].to_i(16), key] + end + end + continuum.sort do |a, b| + a[0] - b[0] + end + end + + def compute_total_weight + @data["ring"].reduce(0) do |result, zone| + result + zone[1]["weight"] + end + end + end + end +end Added: test/unit/catalog/test_dataset.rb (+385 -0) 100644 =================================================================== --- /dev/null +++ test/unit/catalog/test_dataset.rb 2014-02-03 17:02:04 +0900 (958960d) @@ -0,0 +1,385 @@ +# Copyright (C) 2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +require "droonga/catalog/dataset" + +class CatalogDatasetTest < Test::Unit::TestCase + private + def create_dataset(data) + Droonga::Catalog::Dataset.new(data) + end + + class ContinuumTest < self + def setup + @ring = { + "localhost:23041" => { + "weight" => 50, + "partitions" => { + "2014-02-09" => [ + "localhost:20341/droonga.000", + "localhost:20341/droonga.001", + ], + }, + }, + "localhost:23042" => { + "weight" => 50, + "partitions" => { + "2014-02-09" => [ + "localhost:20342/droonga.002", + "localhost:20342/droonga.003", + ], + }, + }, + } + end + + def continuum(data) + create_dataset(data).continuum + end + + def test_no_partition + assert_equal([], + continuum("number_of_partitions" => 1, + "ring" => @ring)) + end + + def test_multiple_partitions + assert_equal([ + [9603047, "localhost:23041"], + [27629778, "localhost:23042"], + [41438004, "localhost:23042"], + [46078372, "localhost:23042"], + [49960577, "localhost:23041"], + [50458434, "localhost:23042"], + [62539901, "localhost:23041"], + [102160356, "localhost:23042"], + [118777121, "localhost:23041"], + [135178227, "localhost:23041"], + [137745106, "localhost:23042"], + [145409221, "localhost:23041"], + [151846190, "localhost:23042"], + [159720530, "localhost:23041"], + [174946501, "localhost:23042"], + [180602930, "localhost:23042"], + [202106994, "localhost:23042"], + [205862983, "localhost:23042"], + [214712657, "localhost:23041"], + [247420023, "localhost:23041"], + [259057847, "localhost:23041"], + [272576744, "localhost:23042"], + [273722093, "localhost:23041"], + [281067628, "localhost:23042"], + [293157057, "localhost:23041"], + [316454767, "localhost:23041"], + [329395260, "localhost:23041"], + [336035525, "localhost:23042"], + [337183821, "localhost:23042"], + [345936445, "localhost:23042"], + [352998716, "localhost:23042"], + [356549233, "localhost:23042"], + [365790167, "localhost:23042"], + [366761715, "localhost:23042"], + [374718742, "localhost:23042"], + [423944977, "localhost:23041"], + [441573727, "localhost:23041"], + [442348808, "localhost:23042"], + [456608714, "localhost:23042"], + [486506717, "localhost:23042"], + [503359185, "localhost:23041"], + [507968811, "localhost:23041"], + [522389108, "localhost:23041"], + [538007376, "localhost:23042"], + [552940093, "localhost:23041"], + [565987242, "localhost:23041"], + [582806095, "localhost:23041"], + [611312183, "localhost:23041"], + [621389814, "localhost:23041"], + [644400226, "localhost:23041"], + [654418860, "localhost:23041"], + [669337050, "localhost:23042"], + [672929644, "localhost:23042"], + [677668675, "localhost:23041"], + [703432973, "localhost:23041"], + [716459360, "localhost:23041"], + [746047339, "localhost:23042"], + [789450083, "localhost:23041"], + [796244908, "localhost:23042"], + [801162758, "localhost:23041"], + [806867059, "localhost:23041"], + [818911813, "localhost:23042"], + [819949679, "localhost:23042"], + [833118130, "localhost:23042"], + [833679755, "localhost:23041"], + [873615689, "localhost:23042"], + [880898222, "localhost:23041"], + [894480469, "localhost:23042"], + [910910091, "localhost:23041"], + [919595198, "localhost:23041"], + [932350249, "localhost:23042"], + [939377609, "localhost:23041"], + [958562472, "localhost:23042"], + [981240873, "localhost:23041"], + [986623018, "localhost:23042"], + [999488955, "localhost:23042"], + [1017009664, "localhost:23041"], + [1018813132, "localhost:23042"], + [1027591410, "localhost:23041"], + [1048831053, "localhost:23041"], + [1065756786, "localhost:23042"], + [1068022889, "localhost:23042"], + [1074085731, "localhost:23042"], + [1084163769, "localhost:23041"], + [1098037927, "localhost:23042"], + [1121835916, "localhost:23042"], + [1129345220, "localhost:23042"], + [1148803987, "localhost:23041"], + [1151870780, "localhost:23042"], + [1151876336, "localhost:23042"], + [1172639414, "localhost:23042"], + [1174498870, "localhost:23041"], + [1185602679, "localhost:23042"], + [1197984299, "localhost:23042"], + [1207475922, "localhost:23042"], + [1235417559, "localhost:23041"], + [1238004412, "localhost:23042"], + [1243706366, "localhost:23042"], + [1245715925, "localhost:23042"], + [1250583493, "localhost:23041"], + [1288824895, "localhost:23041"], + [1308702666, "localhost:23042"], + [1327123066, "localhost:23042"], + [1327995980, "localhost:23041"], + [1330953926, "localhost:23042"], + [1339581304, "localhost:23042"], + [1347736889, "localhost:23042"], + [1360110626, "localhost:23042"], + [1384082650, "localhost:23042"], + [1401035340, "localhost:23041"], + [1411013100, "localhost:23041"], + [1426568376, "localhost:23042"], + [1431710724, "localhost:23041"], + [1444398493, "localhost:23041"], + [1479189521, "localhost:23041"], + [1513093825, "localhost:23041"], + [1514666132, "localhost:23041"], + [1519362198, "localhost:23042"], + [1531494698, "localhost:23042"], + [1535282727, "localhost:23041"], + [1535626422, "localhost:23042"], + [1553592951, "localhost:23042"], + [1559468978, "localhost:23041"], + [1581367000, "localhost:23042"], + [1589920429, "localhost:23041"], + [1605687052, "localhost:23042"], + [1624945150, "localhost:23042"], + [1628150772, "localhost:23041"], + [1670394510, "localhost:23041"], + [1683839421, "localhost:23041"], + [1689437303, "localhost:23042"], + [1696925840, "localhost:23042"], + [1696962849, "localhost:23041"], + [1711148491, "localhost:23041"], + [1715075293, "localhost:23042"], + [1727144721, "localhost:23041"], + [1741689697, "localhost:23041"], + [1747842507, "localhost:23042"], + [1756538966, "localhost:23042"], + [1756579826, "localhost:23041"], + [1759918231, "localhost:23041"], + [1763420733, "localhost:23042"], + [1773027279, "localhost:23041"], + [1783071332, "localhost:23042"], + [1783904572, "localhost:23041"], + [1798455991, "localhost:23041"], + [1873514423, "localhost:23042"], + [1891118101, "localhost:23041"], + [1893238867, "localhost:23042"], + [1903033611, "localhost:23041"], + [1925915300, "localhost:23041"], + [1938049314, "localhost:23041"], + [1944148871, "localhost:23041"], + [1948017755, "localhost:23042"], + [1968402121, "localhost:23041"], + [1991372406, "localhost:23042"], + [1994291866, "localhost:23041"], + [2008535226, "localhost:23042"], + [2018311062, "localhost:23041"], + [2034595495, "localhost:23041"], + [2035213452, "localhost:23041"], + [2037794404, "localhost:23041"], + [2045835634, "localhost:23041"], + [2047702072, "localhost:23041"], + [2047817697, "localhost:23041"], + [2055369974, "localhost:23042"], + [2080668066, "localhost:23042"], + [2103770068, "localhost:23041"], + [2123603348, "localhost:23042"], + [2139800272, "localhost:23041"], + [2179129230, "localhost:23041"], + [2196771767, "localhost:23042"], + [2201832130, "localhost:23041"], + [2202361965, "localhost:23041"], + [2205203213, "localhost:23041"], + [2224638783, "localhost:23041"], + [2231966397, "localhost:23042"], + [2246002957, "localhost:23041"], + [2268183028, "localhost:23041"], + [2278962012, "localhost:23041"], + [2281079708, "localhost:23041"], + [2319189432, "localhost:23041"], + [2333806182, "localhost:23042"], + [2382832820, "localhost:23042"], + [2395820598, "localhost:23042"], + [2400631930, "localhost:23042"], + [2423755877, "localhost:23042"], + [2463262611, "localhost:23042"], + [2472430585, "localhost:23042"], + [2485153021, "localhost:23041"], + [2496668371, "localhost:23041"], + [2514014586, "localhost:23041"], + [2558870426, "localhost:23042"], + [2564276753, "localhost:23042"], + [2574277968, "localhost:23041"], + [2592472493, "localhost:23042"], + [2607258621, "localhost:23041"], + [2614254907, "localhost:23041"], + [2620760890, "localhost:23042"], + [2651983985, "localhost:23042"], + [2655195461, "localhost:23041"], + [2659913742, "localhost:23042"], + [2661202449, "localhost:23042"], + [2685822324, "localhost:23041"], + [2697042260, "localhost:23042"], + [2703527078, "localhost:23042"], + [2705978309, "localhost:23042"], + [2721148403, "localhost:23042"], + [2733447702, "localhost:23041"], + [2736188580, "localhost:23041"], + [2758967840, "localhost:23041"], + [2784848842, "localhost:23042"], + [2833516863, "localhost:23042"], + [2840102575, "localhost:23041"], + [2865654417, "localhost:23041"], + [2879431763, "localhost:23041"], + [2885879450, "localhost:23042"], + [2886116302, "localhost:23042"], + [2893306625, "localhost:23042"], + [2894128113, "localhost:23042"], + [2897556237, "localhost:23041"], + [2908592163, "localhost:23041"], + [2921288405, "localhost:23041"], + [2946669890, "localhost:23042"], + [2963904259, "localhost:23042"], + [2975325206, "localhost:23041"], + [2996645729, "localhost:23041"], + [3000094069, "localhost:23042"], + [3004191432, "localhost:23042"], + [3008276260, "localhost:23042"], + [3009066823, "localhost:23042"], + [3010043272, "localhost:23041"], + [3021930201, "localhost:23041"], + [3022561244, "localhost:23041"], + [3035183544, "localhost:23041"], + [3061834112, "localhost:23041"], + [3081895333, "localhost:23042"], + [3100253179, "localhost:23041"], + [3105348121, "localhost:23042"], + [3128093110, "localhost:23041"], + [3139279598, "localhost:23041"], + [3161507274, "localhost:23042"], + [3176232817, "localhost:23042"], + [3179328318, "localhost:23041"], + [3193971258, "localhost:23042"], + [3197623137, "localhost:23042"], + [3243553025, "localhost:23041"], + [3256140856, "localhost:23041"], + [3276287733, "localhost:23042"], + [3276659656, "localhost:23041"], + [3336803621, "localhost:23041"], + [3340771432, "localhost:23041"], + [3342756131, "localhost:23041"], + [3349847214, "localhost:23041"], + [3362320951, "localhost:23042"], + [3367216947, "localhost:23042"], + [3373220713, "localhost:23042"], + [3390486913, "localhost:23042"], + [3394808552, "localhost:23041"], + [3427153669, "localhost:23041"], + [3455884916, "localhost:23042"], + [3477557293, "localhost:23041"], + [3490640959, "localhost:23042"], + [3492869366, "localhost:23042"], + [3498663241, "localhost:23041"], + [3511308806, "localhost:23042"], + [3518217839, "localhost:23041"], + [3550643661, "localhost:23042"], + [3560340265, "localhost:23042"], + [3581763062, "localhost:23042"], + [3586388888, "localhost:23041"], + [3613146094, "localhost:23042"], + [3638310074, "localhost:23041"], + [3675913657, "localhost:23042"], + [3707869452, "localhost:23042"], + [3809749253, "localhost:23042"], + [3866669476, "localhost:23042"], + [3868747768, "localhost:23042"], + [3893516035, "localhost:23042"], + [3925429782, "localhost:23042"], + [3930474602, "localhost:23042"], + [3975500031, "localhost:23041"], + [3976115920, "localhost:23042"], + [3977644234, "localhost:23041"], + [3979776870, "localhost:23041"], + [3980299749, "localhost:23041"], + [3980347759, "localhost:23042"], + [4003152522, "localhost:23041"], + [4008016337, "localhost:23041"], + [4009078721, "localhost:23041"], + [4023291693, "localhost:23041"], + [4044935778, "localhost:23042"], + [4069030469, "localhost:23041"], + [4089201952, "localhost:23041"], + [4102445160, "localhost:23042"], + [4110744646, "localhost:23041"], + [4111449069, "localhost:23042"], + [4115421801, "localhost:23041"], + [4146806390, "localhost:23041"], + [4155072858, "localhost:23041"], + [4158437676, "localhost:23041"], + [4169311721, "localhost:23042"], + [4175251809, "localhost:23041"], + [4175808068, "localhost:23042"], + [4197302191, "localhost:23042"], + [4230703474, "localhost:23041"], + [4230786979, "localhost:23042"], + [4233561014, "localhost:23041"], + [4234760241, "localhost:23042"], + [4240706113, "localhost:23042"], + [4242248154, "localhost:23041"], + [4244962758, "localhost:23042"], + [4249972704, "localhost:23042"], + [4255505170, "localhost:23042"], + [4261033451, "localhost:23041"], + [4280396822, "localhost:23041"], + [4281027412, "localhost:23042"], + [4292367368, "localhost:23042"], + [4294093319, "localhost:23042"], + [4294346407, "localhost:23041"], + ], + continuum("number_of_partitions" => 2, + "ring" => @ring)) + end + end +end -------------- next part -------------- HTML����������������������������...Download