-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathWikipediaLoader.java
663 lines (581 loc) · 25.1 KB
/
WikipediaLoader.java
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/*
* Copyright 2020 by OLTPBenchmark Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.oltpbenchmark.benchmarks.wikipedia;
import com.oltpbenchmark.api.Loader;
import com.oltpbenchmark.api.LoaderThread;
import com.oltpbenchmark.benchmarks.wikipedia.data.PageHistograms;
import com.oltpbenchmark.benchmarks.wikipedia.data.TextHistograms;
import com.oltpbenchmark.benchmarks.wikipedia.data.UserHistograms;
import com.oltpbenchmark.benchmarks.wikipedia.util.WikipediaUtil;
import com.oltpbenchmark.catalog.Table;
import com.oltpbenchmark.types.DatabaseType;
import com.oltpbenchmark.util.RandomDistribution.FlatHistogram;
import com.oltpbenchmark.util.RandomDistribution.Zipf;
import com.oltpbenchmark.util.SQLUtil;
import com.oltpbenchmark.util.StringUtil;
import com.oltpbenchmark.util.TextGenerator;
import com.oltpbenchmark.util.TimeUtil;
import java.sql.Connection;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.CountDownLatch;
/**
* Synthetic Wikipedia Data Loader
*
* @author pavlo
* @author djellel
*/
public final class WikipediaLoader extends Loader<WikipediaBenchmark> {
/** UserId -> # of Revisions */
private final int[] user_revision_ctr;
/** PageId -> Last Revision Id */
private final int[] page_last_rev_id;
/** PageId -> Last Revision Length */
private final int[] page_last_rev_length;
/**
* Constructor
*
* @param benchmark
*/
public WikipediaLoader(WikipediaBenchmark benchmark) {
super(benchmark);
this.user_revision_ctr = new int[this.benchmark.num_users];
Arrays.fill(this.user_revision_ctr, 0);
this.page_last_rev_id = new int[this.benchmark.num_pages];
Arrays.fill(this.page_last_rev_id, -1);
this.page_last_rev_length = new int[this.benchmark.num_pages];
Arrays.fill(this.page_last_rev_length, -1);
if (LOG.isDebugEnabled()) {
LOG.debug("# of USERS: {}", this.benchmark.num_users);
LOG.debug("# of PAGES: {}", this.benchmark.num_pages);
}
}
@Override
public List<LoaderThread> createLoaderThreads() {
List<LoaderThread> threads = new ArrayList<>();
final int numLoaders = this.benchmark.getWorkloadConfiguration().getLoaderThreads();
final int numItems = this.benchmark.num_pages + this.benchmark.num_users;
final int itemsPerThread = Math.max(numItems / numLoaders, 1);
final int numUserThreads = (int) Math.ceil((double) this.benchmark.num_users / itemsPerThread);
final int numPageThreads = (int) Math.ceil((double) this.benchmark.num_pages / itemsPerThread);
final CountDownLatch userPageLatch = new CountDownLatch(numUserThreads + numPageThreads);
final CountDownLatch anonUserLatch = new CountDownLatch(1);
threads.add(
new LoaderThread(this.benchmark) {
@Override
public void load(Connection conn) throws SQLException {
Table catalog_tbl = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_USER);
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, true);
String sql =
SQLUtil.getInsertSQL(
catalog_tbl, benchmark.getWorkloadConfiguration().getDatabaseType());
// Empty string which is treated as NULL in Oracle DB
String dummyString = getDatabaseType() == DatabaseType.ORACLE ? " " : "";
// load anonymous user
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int param = 1;
stmt.setInt(param++, WikipediaConstants.ANONYMOUS_USER_ID); // user_id
stmt.setString(param++, "Anonymous"); // user_name
stmt.setString(param++, dummyString); // user_real_name
stmt.setString(param++, dummyString); // user_password
stmt.setString(param++, dummyString); // user_newpassword
stmt.setNull(param++, JDBCType.VARCHAR.getVendorTypeNumber()); // user_newpass_time
stmt.setString(param++, dummyString); // user_email
stmt.setString(param++, dummyString); // user_options
stmt.setString(param++, dummyString); // user_touched
stmt.setString(param++, dummyString); // user_token
stmt.setNull(
param++, JDBCType.VARCHAR.getVendorTypeNumber()); // user_email_authenticated
stmt.setNull(param++, JDBCType.VARCHAR.getVendorTypeNumber()); // user_email_token
stmt.setNull(
param++, JDBCType.VARCHAR.getVendorTypeNumber()); // user_email_token_expires
stmt.setNull(param++, JDBCType.VARCHAR.getVendorTypeNumber()); // user_registration
stmt.setInt(param, 0); // user_editcount
stmt.executeUpdate();
}
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, false);
}
@Override
public void afterLoad() {
anonUserLatch.countDown();
}
});
// USERS
for (int i = 0; i < numUserThreads; i++) {
// load USERS[lo, hi]
final int lo = i * itemsPerThread + 1;
final int hi = Math.min(this.benchmark.num_users, (i + 1) * itemsPerThread);
threads.add(
new LoaderThread(this.benchmark) {
@Override
public void load(Connection conn) throws SQLException {
loadUsers(conn, lo, hi);
}
@Override
public void afterLoad() {
userPageLatch.countDown();
}
@Override
public void beforeLoad() {
try {
anonUserLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
// PAGES
for (int i = 0; i < numPageThreads; i++) {
// load PAGES[lo, hi]
final int lo = i * itemsPerThread + 1;
final int hi = Math.min(this.benchmark.num_pages, (i + 1) * itemsPerThread);
threads.add(
new LoaderThread(this.benchmark) {
@Override
public void load(Connection conn) throws SQLException {
loadPages(conn, lo, hi);
}
@Override
public void afterLoad() {
userPageLatch.countDown();
}
@Override
public void beforeLoad() {
try {
anonUserLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
// WATCHLIST and REVISIONS depends on USERS and PAGES
// WATCHLIST
threads.add(
new LoaderThread(this.benchmark) {
@Override
public void load(Connection conn) throws SQLException {
loadWatchlist(conn);
}
@Override
public void beforeLoad() {
try {
userPageLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
// REVISIONS
threads.add(
new LoaderThread(this.benchmark) {
@Override
public void load(Connection conn) throws SQLException {
loadRevision(conn);
}
@Override
public void beforeLoad() {
try {
userPageLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
return threads;
}
/** USERACCTS */
private void loadUsers(Connection conn, int lo, int hi) throws SQLException {
Table catalog_tbl = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_USER);
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, true);
String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType());
try (PreparedStatement userInsert = conn.prepareStatement(sql)) {
FlatHistogram<Integer> h_nameLength = new FlatHistogram<>(rng(), UserHistograms.NAME_LENGTH);
FlatHistogram<Integer> h_realNameLength =
new FlatHistogram<>(rng(), UserHistograms.REAL_NAME_LENGTH);
FlatHistogram<Integer> h_revCount = new FlatHistogram<>(rng(), UserHistograms.REVISION_COUNT);
int[] types = catalog_tbl.getColumnTypes();
int batchSize = 0;
int lastPercent = -1;
for (int i = lo; i <= hi; i++) {
// The name will be prefixed with their UserId. This increases
// the likelihood that all of our usernames are going to be unique
// It's not a guarantee, but it's good enough...
String name = i + TextGenerator.randomStr(rng(), h_nameLength.nextValue());
String realName = TextGenerator.randomStr(rng(), h_realNameLength.nextValue());
int revCount = h_revCount.nextValue();
String password = StringUtil.repeat("*", rng().nextInt(32) + 1);
char[] eChars = TextGenerator.randomChars(rng(), rng().nextInt(32) + 5);
eChars[4 + rng().nextInt(eChars.length - 4)] = '@';
String email = new String(eChars);
String token = TextGenerator.randomStr(rng(), WikipediaConstants.TOKEN_LENGTH);
String userOptions = "fake_longoptionslist";
String newPassTime = TimeUtil.getCurrentTimeString14();
String touched = TimeUtil.getCurrentTimeString14();
int param = 1;
userInsert.setInt(param++, i); // user_id
userInsert.setString(param++, name); // user_name
userInsert.setString(param++, realName); // user_real_name
userInsert.setString(param++, password); // user_password
userInsert.setString(param++, password); // user_newpassword
userInsert.setString(param++, newPassTime); // user_newpass_time
userInsert.setString(param++, email); // user_email
userInsert.setString(param++, userOptions); // user_options
userInsert.setString(param++, touched); // user_touched
userInsert.setString(param++, token); // user_token
userInsert.setNull(param++, types[param - 2]); // user_email_authenticated
userInsert.setNull(param++, types[param - 2]); // user_email_token
userInsert.setNull(param++, types[param - 2]); // user_email_token_expires
userInsert.setNull(param++, types[param - 2]); // user_registration
userInsert.setInt(param++, revCount); // user_editcount
userInsert.addBatch();
if (++batchSize % workConf.getBatchSize() == 0) {
userInsert.executeBatch();
userInsert.clearBatch();
this.addToTableCount(catalog_tbl.getName(), batchSize);
batchSize = 0;
if (LOG.isDebugEnabled()) {
int percent = (int) (((double) i / (double) this.benchmark.num_users) * 100);
if (percent != lastPercent) {
LOG.debug("USERACCT ({}%)", percent);
}
lastPercent = percent;
}
}
}
if (batchSize > 0) {
this.addToTableCount(catalog_tbl.getName(), batchSize);
userInsert.executeBatch();
userInsert.clearBatch();
}
}
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, false);
DatabaseType dbType = this.getDatabaseType();
if (dbType.shouldUpdateColumnSequenceAfterLoad()) {
this.updateAutoIncrement(conn, catalog_tbl.getColumn(0), this.benchmark.num_users);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Users % {}", this.benchmark.num_users);
}
}
/** PAGE */
private void loadPages(Connection conn, int lo, int hi) throws SQLException {
Table catalog_tbl = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_PAGE);
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, true);
String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType());
try (PreparedStatement pageInsert = conn.prepareStatement(sql)) {
FlatHistogram<String> h_restrictions =
new FlatHistogram<>(rng(), PageHistograms.RESTRICTIONS);
int batchSize = 0;
int lastPercent = -1;
for (int i = lo; i <= hi; i++) {
String title = WikipediaUtil.generatePageTitle(rng(), i);
int namespace = WikipediaUtil.generatePageNamespace(rng(), i);
String restrictions = h_restrictions.nextValue();
double pageRandom = rng().nextDouble();
String pageTouched = TimeUtil.getCurrentTimeString14();
int param = 1;
pageInsert.setInt(param++, i); // page_id
pageInsert.setInt(param++, namespace); // page_namespace
pageInsert.setString(param++, title); // page_title
pageInsert.setString(param++, restrictions); // page_restrictions
pageInsert.setInt(param++, 0); // page_counter
pageInsert.setInt(param++, 0); // page_is_redirect
pageInsert.setInt(param++, 0); // page_is_new
pageInsert.setDouble(param++, pageRandom); // page_random
pageInsert.setString(param++, pageTouched); // page_touched
pageInsert.setInt(param++, 0); // page_latest
pageInsert.setInt(param++, 0); // page_len
pageInsert.addBatch();
if (++batchSize % workConf.getBatchSize() == 0) {
pageInsert.executeBatch();
pageInsert.clearBatch();
this.addToTableCount(catalog_tbl.getName(), batchSize);
batchSize = 0;
if (LOG.isDebugEnabled()) {
int percent = (int) (((double) i / (double) this.benchmark.num_pages) * 100);
if (percent != lastPercent) {
LOG.debug("PAGE ({}%)", percent);
}
lastPercent = percent;
}
}
}
if (batchSize > 0) {
pageInsert.executeBatch();
pageInsert.clearBatch();
this.addToTableCount(catalog_tbl.getName(), batchSize);
}
}
SQLUtil.setIdentityInsert(conn, getDatabaseType(), catalog_tbl, false);
DatabaseType dbType = this.getDatabaseType();
if (dbType.shouldUpdateColumnSequenceAfterLoad()) {
this.updateAutoIncrement(conn, catalog_tbl.getColumn(0), this.benchmark.num_pages);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Users % {}", this.benchmark.num_pages);
}
}
/** WATCHLIST */
private void loadWatchlist(Connection conn) throws SQLException {
Table catalog_tbl = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_WATCHLIST);
String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType());
try (PreparedStatement watchInsert = conn.prepareStatement(sql)) {
int max_watches_per_user =
Math.min(this.benchmark.num_pages, WikipediaConstants.MAX_WATCHES_PER_USER);
Zipf h_numWatches =
new Zipf(rng(), 0, max_watches_per_user, WikipediaConstants.NUM_WATCHES_PER_USER_SIGMA);
Zipf h_pageId =
new Zipf(rng(), 1, this.benchmark.num_pages, WikipediaConstants.WATCHLIST_PAGE_SIGMA);
// Use a large max batch size for tables with smaller tuples
int maxBatchSize = workConf.getBatchSize() * 5;
int batchSize = 0;
int lastPercent = -1;
Set<Integer> userPages = new HashSet<>();
for (int user_id = 1; user_id <= this.benchmark.num_users; user_id++) {
int num_watches = h_numWatches.nextInt();
if (LOG.isTraceEnabled()) {
LOG.trace("{} => {}", user_id, num_watches);
}
if (num_watches == 0) {
continue;
}
userPages.clear();
for (int i = 0; i < num_watches; i++) {
int pageId = -1;
// HACK: Work around for testing with small database sizes
if (num_watches == max_watches_per_user) {
pageId = i + 1;
} else {
pageId = h_pageId.nextInt();
while (userPages.contains(pageId)) {
pageId = h_pageId.nextInt();
}
}
userPages.add(pageId);
Integer namespace = WikipediaUtil.generatePageNamespace(rng(), pageId);
String title = WikipediaUtil.generatePageTitle(rng(), pageId);
int param = 1;
watchInsert.setInt(param++, user_id); // wl_user
watchInsert.setInt(param++, namespace); // wl_namespace
watchInsert.setString(param++, title); // wl_title
watchInsert.setNull(param++, java.sql.Types.VARCHAR); // wl_notificationtimestamp
watchInsert.addBatch();
batchSize++;
}
if (batchSize >= maxBatchSize) {
watchInsert.executeBatch();
watchInsert.clearBatch();
this.addToTableCount(catalog_tbl.getName(), batchSize);
batchSize = 0;
if (LOG.isDebugEnabled()) {
int percent = (int) (((double) user_id / (double) this.benchmark.num_users) * 100);
if (percent != lastPercent) {
LOG.debug("WATCHLIST ({}%)", percent);
}
lastPercent = percent;
}
}
}
if (batchSize > 0) {
watchInsert.executeBatch();
watchInsert.clearBatch();
this.addToTableCount(catalog_tbl.getName(), batchSize);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Watchlist Loaded");
}
}
/** REVISIONS */
private void loadRevision(Connection conn) throws SQLException {
// TEXT
Table textTable = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_TEXT);
String textSQL = SQLUtil.getInsertSQL(textTable, this.getDatabaseType());
// REVISION
Table revTable = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_REVISION);
String revSQL = SQLUtil.getInsertSQL(revTable, this.getDatabaseType());
int batchSize = 1;
Zipf h_users =
new Zipf(rng(), 1, this.benchmark.num_users, WikipediaConstants.REVISION_USER_SIGMA);
FlatHistogram<Integer> h_textLength = new FlatHistogram<>(rng(), TextHistograms.TEXT_LENGTH);
FlatHistogram<Integer> h_commentLength = this.benchmark.commentLength;
FlatHistogram<Integer> h_minorEdit = this.benchmark.minorEdit;
FlatHistogram<Integer> h_nameLength = new FlatHistogram<>(rng(), UserHistograms.NAME_LENGTH);
FlatHistogram<Integer> h_numRevisions =
new FlatHistogram<>(rng(), PageHistograms.REVISIONS_PER_PAGE);
final int rev_comment_max = revTable.getColumnByName("rev_comment").getSize();
int rev_id = 1;
int lastPercent = -1;
try (PreparedStatement textInsert = conn.prepareStatement(textSQL);
PreparedStatement revisionInsert = conn.prepareStatement(revSQL)) {
for (int page_id = 1; page_id <= this.benchmark.num_pages; page_id++) {
// There must be at least one revision per page
int num_revised = h_numRevisions.nextValue();
LOG.debug(String.format("# Revisions for Page %d: %d", page_id, num_revised));
// Generate what the new revision is going to be
int old_text_length = h_textLength.nextValue();
char[] old_text = TextGenerator.randomChars(rng(), old_text_length);
// FIXME: Need to break up the num_revised into multiple batches to avoid
// packet size limits in loader.
// See Also: #405
for (int i = 0; i < num_revised; i++) {
// Generate the User who's doing the revision and the Page revised
// Makes sure that we always update their counter
int user_id = h_users.nextInt();
this.user_revision_ctr[user_id - 1]++;
// Generate what the new revision is going to be
if (i > 0) {
old_text = this.benchmark.generateRevisionText(old_text);
old_text_length = old_text.length;
}
int rev_comment_len = Math.min(rev_comment_max, h_commentLength.nextValue() + 1); // HACK
String rev_comment = TextGenerator.randomStr(rng(), rev_comment_len);
// The REV_USER_TEXT field is usually the username, but we'll
// just put in gibberish for now
String user_text = TextGenerator.randomStr(rng(), h_nameLength.nextValue() + 1);
// Insert the text
int col = 1;
textInsert.setInt(col++, rev_id); // old_id
textInsert.setString(col++, new String(old_text)); // old_text
textInsert.setString(col++, "utf-8"); // old_flags
textInsert.setInt(col++, page_id); // old_page
textInsert.addBatch();
// Insert the revision
col = 1;
revisionInsert.setInt(col++, rev_id); // rev_id
revisionInsert.setInt(col++, page_id); // rev_page
revisionInsert.setInt(col++, rev_id); // rev_text_id
revisionInsert.setString(col++, rev_comment); // rev_comment
revisionInsert.setInt(col++, user_id); // rev_user
revisionInsert.setString(col++, user_text); // rev_user_text
revisionInsert.setString(col++, TimeUtil.getCurrentTimeString14()); // rev_timestamp
revisionInsert.setInt(col++, h_minorEdit.nextValue()); // rev_minor_edit
revisionInsert.setInt(col++, 0); // rev_deleted
revisionInsert.setInt(col++, 0); // rev_len
revisionInsert.setInt(col++, 0); // rev_parent_id
revisionInsert.addBatch();
// Update Last Revision Stuff
this.page_last_rev_id[page_id - 1] = rev_id;
this.page_last_rev_length[page_id - 1] = old_text_length;
rev_id++;
batchSize++;
}
if (batchSize > workConf.getBatchSize()) {
textInsert.executeBatch();
revisionInsert.executeBatch();
this.addToTableCount(textTable.getName(), batchSize);
this.addToTableCount(revTable.getName(), batchSize);
batchSize = 0;
if (LOG.isDebugEnabled()) {
int percent = (int) (((double) page_id / (double) this.benchmark.num_pages) * 100);
if (percent != lastPercent) {
LOG.debug("REVISIONS ({}%)", percent);
}
lastPercent = percent;
}
}
}
if (batchSize > 0) {
textInsert.executeBatch();
revisionInsert.executeBatch();
this.addToTableCount(textTable.getName(), batchSize);
this.addToTableCount(revTable.getName(), batchSize);
}
}
DatabaseType dbType = this.getDatabaseType();
if (dbType.shouldUpdateColumnSequenceAfterLoad()) {
this.updateAutoIncrement(conn, textTable.getColumn(0), rev_id);
this.updateAutoIncrement(conn, revTable.getColumn(0), rev_id);
}
// UPDATE USER
revTable = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_USER);
String revTableName =
(this.getDatabaseType().shouldEscapeNames())
? revTable.getEscapedName()
: revTable.getName();
String updateUserSql =
"UPDATE "
+ revTableName
+ " SET user_editcount = ?, "
+ " user_touched = ? "
+ " WHERE user_id = ?";
try (PreparedStatement userUpdate = conn.prepareStatement(updateUserSql)) {
batchSize = 0;
for (int i = 0; i < this.benchmark.num_users; i++) {
int col = 1;
userUpdate.setInt(col++, this.user_revision_ctr[i]);
userUpdate.setString(col++, TimeUtil.getCurrentTimeString14());
userUpdate.setInt(col++, i + 1); // ids start at 1
userUpdate.addBatch();
if ((++batchSize % workConf.getBatchSize()) == 0) {
userUpdate.executeBatch();
userUpdate.clearBatch();
batchSize = 0;
}
}
if (batchSize > 0) {
userUpdate.executeBatch();
userUpdate.clearBatch();
}
}
// UPDATE PAGES
revTable = benchmark.getCatalog().getTable(WikipediaConstants.TABLENAME_PAGE);
revTableName =
(this.getDatabaseType().shouldEscapeNames())
? revTable.getEscapedName()
: revTable.getName();
String updatePageSql =
"UPDATE "
+ revTableName
+ " SET page_latest = ?, "
+ " page_touched = ?, "
+ " page_is_new = 0, "
+ " page_is_redirect = 0, "
+ " page_len = ? "
+ " WHERE page_id = ?";
try (PreparedStatement pageUpdate = conn.prepareStatement(updatePageSql)) {
batchSize = 0;
for (int i = 0; i < this.benchmark.num_pages; i++) {
if (this.page_last_rev_id[i] == -1) {
continue;
}
int col = 1;
pageUpdate.setInt(col++, this.page_last_rev_id[i]);
pageUpdate.setString(col++, TimeUtil.getCurrentTimeString14());
pageUpdate.setInt(col++, this.page_last_rev_length[i]);
pageUpdate.setInt(col++, i + 1); // ids start at 1
pageUpdate.addBatch();
if ((++batchSize % workConf.getBatchSize()) == 0) {
pageUpdate.executeBatch();
pageUpdate.clearBatch();
batchSize = 0;
}
}
if (batchSize > 0) {
pageUpdate.executeBatch();
pageUpdate.clearBatch();
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Revision loaded");
}
}
}