-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBWR_FilePartAnalyzer.ecl
354 lines (319 loc) · 13.8 KB
/
BWR_FilePartAnalyzer.ecl
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/**
* Code that examines a workunit looks for input files with "bad" data skews.
* Such files may cause poor performance if the skew is not addressed by
* ECL code.
*
* This code can either be run as a batch job under any of the HPCC engines
* or it can be compiled and published as a Roxie or hThor query.
*
* If run as a batch job, you should supply values for the following
* ECL attributes:
*
* WORKUNIT_ID
* ESP_URL
* ESP_USER
* ESP_USER_PW
*
* If run as a query, these parameters can be supplied at run time. The
* descriptions for each are below. Note that if run as a query, the default
* values below are still in effect even though they will not appear on the
* default query form.
*
* There are two results from this code: Skew information on all of the files
* that are used by the given workunit, and a subset of those files that may
* have "bad" skew values (meaning, you should perhaps consider redistributing
* their data or otherwise taking the skew into account).
*
* Origin: https://github.com/hpccsystems-solutions-lab/Useful_ECL
*/
IMPORT Std;
#WORKUNIT('name', 'File Part Analyzer');
// The workunit ID to inspect; this code will find that workunit's input
// files and analyze them for skew
STRING WORKUNIT_ID := '' : STORED('Workunit_ID', FORMAT(SEQUENCE(100)));
// ESP (ECL Watch) information for the cluster you will be inspecting; defaults
// to the same ESP process this job is running on
STRING ESP_URL := Std.File.GetEspURL() : STORED('ESP_URL', FORMAT(SEQUENCE(200)));
// Any authentication needed to access the ESP process
STRING ESP_USER := '' : STORED('Username', FORMAT(SEQUENCE(300)));
STRING ESP_USER_PW := '' : STORED('User_Password', FORMAT(SEQUENCE(400), PASSWORD));
//==============================================================================
IF(WORKUNIT_ID = '', FAIL('A workunit ID must be supplied'));
// Authentication header for SOAPCALL
auth := IF
(
TRIM(ESP_USER, ALL) != '',
'Basic ' + Std.Str.EncodeBase64((DATA)(TRIM(ESP_USER, ALL) + ':' + TRIM(ESP_USER_PW, LEFT, RIGHT))),
''
);
//------------------------------------------------------------------------------
// Get list of input files used by workunit
//------------------------------------------------------------------------------
FileNameInfo := RECORD
STRING name {XPATH('Name')};
BOOLEAN isSuperFile {XPATH('IsSuperFile')};
END;
initialFilenameList := SOAPCALL
(
ESP_URL + '/WsWorkunits?ver_=1.62', // Verified with platform 6.2.20-1
'WUInfo',
{
STRING wuid {XPATH('Wuid')} := WORKUNIT_ID,
BOOLEAN includeExceptions {XPATH('IncludeExceptions')} := FALSE,
BOOLEAN includeGraphs {XPATH('IncludeGraphs')} := FALSE,
BOOLEAN includeSourceFiles {XPATH('IncludeSourceFiles')} := TRUE,
BOOLEAN includeResults {XPATH('IncludeResults')} := FALSE,
BOOLEAN includeVariables {XPATH('IncludeVariables')} := FALSE,
BOOLEAN includeTimers {XPATH('IncludeTimers')} := FALSE,
BOOLEAN includeDebugValues {XPATH('IncludeDebugValues')} := FALSE,
BOOLEAN includeApplicationValues {XPATH('IncludeApplicationValues')} := FALSE,
BOOLEAN includeWorkflows {XPATH('IncludeWorkflows')} := FALSE
},
DATASET(FileNameInfo),
XPATH('WUInfoResponse/Workunit/SourceFiles/ECLSourceFile'),
HTTPHEADER('Authorization', auth)
);
// initialFilenameList may contain superfiles; expand them if possible
expandedFilenameList := NOTHOR
(
PROJECT
(
GLOBAL(initialFilenameList, FEW),
TRANSFORM
(
{
DATASET(Std.File.FsLogicalFileNameRecord) logicalFiles
},
SELF.logicalFiles := IF(LEFT.isSuperFile, Std.File.SuperFileContents('~' + LEFT.name, TRUE), DATASET([LEFT.name], Std.File.FsLogicalFileNameRecord))
)
)
);
fullFilenameList := NORMALIZE
(
expandedFilenameList,
LEFT.logicalFiles,
TRANSFORM
(
FileNameInfo,
SELF.name := RIGHT.name,
SELF.isSuperFile := FALSE
)
);
filenameList := DEDUP(SORT(fullFilenameList, name), name);
//------------------------------------------------------------------------------
// Get topology information so we know what names are used for Thor clusters
//------------------------------------------------------------------------------
ClusterNameRec := RECORD
STRING cluster_name {XPATH('Name')};
END;
TopologyRec := RECORD
STRING cluster_type {XPATH('Type')};
DATASET(ClusterNameRec) clusters {XPATH('TpClusters/TpCluster')};
END;
rawTopologyInfo := SOAPCALL
(
ESP_URL + '/WsTopology?ver_=1.25', // Verified with platform 6.2.20-1
'TpTargetClusterQuery',
{
STRING pType {XPATH('Type')} := ''
},
DATASET(TopologyRec),
XPATH('TpTargetClusterQueryResponse/TpTargetClusters/TpTargetCluster'),
HTTPHEADER('Authorization', auth),
TRIM
);
topologyInfo := NORMALIZE
(
rawTopologyInfo,
LEFT.clusters,
TRANSFORM
(
{
STRING cluster_type,
STRING cluster_name
},
SELF.cluster_type := IF(LEFT.cluster_type = 'ThorCluster', 'thor', SKIP),
SELF.cluster_name := IF(RIGHT.cluster_name != '', RIGHT.cluster_name, SELF.cluster_type)
)
);
//------------------------------------------------------------------------------
// Get file part information for all files that matched the file name pattern
//------------------------------------------------------------------------------
RawFilePartRec := RECORD
UNSIGNED1 part_id {XPATH('Id')};
UNSIGNED1 copy_num {XPATH('Copy')};
STRING ip_address {XPATH('Ip')};
STRING part_size_bytes {XPATH('Partsize')};
END;
RawClusterInfoRec := RECORD
STRING cluster_name {XPATH('Cluster')};
DATASET(RawFilePartRec) file_parts {XPATH('DFUFileParts/DFUPart')};
END;
RawResultRec := RECORD
STRING file_name {XPATH('Name')};
STRING owner {XPATH('Owner')};
STRING file_size_bytes {XPATH('Filesize')};
STRING record_size_bytes {XPATH('Recordsize')};
STRING record_cnt {XPATH('RecordCount')};
DATASET(RawClusterInfoRec) clusterInfo {XPATH('DFUFilePartsOnClusters[1]/DFUFilePartsOnCluster')};
END;
DFUInfoParamRec := RECORD
STRING pfile_name {XPATH('Name')};
END;
dfuInfoRawResults := SOAPCALL
(
filenameList,
ESP_URL + '/WsDFU?ver_=1.34', // Verified with platform 6.2.20-1
'DFUInfo',
DFUInfoParamRec,
TRANSFORM
(
DFUInfoParamRec,
SELF.pfile_name := LEFT.name
),
DATASET(RawResultRec),
XPATH('DFUInfoResponse/FileDetail'),
HTTPHEADER('Authorization', auth),
TRIM
);
//------------------------------------------------------------------------------
// Normalize one level, hoisting the cluster name up to the file_name level
//------------------------------------------------------------------------------
DFUResultRec2 := RECORD
STRING file_name;
STRING owner;
UNSIGNED8 file_size_bytes;
UNSIGNED8 record_size_bytes;
UNSIGNED8 record_cnt;
STRING cluster_name;
DATASET(RawFilePartRec) file_parts;
END;
normalizedDFUInfoResults := NORMALIZE
(
DISTRIBUTE(dfuInfoRawResults),
LEFT.clusterInfo,
TRANSFORM
(
DFUResultRec2,
SELF.cluster_name := RIGHT.cluster_name,
SELF.file_parts := RIGHT.file_parts,
SELF.file_size_bytes := (UNSIGNED8)Std.Str.FilterOut(LEFT.file_size_bytes, ','),
SELF.record_size_bytes := (UNSIGNED8)Std.Str.FilterOut(LEFT.record_size_bytes, ','),
SELF.record_cnt := (UNSIGNED8)Std.Str.FilterOut(LEFT.record_cnt, ','),
SELF := LEFT
)
);
//------------------------------------------------------------------------------
// Filter so that only file_names belonging to a Thor cluster remain
//------------------------------------------------------------------------------
onlyThorData := JOIN
(
normalizedDFUInfoResults,
topologyInfo,
LEFT.cluster_name = RIGHT.cluster_name,
TRANSFORM(LEFT),
LOOKUP
);
//------------------------------------------------------------------------------
// Normalize file part information; we'll wind up with one record per file
// part
//------------------------------------------------------------------------------
FilePartRec := RECORD
UNSIGNED1 part_id;
UNSIGNED8 part_size_bytes;
DECIMAL9_2 part_skew_pct;
END;
DFUResultRec3 := RECORD
STRING file_name;
STRING owner;
UNSIGNED8 file_size_bytes;
UNSIGNED8 record_size_bytes;
UNSIGNED8 record_cnt;
STRING cluster_name;
FilePartRec;
END;
flattenedResults := NORMALIZE
(
onlyThorData,
LEFT.file_parts(copy_num = 1), // Look at only the first copy of a file
TRANSFORM
(
DFUResultRec3,
REAL idealpart_size_bytes := LEFT.file_size_bytes / MAX(LEFT.file_parts, part_id);
SELF.part_size_bytes := (UNSIGNED8)Std.Str.FilterOut(RIGHT.part_size_bytes, ','),
SELF.part_skew_pct := ((REAL)SELF.part_size_bytes - idealpart_size_bytes) / idealpart_size_bytes * 100,
SELF := RIGHT,
SELF := LEFT
)
);
//------------------------------------------------------------------------------
// Simple analysis of the flattened results
//------------------------------------------------------------------------------
analysis := TABLE
(
flattenedResults,
{
file_name,
owner,
cluster_name,
file_size_bytes,
record_cnt,
UNSIGNED2 file_part_cnt := COUNT(GROUP),
DECIMAL9_2 min_part_skew_pct := MIN(GROUP, part_skew_pct),
DECIMAL9_2 max_part_skew_pct := MAX(GROUP, part_skew_pct),
UNSIGNED2 num_high_skew := SUM(GROUP, IF(part_skew_pct >= 100, 1, 0)),
UNSIGNED2 num_low_skew := SUM(GROUP, IF(part_skew_pct <= -70, 1, 0)),
UNSIGNED2 num_index_parts := SUM(GROUP, IF(part_size_bytes = 32768, 1, 0)) // Kind of a hack
},
file_name, owner, cluster_name, file_size_bytes, record_cnt,
LOCAL
);
maxFilePartCnt := MAX(analysis, file_part_cnt);
flaggedAnalysis := PROJECT
(
analysis,
TRANSFORM
(
{
BOOLEAN flagged,
RECORDOF(LEFT)
},
SELF.flagged := MAP
(
LEFT.num_index_parts = 1 => FALSE, // Don't flag index files stored on Thor
LEFT.file_size_bytes < 2000000 => FALSE, // Don't flag small (<2MB) files
LEFT.max_part_skew_pct >= (90 * (maxFilePartCnt - 1)) => TRUE,
LEFT.num_high_skew > 1 => TRUE,
LEFT.num_low_skew > 1 => TRUE,
LEFT.min_part_skew_pct = -100 => TRUE,
FALSE
),
SELF := LEFT
)
);
//------------------------------------------------------------------------------
// Attach detailed part information to each file
//------------------------------------------------------------------------------
summary := DENORMALIZE
(
flaggedAnalysis,
flattenedResults,
LEFT.file_name = RIGHT.file_name
AND LEFT.cluster_name = RIGHT.cluster_name,
GROUP,
TRANSFORM
(
{
RECORDOF(LEFT) - [file_part_cnt, num_high_skew, num_low_skew, num_index_parts],
DATASET(FilePartRec) partInfo
},
SELF.partInfo := PROJECT(ROWS(RIGHT), TRANSFORM(FilePartRec, SELF := LEFT)),
SELF := LEFT
)
);
//------------------------------------------------------------------------------
// Output final results
//------------------------------------------------------------------------------
sortedSummary := SORT(summary, -max_part_skew_pct, min_part_skew_pct);
OUTPUT(sortedSummary, NAMED('AllFiles'), NOXPATH);
OUTPUT(sortedSummary(flagged), NAMED('FlaggedFiles'), NOXPATH);