Debian Codegraph @

tools/check-index-merge-source-dump.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # Copyright(C) 2019 Kouhei Sutou <[email protected]>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 require "English"
20
21 require "groonga-log"
22
23 def flatten_record_batches(record_batches)
24 record_batches.inject([], &:<<)
25 end
26
27 parser = GroongaLog::Parser.new
28
29 n_sections = 5
30 record_batches = []
31 record_batch = []
32 contexts = []
33 term = nil
34 term_id = nil
35 parser.parse(ARGF) do |statistics|
36 message = statistics.message
37 case statistics.message
38 when /\A\[ii\]\[merge\]\[source\]\[[a-zA-Z0-9.]+\]\[\d+\/\d+\]
39 \ <"(.*?)">\((\d)\):\ /x
40 current_term = $1
41 current_term_id = $2.to_i
42 context = $POSTMATCH
43 if record_batch != record_batch.sort
44 pp([:invalid_current_records,
45 term, term_id,
46 record_batches.collect(&:size),
47 record_batch.size,
48 contexts])
49 pp({record_batch: record_batch})
50 exit(false)
51 end
52 record_batches << record_batch unless record_batch.empty?
53 sorted_record_batches = record_batches.sort_by do |batch|
54 batch[0]
55 end
56 if flatten_record_batches(sorted_record_batches) !=
57 flatten_record_batches(record_batches).sort
58 pp([:invalid_records,
59 term, term_id,
60 record_batches.collect(&:size),
61 record_batch.size,
62 contexts])
63 pp({sorted_record_batches: sorted_record_batches.flatten,
64 record_batch: record_batch})
65 exit(false)
66 end
67 if term_id != current_term_id
68 expected_record_id = 1
69 expected_section_id = 1
70 sorted_record_batches.each do |batch|
71 batch.each do |record_id, section_id, _, _|
72 if [record_id, section_id] != [expected_record_id, expected_section_id]
73 pp([:invalid,
74 term, term_id,
75 [record_id, section_id],
76 [expected_record_id, expected_section_id],
77 record_batches.collect(&:size),
78 batch.size,
79 contexts])
80 pp({sorted_record_batches: sorted_record_batches,
81 record_batch: batch})
82 exit(false)
83 end
84 if expected_section_id == n_sections
85 expected_record_id += 1
86 expected_section_id = 1
87 else
88 expected_section_id += 1
89 end
90 end
91 end
92 pp([:checked,
93 term, term_id,
94 record_batches.collect(&:size),
95 contexts])
96 record_batches = []
97 contexts = []
98 term = current_term
99 term_id = current_term_id
100 end
101 record_batch = []
102 contexts << context
103 when /\Arecord:/
104 record = message.scan(/\((\d+):(\d+):(\d+):(\d+)\)/)[0].collect(&:to_i)
105 record_batch << record
106 when /\A\(/
107 message.scan(/\((\d+):(\d+):(\d+):(\d+)\)/) do |raw_record|
108 record_batch << raw_record.collect(&:to_i)
109 end
110 else
111 end
112 end