Merge lp:~pbeaman/akiban-persistit/display-volume-header-info into lp:akiban-persistit

Proposed by Peter Beaman
Status: Merged
Approved by: Nathan Williams
Approved revision: 422
Merged at revision: 420
Proposed branch: lp:~pbeaman/akiban-persistit/display-volume-header-info
Merge into: lp:akiban-persistit
Diff against target: 149 lines (+97/-2)
3 files modified
src/main/java/com/persistit/CLI.java (+1/-1)
src/main/java/com/persistit/CheckpointManager.java (+0/-1)
src/main/java/com/persistit/VolumeHeader.java (+96/-0)
To merge this branch: bzr merge lp:~pbeaman/akiban-persistit/display-volume-header-info
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Review via email: mp+146693@code.launchpad.net

Description of the change

Add volumeinfo CLI command. Pretty-prints all the dates and other information in the volume header. Useful for diagnosing problems on client machines.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/main/java/com/persistit/CLI.java'
--- src/main/java/com/persistit/CLI.java 2013-01-19 17:52:20 +0000
+++ src/main/java/com/persistit/CLI.java 2013-02-05 18:08:28 +0000
@@ -156,7 +156,7 @@
156 private final static Map<String, Command> COMMANDS = new TreeMap<String, Command>();156 private final static Map<String, Command> COMMANDS = new TreeMap<String, Command>();
157157
158 private final static Class<?>[] CLASSES = { CLI.class, BackupTask.class, IntegrityCheck.class, StreamSaver.class,158 private final static Class<?>[] CLASSES = { CLI.class, BackupTask.class, IntegrityCheck.class, StreamSaver.class,
159 StreamLoader.class, StatisticsTask.class, TaskCheck.class };159 StreamLoader.class, StatisticsTask.class, TaskCheck.class, VolumeHeader.class };
160160
161 static {161 static {
162 for (final Class<?> clazz : CLASSES) {162 for (final Class<?> clazz : CLASSES) {
163163
=== modified file 'src/main/java/com/persistit/CheckpointManager.java'
--- src/main/java/com/persistit/CheckpointManager.java 2013-02-01 12:09:51 +0000
+++ src/main/java/com/persistit/CheckpointManager.java 2013-02-05 18:08:28 +0000
@@ -26,7 +26,6 @@
26import java.util.concurrent.atomic.AtomicBoolean;26import java.util.concurrent.atomic.AtomicBoolean;
2727
28import com.persistit.Transaction.CommitPolicy;28import com.persistit.Transaction.CommitPolicy;
29import com.persistit.exception.MissingThreadException;
30import com.persistit.exception.PersistitException;29import com.persistit.exception.PersistitException;
31import com.persistit.exception.PersistitInterruptedException;30import com.persistit.exception.PersistitInterruptedException;
32import com.persistit.mxbeans.CheckpointManagerMXBean;31import com.persistit.mxbeans.CheckpointManagerMXBean;
3332
=== modified file 'src/main/java/com/persistit/VolumeHeader.java'
--- src/main/java/com/persistit/VolumeHeader.java 2012-10-05 19:37:58 +0000
+++ src/main/java/com/persistit/VolumeHeader.java 2013-02-05 18:08:28 +0000
@@ -18,11 +18,17 @@
18import java.io.File;18import java.io.File;
19import java.io.FileInputStream;19import java.io.FileInputStream;
20import java.io.IOException;20import java.io.IOException;
21import java.io.PrintWriter;
22import java.text.SimpleDateFormat;
23import java.util.Date;
2124
25import com.persistit.CLI.Arg;
26import com.persistit.CLI.Cmd;
22import com.persistit.exception.CorruptVolumeException;27import com.persistit.exception.CorruptVolumeException;
23import com.persistit.exception.InvalidVolumeSpecificationException;28import com.persistit.exception.InvalidVolumeSpecificationException;
24import com.persistit.exception.PersistitException;29import com.persistit.exception.PersistitException;
25import com.persistit.exception.PersistitIOException;30import com.persistit.exception.PersistitIOException;
31import com.persistit.util.ArgParser;
26import com.persistit.util.Util;32import com.persistit.util.Util;
2733
28/**34/**
@@ -30,7 +36,13 @@
30 * volume file.36 * volume file.
31 */37 */
32class VolumeHeader {38class VolumeHeader {
39
40 private final static String[] ARGS_TEMPLATE = { "path|string:|Volume file name" };
41
42 private final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
43
33 /**44 /**
45 *
34 * Signature value - human and machine readable confirmation that this file46 * Signature value - human and machine readable confirmation that this file
35 * resulted from Persistit.47 * resulted from Persistit.
36 */48 */
@@ -355,4 +367,88 @@
355 return CURRENT_VERSION;367 return CURRENT_VERSION;
356 }368 }
357369
370 @Cmd("volumeinfo")
371 static VolumeInfoTask createTask(@Arg("file|string:|Volume file") final String file) throws Exception {
372 return new VolumeInfoTask(file);
373 }
374
375 private static class VolumeInfoTask extends Task {
376 String _volumeFileName;
377
378 private VolumeInfoTask(final String fileName) {
379 _volumeFileName = fileName;
380 }
381
382 @Override
383 protected void runTask() throws Exception {
384 final File file = new File(_volumeFileName);
385 final FileInputStream stream = new FileInputStream(file);
386 final byte[] bytes = new byte[SIZE];
387 final int readSize = stream.read(bytes);
388 stream.close();
389 if (readSize < SIZE) {
390 throw new CorruptVolumeException(String.format(
391 "File %s of size %,d is too short to be a Volume file\n", file, readSize));
392 }
393 /*
394 * Check out the fixed Volume file and learn the buffer size.
395 */
396 if (!verifySignature(bytes)) {
397 throw new CorruptVolumeException(String.format("File %s is not a Volume file: Invalid signature", file));
398 }
399 postMessage(String.format("%30s: %s", "File", file), Task.LOG_NORMAL);
400 outn("ID", getId(bytes));
401 outn("Page size", getPageSize(bytes));
402 outd("Creation time", getCreateTime(bytes));
403 outd("Last open time", getOpenTime(bytes));
404 outd("Last extension time", getLastExtensionTime(bytes));
405 outd("Last read time", getLastReadTime(bytes));
406 outd("Last write time", getLastWriteTime(bytes));
407 outn("Global timestamp", getGlobalTimestamp(bytes));
408 outn("Timestamp", getTimestamp(bytes));
409 outn("Version", getVersion(bytes));
410
411 outn("Directory root", getDirectoryRoot(bytes));
412 outn("Garbage root", getGarbageRoot(bytes));
413 outn("Initial pages", getInitialPages(bytes));
414 outn("Next available page", getNextAvailablePage(bytes));
415 outn("Extended page count", getExtendedPageCount(bytes));
416 outn("Pages per extension", getExtensionPages(bytes));
417 outn("Maximum pages", getMaximumPages(bytes));
418
419 outn("Fetch counter", getfetchCounter(bytes));
420 outn("Get counter", getGetCounter(bytes));
421 outn("Read counter", getReadCounter(bytes));
422 outn("Remove counter", getRemoveCounter(bytes));
423 outn("Store counter", getStoreCounter(bytes));
424 outn("Traverse counter", getTraverseCounter(bytes));
425 outn("Write counter", getWriteCounter(bytes));
426
427 }
428
429 private void outd(final String legend, final long value) {
430 postMessage(String.format("%30s: %s", legend, SDF.format(new Date(value))), Task.LOG_NORMAL);
431 }
432
433 private void outn(final String legend, final long value) {
434 postMessage(String.format("%30s: %,12d", legend, value), Task.LOG_NORMAL);
435 }
436
437 @Override
438 public String getStatus() {
439 return "";
440 }
441
442 }
443
444 public static void main(final String[] args) throws Exception {
445 final ArgParser ap = new ArgParser("VolumeHeader", args, ARGS_TEMPLATE).strict();
446 if (ap.isUsageOnly()) {
447 return;
448 }
449 final Task task = new VolumeInfoTask(ap.getStringValue("path"));
450 task.setMessageWriter(new PrintWriter(System.out));
451 task.runTask();
452 }
453
358}454}

Subscribers

People subscribed via source and target branches