This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/
DiffScriptGenerationTestResultEF.rb
183 lines (168 loc) · 8.74 KB
/
DiffScriptGenerationTestResultEF.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
###############################################################################
# HBase Schema Update Script
#
# Summary:
#
# * Create 0 tables.
#
# * Alter 1 table:
# minimal
# property change: minimal:fullSchema:<table name="minimal"><columnFamilies><columnFamily name="minimalColumnFamily1"></columnFamily></columnFamilies></table>-><table isReadOnly="false" maxFileSizeMB="10240" memStoreFlushSizeMB="128" name="minimal" useDeferredLogFlush="false"><columnFamilies><columnFamily blockCache="true" blockSizeKB="64" bloomFilter="NONE" inMemory="false" maxVersions="3" name="minimalColumnFamily1" replicationScope="0" timeToLiveMS="2147483647"></columnFamily></columnFamilies></table>;
#
# * Drop 0 tables.
#
# * Ignore 0 tables.
###############################################################################
###############################################################################
# Initialization
###############################################################################
include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.HColumnDescriptor
import org.apache.hadoop.hbase.HConstants
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.util.Bytes
conf = HBaseConfiguration.new
admin = HBaseAdmin.new(conf)
preErrors = Array.new
preWarnings = Array.new
postErrors = Array.new
###############################################################################
# Utility methods
###############################################################################
def compare(errs, obj, action, attr, val)
if (obj.getValue(attr).to_s != val)
errs << "Object '#{obj.getNameAsString()}', which is targeted for #{action} by this script, should have had a value of \"#{val}\" for #{attr}, but it was \"#{obj.getValue(attr)}\" instead.\n"
end
end
###############################################################################
# Pre Validation
#
# This step makes sure that the existing schema on the cluster matches what you
# think should be there. It will emit warnings for problems that won't make the
# script fail; it will emit errors and exit if it encounters any problems that
# will make the script fail.
###############################################################################
# Table 'minimal' should exist
tablename = "minimal"
if !admin.tableExists(tablename)
preErrors << "Table '#{tablename}' should exist, but it does not.\n"
end
# Table 'minimal' will error if it doesn't match the expected definition.
if admin.tableExists(tablename)
table = admin.getTableDescriptor(tablename.bytes.to_a)
compare(preErrors, table, "alter", "DEFERRED_LOG_FLUSH", "false")
compare(preErrors, table, "alter", "IS_META", "false")
compare(preErrors, table, "alter", "IS_ROOT", "false")
compare(preErrors, table, "alter", "MAX_FILESIZE", "10737418240")
compare(preErrors, table, "alter", "MEMSTORE_FLUSHSIZE", "134217728")
compare(preErrors, table, "alter", "READONLY", "false")
compare(preErrors, table, "alter", "fullSchema", "<table name=\"minimal\"><columnFamilies><columnFamily name=\"minimalColumnFamily1\"></columnFamily></columnFamilies></table>")
# Column family: minimalColumnFamily1
cfname = "minimalColumnFamily1"
cf = table.getFamily(cfname.bytes.to_a)
compare(preErrors, cf, "alter", "BLOCKCACHE", "true")
compare(preErrors, cf, "alter", "BLOCKSIZE", "65536")
compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE")
compare(preErrors, cf, "alter", "COMPRESSION", "NONE")
compare(preErrors, cf, "alter", "DATA_BLOCK_ENCODING", "NONE")
compare(preErrors, cf, "alter", "ENCODE_ON_DISK", "true")
compare(preErrors, cf, "alter", "IN_MEMORY", "false")
compare(preErrors, cf, "alter", "KEEP_DELETED_CELLS", "false")
compare(preErrors, cf, "alter", "MIN_VERSIONS", "0")
compare(preErrors, cf, "alter", "REPLICATION_SCOPE", "0")
compare(preErrors, cf, "alter", "TTL", "2147483647")
compare(preErrors, cf, "alter", "VERSIONS", "3")
end
# If any pre-validations had errors, report them and exit the script.
if (preErrors.length > 0)
puts "There were #{preErrors.length} error(s) and #{preWarnings.length} warning(s) during table pre-validation:"
print "#{preErrors.collect{|msg| "Error: " + msg}}"
print "#{preWarnings.collect{|msg| "Warning: " + msg}}"
raise
exit
elsif (preWarnings.length > 0)
puts "Pre-validations successful with #{preWarnings.length} warnings:"
print "#{preWarnings.collect{|msg| "Warning: " + msg}}"
else
puts "Pre-validations successful."
end
###############################################################################
# Modifications
#
# This step actually modifies the schema on the cluster.
###############################################################################
# Modify table: minimal
tablename = "minimal"
table = admin.getTableDescriptor(tablename.bytes.to_a)
table.setValue("DEFERRED_LOG_FLUSH", "false")
table.setValue("IS_META", "false")
table.setValue("IS_ROOT", "false")
table.setValue("MAX_FILESIZE", "10737418240")
table.setValue("MEMSTORE_FLUSHSIZE", "134217728")
table.setValue("READONLY", "false")
table.setValue("fullSchema", "<table isReadOnly=\"false\" maxFileSizeMB=\"10240\" memStoreFlushSizeMB=\"128\" name=\"minimal\" useDeferredLogFlush=\"false\"><columnFamilies><columnFamily blockCache=\"true\" blockSizeKB=\"64\" bloomFilter=\"NONE\" inMemory=\"false\" maxVersions=\"3\" name=\"minimalColumnFamily1\" replicationScope=\"0\" timeToLiveMS=\"2147483647\"></columnFamily></columnFamilies></table>")
cf = HColumnDescriptor.new("minimalColumnFamily1")
cf.setValue("BLOCKCACHE", "true")
cf.setValue("BLOCKSIZE", "65536")
cf.setValue("BLOOMFILTER", "NONE")
cf.setValue("COMPRESSION", "NONE")
cf.setValue("DATA_BLOCK_ENCODING", "NONE")
cf.setValue("ENCODE_ON_DISK", "true")
cf.setValue("IN_MEMORY", "false")
cf.setValue("KEEP_DELETED_CELLS", "false")
cf.setValue("MIN_VERSIONS", "0")
cf.setValue("REPLICATION_SCOPE", "0")
cf.setValue("TTL", "2147483647")
cf.setValue("VERSIONS", "3")
table.addFamily(cf)
puts "Disabling table '#{tablename}' prior to modification ..."
admin.disableTable(tablename)
puts "Modifying table '#{tablename}' ..."
admin.modifyTable(tablename.bytes.to_a, table)
puts "Enabling table '#{tablename}' after modification ..."
admin.enableTable(tablename)
puts "Modified table '#{tablename}"
puts "Table creations & modifications successful."
###############################################################################
# Post Validation
#
# This step ensures that changes were successful, and that the resulting schema
# on the cluster matches what you want to be there.
###############################################################################
# Table 'minimal' should exist
tablename = "minimal"
if !admin.tableExists(tablename)
preErrors << "Table '#{tablename}' should exist, but it does not.\n"
end
# Table 'minimal' will error if it doesn't match the expected definition.
if admin.tableExists(tablename)
table = admin.getTableDescriptor(tablename.bytes.to_a)
compare(preErrors, table, "alter", "DEFERRED_LOG_FLUSH", "false")
compare(preErrors, table, "alter", "IS_META", "false")
compare(preErrors, table, "alter", "IS_ROOT", "false")
compare(preErrors, table, "alter", "MAX_FILESIZE", "10737418240")
compare(preErrors, table, "alter", "MEMSTORE_FLUSHSIZE", "134217728")
compare(preErrors, table, "alter", "READONLY", "false")
compare(preErrors, table, "alter", "fullSchema", "<table isReadOnly=\"false\" maxFileSizeMB=\"10240\" memStoreFlushSizeMB=\"128\" name=\"minimal\" useDeferredLogFlush=\"false\"><columnFamilies><columnFamily blockCache=\"true\" blockSizeKB=\"64\" bloomFilter=\"NONE\" inMemory=\"false\" maxVersions=\"3\" name=\"minimalColumnFamily1\" replicationScope=\"0\" timeToLiveMS=\"2147483647\"></columnFamily></columnFamilies></table>")
# Column family: minimalColumnFamily1
cfname = "minimalColumnFamily1"
cf = table.getFamily(cfname.bytes.to_a)
compare(preErrors, cf, "alter", "BLOCKCACHE", "true")
compare(preErrors, cf, "alter", "BLOCKSIZE", "65536")
compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE")
compare(preErrors, cf, "alter", "COMPRESSION", "NONE")
compare(preErrors, cf, "alter", "DATA_BLOCK_ENCODING", "NONE")
compare(preErrors, cf, "alter", "ENCODE_ON_DISK", "true")
compare(preErrors, cf, "alter", "IN_MEMORY", "false")
compare(preErrors, cf, "alter", "KEEP_DELETED_CELLS", "false")
compare(preErrors, cf, "alter", "MIN_VERSIONS", "0")
compare(preErrors, cf, "alter", "REPLICATION_SCOPE", "0")
compare(preErrors, cf, "alter", "TTL", "2147483647")
compare(preErrors, cf, "alter", "VERSIONS", "3")
end
puts "Post-validation successful."
puts "Script complete. Share and enjoy."
exit